为什么施放时间戳会给出两个不同的结果

时间:2016-12-22 05:39:26

标签: sql hadoop apache-spark hive

我有一个包含两行的hive表:

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)

1 个答案:

答案 0 :(得分: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;