2

I'm going to use the same value in lots of statements in the SQL Expression. So it is possible to declare and assign the value to a variable at the beginning of the query and refer the value by it? (I'm writing an execution plan in WSO2 DAS)

Community
  • 1
  • 1
PasinduJay
  • 487
  • 5
  • 17

1 Answers1

1

This is not supported as of now. However, supporting this has been under discussion, hence this might be implemented in a future release.

If you want to store a value and use it in a query, the currently available ways are:

  • Putting that value into an indexed event table and then doing a join with the event table to read that value whenever required.

Indexed In-memory Event Table internally uses a Hash-Map, therefore you could use one to store your variables, in such a way that the key of the hashmap will be the name of your varaible and the value of the hashmap will be the value of your variable.

However I feel that above solution is too complicated for your requirement.

Dilini
  • 777
  • 8
  • 22
  • @PasinduJw I am currently using Siddhi QL, and i have a strange requirement. Input data is given in quote e.g. "apple" and the output would be : apple. I have tried using select substr(sensorId,1,4) as out insert into outputStream; Than i am getting error "substr is neither a function nor an aggregated attribute, " HOwever i have tried using JS to substring it and i got : jdk.nashorn.internal.runtime.ParserException: :1:22 Missing space after numeric literal var data = [""tempID=1wef"",0] do you have any alternative solution ; or am i doing something wrong – Sidharth Dash Aug 30 '16 at 14:27
  • The proper way to use substr function in siddhi is as follows: select str:substr(sensorId,1,4) as partOfString. You may use replaceAll function as well. – Charini Nanayakkara Sep 02 '16 at 08:32