【问题标题】:Why cast as timestamp give out two different result为什么转换为时间戳会给出两个不同的结果
【发布时间】:2017-05-07 16:24:12
【问题描述】:

我有一个像这样有两行的蜂巢表:

0: jdbc:hive2://localhost:10000/default> select * from t2;
+-----+--------+
| id  | value  |
+-----+--------+
| 10  | 100    |
| 11  | 101    |
+-----+--------+
2 rows selected (1.116 seconds)

但是当我发出查询时:

select cast(1 as timestamp) from t2;

结果不一致,谁能告诉我原因?

0: jdbc:hive2://localhost:10000/default> select cast(1 as timestamp) from t2;
+--------------------------+
|           _c0            |
+--------------------------+
| 1970-01-01 07:00:00.001  |
| 1970-01-01 07:00:00.001  |
+--------------------------+
2 rows selected (0.913 seconds)
0: jdbc:hive2://localhost:10000/default> select cast(1 as timestamp) from t2;
+--------------------------+
|           _c0            |
+--------------------------+
| 1970-01-01 08:00:00.001  |
| 1970-01-01 07:00:00.001  |
+--------------------------+
2 rows selected (1.637 seconds)

【问题讨论】:

  • casecast?
  • 强制转换,将 int 转换为时间戳
  • 顺便说一句,你为什么要这样做?

标签: sql hadoop apache-spark hive


【解决方案1】:

我无法重现您的问题,您使用的是哪个 Hive 版本? Hive 有一个带有时间戳和 bigint 的错误(请参阅https://issues.apache.org/jira/browse/HIVE-3454),但这并不能解释您的问题。例如 Hive 0.14 给出了不同的结果

SELECT (cast 1 as timestamp), cast(cast(1 as double) as timestamp) from my_table limit 5;

【讨论】:

    猜你喜欢
    • 2016-03-17
    • 1970-01-01
    • 2013-05-15
    • 2012-06-09
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多