Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

怎么导入特殊时间类型的数据 ?

我有一个csv文件,其中时间列后面多一个字符Z,样本数据如下所示:

code,ts,close,volume
TXFL9,2019.12.17T01:54:01.001123321Z,12001,1
TXO12400A0,2019.12.17T01:54:01.867000123Z,30,10
UDFL9,2019.12.17T01:54:04.381321124Z,28313,1
...

现在我想用下列代码导入数据到DolphinDB database分布式表中,可是没成功:

dbName = "dfs://db1"
path = "d:/ticks.csv"
if(existsDatabase(dbName)){
 dropDatabase(dbName)
}
db = database(dbName,VALUE,2019.09.04..2020.10.09)
modaltb = table(1:0, `code`timestamp`close`volume,[SYMBOL,TIMESTAMP,DOUBLE,DOUBLE])
db.createPartitionedTable(modaltb, `trade,`timestamp)

schemaTb=extractTextSchema(path)
update schemaTb set type=`NANOTIMESTAMP where name=`ts ;
loadTextEx(dbHandle=db,tableName='trade', partitionColumns='timestamp',filename=path,schema=schemaTb)

请教一下该怎么实现?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

在将数据导入DolphinDB database中的数据库之前,若需要对数据进行预处理,例如转换日期和时间数据类型,填充空值等,可以在调用loadTextEx函数时指定transform参数。
以上问题可以自定义函数进行处理,代码如下:

schemaTb=extractTextSchema(path)
def d2t(mutable t){
    return t.replaceColumn!(`ts,temporalParse(t.ts,"yyyy.MM.ddTHH:mm:ss.nnnnnnnnnZ"))
}
tmpTB=loadTextEx(dbHandle=db,tableName=`trade,partitionColumns=`timestamp,filename=path,schema=schemaTb,transform=d2t);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...