Hi All,

As discussed with Suho and Srinath today, the scripting support is going to
be in following manner,

1. The user can just write only set of statements without writing functions.
   For example, if the user needs to concatenate strings defining a siddhi
function call concat, he can define the function like below,

define function concat[JavaScript] {
  var a = data[0];
  var b = data[1];
  rerurn a + b;
};

and he/she can call it in siddhi like below,

from cseEventStream
select *concat( *a, b *) *as c
insert into some_other;

2. Internally, Siddhi construct a function like below, for the above
example, Siddhi constructs a function like below which the external user
cannot see,

function concat(Data) {
  var a = data[0].toString();
  var b = data[1].toString();
  return a + b;
}

For the Scala also, user is having the same ability, below is the suggested
Siddhi script for scala,

define function concat[Scala] {
  var a = data(0).asInstanceOf[String]
  var b = data(1).asInstanceOf[String]
  a + b
}

and call it in siddhi exactly like we did it above JavaScript example.
Siddhi internally construct the below function,

data: Array[Any] => {
  var a = data(0).asInstanceOf[String]
  var b = data(1).asInstanceOf[String]
  a + b
}

Appreciate your thoughts!!!!

Thanks,
-Ayash

On Mon, Dec 1, 2014 at 5:17 PM, Sriskandarajah Suhothayan <[email protected]>
wrote:

> +1 looks good
>
> Suho
>
> On Mon, Dec 1, 2014 at 4:57 PM, Ayash <[email protected]> wrote:
>
>> Hi All,
>>
>> The implementation, $subject is adding some scripting support for Siddhi.
>> It is as follows,
>>
>> 1. Scripting languages are going to be JavaScript and Scala.
>> 2. New language feature is to be introduced like below,
>>       Define script[Language]{//script implementation goes here}
>> 3. Siddhi user can choose the scripting language mentioning it like below
>> in Siddhi,
>>       Define script[JavaScript] {//JavaScript implementation goes here}
>>       or
>>       Define script[Scala]{//Scala implementation goes here}
>> 4. The functions or methods defined are to be available to the user to
>> call it like Siddhi inbuilt function.
>>
>> For example, let's just define and call a Scala-method in Siddhi like
>> below,
>>
>> define script[Scala] {
>>     Def *getSymbol*(id: String): String = id
>> }
>> define stream cseEventStream (symbol string, price float, volume string)
>> from cseEventStream
>> select *getSymbol*(symbol), convert(volume,long)/1000 as vol,
>> sum(convert(volume,long)) as sumVolume
>> group by symbol
>> insert into StockQuote;
>>
>> Appreciate your thoughts!!!
>>
>> Thanks,
>> -Ayash
>>
>>
>> --
>> Ayashkantha Ramasinghe
>> Software Engineer WSO2, Inc.
>> email: [email protected] <[email protected]>;
>> TP: +94 77 7 487 669
>>
>
>
>
> --
>
> *S. Suhothayan*
> Technical Lead & Team Lead of WSO2 Complex Event Processor
>  *WSO2 Inc. *http://wso2.com
> * <http://wso2.com/>*
> lean . enterprise . middleware
>
>
> *cell: (+94) 779 756 757 <%28%2B94%29%20779%20756%20757> | blog:
> http://suhothayan.blogspot.com/ <http://suhothayan.blogspot.com/>twitter:
> http://twitter.com/suhothayan <http://twitter.com/suhothayan> | linked-in:
> http://lk.linkedin.com/in/suhothayan <http://lk.linkedin.com/in/suhothayan>*
>



-- 
Ayashkantha Ramasinghe
Software Engineer WSO2, Inc.
email: [email protected] <[email protected]>;
TP: +94 77 7 487 669
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to