我有一个要在WS02流处理器中加载的CSV文件,用于模拟事件。我有一列名为“结果”。这是CSV文件中的字符串列。
在WSO2流处理器中,我尝试将传入的Result字符串转换为double或float。但这不起作用。我也尝试过以某种方式更改CSV文件。例如,我尝试使用excel中的“格式单元格”选项将其设置为双精度或十进制,但这没有用。
下面是我在WSO2中尝试过的代码。这是结果值的示例:159,321
最多可包含6位数字。逗号前后最多3位数字。
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;
我收到以下错误:
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)
答案 0 :(得分:0)
您遇到的问题是由于结果值中的逗号引起的。 您需要删除逗号以使其成为转换的有效数字。
在下面检查更新的Siddhi应用程序。我已经使用str:replaceAll方法删除带有空字符串的','。
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;