如何确保在使用MySQL插件导入数据后,数据类型精度保持不变?

huangapple go评论80阅读模式
英文:

How to ensure the data type precision remains the same after importing data with MySQL plugin?

问题

从MySQL使用DolphinDB MySQL插件导入DATETIME类型的数据时,我发现毫秒部分被丢弃了。例如,2023.12.12 09:12:01 500被更改为2023.12.12 09:12:01。

我尝试使用以下脚本解决这个问题:

db=database("dfs://test6", VALUE, `ag2306`fu2305`fu2309)
def replaceTable(mutable t){return t.replaceColumn!(`datetime,nanotimestamp(t[`datetime]))}
t=mysql::loadEx(conn, db, "tb", `symbol, "SELECT * FROM dbtickdata LIMIT 100",,,,,replaceTable)

然而,尽管数据类型已被替换,结果仍然不是我期望的。有谁知道如何解决这个问题?

英文:

When importing data of type DATETIME from MySQL with DolphinDB MySQL plugin, I found that the milliseconds were discarded. For example, 2023.12.12 09:12:01 500 was changed to 2023.12.12 09:12:01.

I have tried to solve this problem with the following script:

db=database("dfs://test6", VALUE, `ag2306`fu2305`fu2309)
def replaceTable(mutable t){return t.replaceColumn!(`datetime,nanotimestamp(t[`datetime]))}
t=mysql::loadEx(conn, db, "tb",`symbol, "SELECT * FROM dbtickdata LIMIT 100",,,,replaceTable)

However, the result is still not what I expected, even though the data type has been replaced. Does anyone know how to solve this problem?

答案1

得分: 1

造成这个问题的原因是MySQL插件将MySQL的DATETIME解析为DolphinDB的DATETIME,而DolphinDB的DATETIME不支持比秒更高的精度。因此,当您将表传递给mysql::loadExtransform时,其列的时间类型已经是DolphinDB的DATETIME。更高精度的尾数秒部分已被丢弃。

要解决这个问题,请参考以下步骤:

  1. 使用mysql::extractSchema获取MySQL表的架构;
  2. 在架构表中将类型为DATETIME的列更新为NANOTIMESTAMP;
  3. 将架构表传递给mysql::loadEx的架构。
英文:

The cause is that the MySQL plugin parses the MySQL’s DATETIME into the DolphinDB’s DATETIME, which doesn’t support a higher precision than seconds. So when you pass a table to the transform of mysql::loadEx, the time type of its column has already been DolphinDB’s DATETIME. The trailing fractional seconds part in higher precision has been discarded.

To solve this problem, refer to the following steps:

  1. use mysql::extractSchema to get the schema of the MySQL table;
  2. update the column of type DATETIME to NANOTIMESTAMP in the schema
    table;
  3. pass the schema table to the schema of mysql::loadEx.

huangapple
  • 本文由 发表于 2023年5月25日 13:48:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76329259.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定