I have a CSV file I want to load in WS02 stream processor for simulating events. I have a column named "Result". This is a string column in the CSV file.
In the WSO2 stream processor I tried to convert the incoming Result string to double or float. But this doesnt work. I also tried to change the CSV file in some way. For example I have tried making it a double or decimal with the "format cells" option in excel, but this did not work.
Below is the code I tried in WSO2. This is a example of result value: 159,321
It has max 6 digits. Max 3 digits before and after the comma.
define stream ResultStream(Nr String, DateTime String, Result String);
@sink(type='log', prefix='LOGGER')
define stream OutputStream(Nr int, DateTime String, Result double);
@info(name='Query')
from ResultStream
select convert(Nr, 'int') as Nr, DateTime, convert(Result, 'double') as Result
insert into OutputStream;
I get the error below:
java.lang.String cannot be cast to java.lang.Double. Hence, dropping event 'Event{timestamp=1570697706466, data=[18, 1-9-2010 08:06, 54,103], isExpired=false}' java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double
at org.wso2.siddhi.core.query.selector.attribute.aggregator.AvgAttributeAggregator$AvgAttributeAggregatorDouble.processAdd(AvgAttributeAggregator.java:162)
at org.wso2.siddhi.core.query.selector.attribute.aggregator.AvgAttributeAggregator.processAdd(AvgAttributeAggregator.java:102)
at org.wso2.siddhi.core.query.selector.attribute.aggregator.AttributeAggregator.process(AttributeAggregator.java:87)
at org.wso2.siddhi.core.query.selector.attribute.processor.executor.AggregationAttributeExecutor.execute(AggregationAttributeExecutor.java:40)
at org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor.process(AttributeProcessor.java:41)
at org.wso2.siddhi.core.query.selector.QuerySelector.processNoGroupBy(QuerySelector.java:136)
at org.wso2.siddhi.core.query.selector.QuerySelector.process(QuerySelector.java:94)
at org.wso2.siddhi.core.query.processor.stream.window.LengthWindowProcessor.process(LengthWindowProcessor.java:137)
at org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor.processEventChunk(WindowProcessor.java:65)
at org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor.process(AbstractStreamProcessor.java:123)
at org.wso2.siddhi.core.query.input.ProcessStreamReceiver.processAndClear(ProcessStreamReceiver.java:187)
at org.wso2.siddhi.core.query.input.ProcessStreamReceiver.process(ProcessStreamReceiver.java:97)
at org.wso2.siddhi.core.query.input.ProcessStreamReceiver.receive(ProcessStreamReceiver.java:133)
at org.wso2.siddhi.core.stream.StreamJunction.sendEvent(StreamJunction.java:204)
at org.wso2.siddhi.core.stream.StreamJunction$Publisher.send(StreamJunction.java:414)
at org.wso2.siddhi.core.stream.input.InputDistributor.send(InputDistributor.java:34)
at org.wso2.siddhi.core.stream.input.InputEntryValve.send(InputEntryValve.java:44)
at org.wso2.siddhi.core.stream.input.InputHandler.send(InputHandler.java:73)
at org.wso2.carbon.siddhi.editor.core.internal.DebuggerEventStreamService.pushEvent(DebuggerEventStreamService.java:70)
at org.wso2.carbon.event.simulator.core.service.EventSimulator.eventSimulation(EventSimulator.java:320)
at org.wso2.carbon.event.simulator.core.service.EventSimulator.run(EventSimulator.java:451)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
The issue you are experiencing is due to the comma in Result value. You need to remove the comma to make it a valid Number for the conversion.
Check the updated Siddhi app below. I have used str:replaceAll method to remove the ',' with an empty string.
define stream ResultStream(Nr String, DateTime String, Result String);
@sink(type='log', prefix='LOGGER')
define stream OutputStream(Nr int, DateTime String, Result double);
@info(name='Query')
from ResultStream
select convert(Nr, 'int') as Nr, DateTime, convert(str:replaceAll(Result,',',''), 'double') as Result
insert into OutputStream;