In WSO2 CEP 3.0.0. I experienced some confusing behavior with attributes of double type.
Assume the following siddhi script:
define stream LongStream LongAttr1 long, LongAttr2 long;
define stream DoubleStream DoubleAttr1 double;
from LongStream
select (LongAttr1/LongAttr2) as DoubleAttr1
insert into DoubleStream;
from DoubleStream[DoubleAttr1 > 0.75]
...
In this script the insertion of DoubleAttr1 in DoubleStream is working, giving well a floating value with decimals. But the filter afterwards is raising a casting exception.
ERROR - {QuerySelector} Input event attribute type java.lang.Double cannot be cast to java.lang.Long type defined in the stream definition!
java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Long at org.wso2.siddhi.core.executor.conditon.compare.greater_than_equal.GreaterThanEqualCompareConditionExecutorLongDouble.process(GreaterThanEqualCompareConditionExecutorLongDouble.java:34)
This is rather confusing it seems that the DoubleAttr1 is considered as a long?
If I calculate DoubleAttr1 as:
convert(LongAttr1/LongAttr2, double)
or
(LongAttr1 * 100.0) / (LongAttr2 * 100.0)
the exception is not raised anymore. I found this behavior quite confusing and I think it should be prevented or corrected in further releases. What is your opinion?
Br,
Eric
PS: I experienced also some rounding error with the convert function: convert (LogAttr1 / LongAttr2 *100) is giving 99.0 as result if LongAttr1 = 2 and LongAttr2 = 2
I've only just started looking at siddhi this week so I am no expert, but I was experiencing a similar problem. I was trying to divide a long which represented seconds by 60 to get minutes and I was getting a similar exception.
I fixed this by dividing by 60.0 instead. It looks like because I was dividing a long by an integer it was evaluating the result to a long and causing an exception when trying to cast to my stream definition.
Its probably the same issue that has been discussed here
Unexpected result in long/int division