蜂巢日期铸造斩千秒

问题描述:

下面的日期铸造不显示毫秒。蜂巢日期铸造斩千秒

select from_unixtime(unix_timestamp("2017-07-31 23:48:25.957" , "yyyy-MM-dd HH:mm:ss.SSS")); 

2017-07-31 23:48:25 

获得毫秒的方法是什么?

谢谢。

+0

https://*.com/questions/32237365/hive-from -unixtime-with-milliseconds –

+0

为什么不把它当作时间戳而不是字符串呢? –

由于这个字串是ISO格式,铸件可以做简单的

hive> select cast("2017-07-31 23:48:25.957" as timestamp); 
OK 
2017-07-31 23:48:25.957 

hive> select timestamp("2017-07-31 23:48:25.957"); 
OK 
2017-07-31 23:48:25.957 

因为unix_timestamp基于秒,它会截断毫秒。

相反,您可以使用date_format将字符串转换为时间戳记,该日期格式保留了毫秒。然后from_utc_timestamp。

select from_utc_timestamp(date_format("2017-07-31 23:48:25.957",'yyyy-MM-dd HH:mm:ss.SSS'),'UTC') as datetime 
+0

是date_fromat蜂巢中有效的内置函数吗? – TKHN

+0

@TKHN是的,你可以从这里找到功能描述 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF – Wonjin

+0

其给我错误无效函数date_format ..我使用Hive 1.1.0 – TKHN