我的 hive 表中有一个JSON数据,其中包含以下格式的时间(以毫秒为单位):
...."internal":{"time":["1393404205891"]....
我想以
YYYY-MM-DD HH:MM:SS
格式获取时间,以便稍后查询以便仅获取特定时间段的记录。我尝试了以下方法,但仍无法以所需的格式获取时间。
第一次尝试:
select from_unixtime(cast(get_json_object(log_json,'$.internal.time[0]') as bigint)/1000, 'YYYY-MM-DD HH:MM:SS') as time_unix
from slog_table
错误:
No matching method for class org.apache.hadoop.hive.ql.udf.UDFFromUnixTime with (double, string)
第2次尝试:
select from_unixtime (cast ('1393526016039' as int)/1000, 'YYYY-MM-DD HH:MM:SS') as time_unix
from slog_table
最佳答案
下面的查询应该工作:
从from_unixtime中选择(cast(1393526016039/1000 as bigint),'YYYY-MM-dd HH:mm:SS')作为time_unix
来自slog_table
关于json - 在Hive中将时间戳转换为Hive格式时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22103628/