0

我有一个 CSV 文件,我想在 WS02 流处理器中加载以模拟事件。我有一个名为“结果”的列。这是 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)
4

1 回答 1

0

您遇到的问题是由于 Result 值中的逗号。您需要删除逗号以使其成为转换的有效数字。

检查下面更新的 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;
于 2019-10-10T09:47:54.620 回答