What's the difference between StreamCallback and QueryCallback in Siddhi? - wso2

There are many callbacks in siddhi, I want to know the difference between them.
Like, when we shall use streamCallback and when we shall use queryCallback.
I can't find any document about this.
Thanks.

Query callbacks are used to listen to the outputs of a specific query. On the other hand, when you use the StreamCallback, it's not bound to a specific query and can receive outputs from multiple queries (multiple queries can output to the same stream).
eg:
from profileStream
select name, email
insert into outStream;
from alertStream
select name, mailAddress as email
insert into outStream;
If you add a query callback, you'd be adding it to one of these queries. But when you add a stream callback, you can add it for the outStream, which will give you the results of both queries.

Related

Can we write queries in Multichain like select * from Stream1.key1 where key1.value = “xyz”

Can we write queries in Multichain to retrieve conditional data from streams e.g. select * from Stream1.key1 where key1.value = “xyz”
You have many different ways of slicing and dicing stream items, but it does not support SQL. I'm not sure what you want to do with this query, but maybe liststreamkeyitems is what you're looking for? See the 'Querying subscribed streams' section on this page:
https://www.multichain.com/developers/json-rpc-api/

Is there a way to use value from CUST_DDA port as input port for lookup?

I'm trying to use a Lookup transformation to extract ACCT_ID from ACCT table based on the port CUST_DDA which is an output port from an expression.
I'm using an sqloverride as below. The initial lookup condition :
SUBSTR_ACCT_ID = IN_CUST_DDA
Override:
SELECT
ACCT.ACCT_ID as ACCT_ID,
ACCT.ALT_ACCT_ID as ALT_ACCT_ID,
substr(acct.acct_id,-1*(length(IN_CUST_DDA))) as SUBSTR_ACCT_ID
FROM ACCT
WHERE ACCT.ALT_ACCT_ID LIKE '%'||TO_CHAR(IN_CUST_DDA)
AND ACCT.ACCT_ID LIKE '%'||TO_CHAR(IN_CUST_DDA)
The above sql override is failing due to the error : ORA-00904: "IN_CUST_DDA": invalid identifier
Is there a way to use the value from CUST_DDA port as an input port for the lookup. CUST_DDA is not a field that belongs to the ACCT table. Is there a way to do this.
Thanks.
From the override I can see that you are trying to convert IN_CUST_DDA into CHAR, also at the same time your using IN_CUST_DDA in the length.
Might be the length function causing the issue, because length function can be used along with a string.
In order to use CUST_DDA(from source) in your lookup override. You need to join the lookup table with source with a common field in the override.
You cant use the port in the way you mentioned. When you run the workflow informatica integration service will run the lookup override query in the database and get the data into the cache file (that is the reason you are receiving the error "IN_CUST_DDA": invalid identifier.) . Once the cache file is ready it will apply the conditions and then get the output for you.
Let me know if you are not clear on this
Regards
Raj
To achieve this you need to configure your lookup as non-cached, so the query will be executed for each input row. Note, that this degrades performance a lot.
Next, you need to use a bit different syntax, enclosing the input port in question marks. Here's an example. In your case it should be something like (this might need a little adjustment):
SELECT
ACCT.ACCT_ID as ACCT_ID,
ACCT.ALT_ACCT_ID as ALT_ACCT_ID,
substr(acct.acct_id,-1*(length(?IN_CUST_DDA?))) as SUBSTR_ACCT_ID
FROM ACCT
WHERE ACCT.ALT_ACCT_ID LIKE '%'||TO_CHAR(?IN_CUST_DDA?)
AND ACCT.ACCT_ID LIKE '%'||TO_CHAR(?IN_CUST_DDA?)

Passing n number of input to a GET method of a REST service

I am trying to write a REST service with Jersey where the GET method should write me a list of objects. The input to the GET method should take the ids of the list.
Say I will pass n numbers of EmployeeId and the service should return me a list of employees.
If it is not possible to have #Consumes in the GET method, will there be any problem in using other methods of http like PUT or POST to retrieve the list of objects?
Using POST and PUT for resource retrieval contradicts the conventions established for the usage of REST over HTTP. Switching to either of them just for the sake of using a #Consumes annotation is simply wrong.
If you need to provide additional scoping information for a collection of resources, place it in the URL. Specifically, you can use query parameters. It's a common pattern to implement pagination this way (by providing some limit and offset parameters). Your use case is very similar.
Let's assume this is the URL of a collection of employee resources
GET http://www.example.com/employees
A single employee could be fetched like this:
GET http://www.example.com/employees/id1
If you want to retrieve several employees, you could use a query string like this:
GET http://www.example.com/employees?ids=id1;id3;id8
The identifiers do not need to be delimited by semicolons, this is just an example of a way you could fetch them. Remember that it's treated as a single parameter! You'll have to split the values.
Here's how you could read such a list from the URL above
#Path("employees")
#GET
public Response getEmployees(#QueryParam("ids") String employees){
List<String> ids = Arrays.asList(employes.split(";"));
// Validate the ids, get data from a database,
// prepare a response and return it
}
Parsing the list can be cumbersome, especially if you want to validate the ids somehow. Jersey has a neat feature you can use here. If a class has a single-string-parameter constructor or a SomeType parse(String) method, it can be injected by the framework by parsing the string passed as a parameter (QueryParam, PathParam, FormParam, etc.)
You can take advantage of it to make your resource class cleaner.
#Path("employees")
#GET
public Response getEmployees(#QueryParam("ids") Employees e){
doFancyStaffWithAValidListOfEmployees(e.asList());
//prepare a response
}
Where Employees is a class with a String constructor or a parse method, containing all the splitting and validation logic, possibly even some database queries.
Here's a nice article on writing such parameter classes

Scan a dynamodb based on a list

I have a String Set attribute i.e SS in a dynamodb table. I need to scan the database to check the value present in the any one list of the items.
Which comparison operator should I use for this scan?
example the db has items like this:
name
[email1, email2]
phone
I need to search for a items containing a particular email say email1 alone not giving the entire tuple.
It seems like you are looking for the CONTAINS operator of Scan operation. It basically is the equivalent of in in Python.
This said, if you need to perform this often, you probably should de-normalize your data to make it faster.
For example, you could build a second table like this:
hash_key: name
range_key: email
Of course, you would have to maintain this index yourself and query it manually.

Custom Date Aggregate Function

I want to sort my Store models by their opening times. Store models contains is_open function which controls Store's opening time ranges and produces a boolean if it's open or not. The problem is I don't want to sort my queryset manually because of efficiency problem. I thought if I write a custom annotate function then I can filter the query more efficiently.
So I googled and found that I can extend Django's aggregate class. From what I understood, I have to use pre-defined sql functions like MAX, AVG etc. The thing is I want to check that today's date is in a given list of time intervals. So anyone can help me that which sql name should I use ?
Edit
I'd like to put the code here but it's really a spaghetti one. One pages long code only generates time intervals and checks the suitable one.
I want to avoid :
alg= lambda r: (not (s.is_open() and s.reachable))
sorted(stores,key=alg)
and replace with :
Store.objects.annotate(is_open = CheckOpen(datetime.today())).order_by('is_open')
But I'm totally lost at how to write CheckOpen...
have a look at the docs for extra