csv - 将 CSV 文件中的 DateTime 字符串解析为事件时间戳
问题描述
使用 WSO2 SP,我的应用程序从以下 CSV 文件中读取行:
20170801 000001237,1.321420,1.321510,0
20170801 000001487,1.321440,1.321530,0
20170801 000001737,1.321450,1.321530,0
20170801 000001987,1.321440,1.321530,0
第一列是时间戳字符串,需要对其进行解析以对事件进行时间戳记:
yyyyMMdd hhmmssfff
, 其中 fff 是毫秒
我当前的应用程序如下所示:
@App:name('ReceiveAndCount')
@App:description('count events in csv file')
@source(type = 'file',
mode='line',
tailing='false',
file.uri = "file:/Users/A/Desktop/siddhi/wso2sp-4.4.0/data/DAT_ASCII_GBPUSD_T_201708.csv",
action.after.process='NONE',
@map(type = 'csv', header='false', delimiter = ",",
@attributes(
dateTime = '0',
bid='1',
ask='2',
ignore='3' ) ))
define stream csvGBPUSDstream (dateTime string, bid double, ask double, ignore int);
@sink(type = 'log', priority='info')
define stream TotalCountStream (totalCount long);
-- Count the incoming events
@info(name = 'query1')
from csvGBPUSDstream
select count() as totalCount
insert into TotalCountStream;
非常感谢有关将第一列中的日期字符串解析为事件时间戳的任何指导
解决方案
通过以下命令在 docker 中运行 wso2sp-editor,使用音量开关允许读取本地数据文件:
docker run -it -p 9390:9390 -v /Users/A/Desktop/wso2sp-editor-docker-data:/home/wso2carbon/wso2sp-4.4.0/data/ --name editor wso2/wso2sp-editor:4.4.0
最后是应用代码:
@App:name('CsvParseDateTime')
@App:description('parse timestamp string from csv file') --abrakadabra @source(type = 'file', mode = "line", tailing = "false", file.uri = "file://home/wso2carbon /wso2sp-4.4.0/data/DAT_ASCII_GBPUSD_T_201708.csv", --"file:/Users/A/Desktop/siddhi/wso2sp-4.4.0/data/DAT_ASCII_GBPUSD_T_201708.csv", action.after.process = "NONE" , @map(type = 'csv', header = "false", delimiter = ",", @attributes(dateTime = "0", ask = "2", ignore = "3", bid = "1")) ) 定义流 csvGBPUSDstream (dateTime 字符串,bid double,ask double,忽略 int);
@sink(type = 'log', priority = "info") 定义流 FiveSecRangeStream (timestamp long, FiveSecRange double);
-- streat 将 dateTime 字符串解析为可以用作时间窗口索引的毫秒时间 --time:timestampInMilliseconds(date.value,date.format) yyyy-MM-dd HH:mm:ss.SSS @info(name = 'Parse Timestamp') from csvGBPUSDstream select time:timestampInMilliseconds(dateTime, 'yyyyMMdd HHmmssSSS') 作为时间戳,出价,询价插入 indexedGBPUSDstream;
-- 外部窗口时间(事件流中的时间戳)来自 indexedGBPUSDstream#window.externalTime(timestamp,5 Sec) 选择时间戳,max(bid)-min(bid) as FiveSecRange 插入到 FiveSecRangeStream 中;-- 适用于所有事件;
推荐阅读
- css - 当有 2 个连续段落时省略边框
- objective-c - 将自己的 Objective-C 框架添加到 Swift 项目
- cmake - 在 CMAKE 自定义命令中运行 objcopy 会导致 make 期间出错
- maven - 新的 GWT Maven 插件
- java - @target 和 @within 之间的区别(Spring AOP)
- .net - 实体框架,如 Cosmos DB 的 ORM
- android - ReActiveAndroid - 未找到引用的数据库信息
- clips - 剪辑 6.3 CLIPSDLL.h 如何从 c 中修改一个事实?
- r - R中2个数据帧的时间值之间的条件合并
- cvxpy - 为什么 CVXPY 求解器会违反这个简单的约束