我的JSON文件是一个时间戳字段,采用UNIX上传时间戳格式,如1501580484655
。这会转换为GMT:01-08-2017 9:41:24.655
AM
我尝试将此时间戳转换为人类可读的时间格式,直到毫秒为止。
到目前为止我已经尝试过了:
1- select TO_DATE(1501580484655) from (VALUES(1));
O / P是2017-08-01
,直到日期还可以,但我想要到毫秒。
2- select TO_DATE(1501580484655,'yyyy-MM-dd HH:mm:ss.SSS') from (VALUES(1));
O / P是:Error: SYSTEM ERROR: IllegalArgumentException: Invalid format: "1501580484655" is malformed at "4655"
3- select TO_DATE(1501580484,'yyyy-MM-dd HH:mm:ss.SSS') from (VALUES(1));
O / P是:Error: SYSTEM ERROR: IllegalArgumentException: Invalid format: "1501580484" is malformed at "4"
4- select TO_DATE(150158048,'yyyy-MM-dd HH:mm:ss.SSS') from (VALUES(1));
O / P是:Error: SYSTEM ERROR: IllegalArgumentException: Invalid format: "150158048" is too short
5- SELECT TO_TIMESTAMP(1501580484655) from (VALUES(1));
这虽然有效。 O / P为49553-03-11 18:10:55.0
。当我删除最后三个字符655然后我得到O / P为2017-08-01 09:41:24.0
但是当我从json文件在我的上传时间戳列上运行此查询时,我得到:
5a - select TO_TIMESTAMP(SUBSTR((cast(UploadTimeStamp as INTEGER)),1,10)) from dfs.root.
/ test / limit 5;
O / P是:
`Error: SYSTEM ERROR: SchemaChangeException: Failure while trying to materialize incoming schema. Errors:
Error in expression at index -1. Error: Missing function implementation: [castTINYINT(VARCHAR-OPTIONAL)]. Full expression: --UNKNOWN EXPRESSION--..
Fragment 1:3
[Error Id: 7a91a9f8-9776-4f0d-9b9f-da3e65cc282a on rjio-devcluster1-BigdataNode1:31010] (state=,code=0)
尝试转换为各种数据类型,但同样的错误即将发生。尝试没有演员而且出现同样的错误。
将O / P作为2017-08-01 HH:mm:ss.SSS
答案 0 :(得分:2)
要在输出时间戳值中查看millis,可以将浮点数指定为to_timestamp()函数的参数:
0: jdbc:drill:zk=local> SELECT TO_TIMESTAMP(1427936330) FROM (VALUES(1));
+------------------------+
| EXPR$0 |
+------------------------+
| 2015-04-02 00:58:50.0 |
+------------------------+
1 row selected (1.612 seconds)
0: jdbc:drill:zk=local> SELECT TO_TIMESTAMP(1427936330.456) FROM (VALUES(1));
+--------------------------+
| EXPR$0 |
+--------------------------+
| 2015-04-02 00:58:50.456 |
+--------------------------+
答案 1 :(得分:1)
看起来您应该对数据使用substr
,然后转换为INT。
对我来说它有效:
的 test.json:强> { “timestamp”:1501580484655 }
0: jdbc:drill:zk=local> select to_timestamp(cast(substr(`timestamp`,
1, 10) as INTEGER)) from dfs.`tmp/test.json`;
+------------------------+
| EXPR$0 |
+------------------------+
| 2017-08-01 02:41:24.0 |
+------------------------+
答案 2 :(得分:1)
从记录文件中选择timestamp列后,这很有效。
select to_timestamp(cast(CONCAT(substr(`Timestamp`, 1 , 10),'.',substr(`Timestamp`, CHAR_LENGTH(`Timestamp`)-3, 3)) as FLOAT)) from dfs.root.`/test/`;
+--------------------------+
| EXPR$0 |
+--------------------------+
| 2017-08-04 10:00:01.792 |
+--------------------------+