HIVE时间转换问题

我们正在从src“ 2019-11-03 01:01:00”获得时间。 2019-11-03是日光节约日。 可以说这是end_time。蜂巢表start_time中还有另一列。 得出开始时间的逻辑是: start_time = (end_time- 3600)

问题##:

当我们在执行unix_timestamp()的作业期间应用相同的逻辑时,结果如下。

Start_time =
select from_unixtime(unix_timestamp('2019-11-03 01:01:00') - 3600,'yyyy-MM-dd HH:mm:ss');
+----------------------+--+
|         _c0          |
+----------------------+--+
| 2019-11-03 01:01:00  |
+----------------------+--+

End_time = select from_unixtime(unix_timestamp('2019-11-03 01:01:00'),'yyyy-MM-dd HH:mm:ss');

+----------------------+--+
|         _c0          |
+----------------------+--+
| 2019-11-03 01:01:00  |
+----------------------+--+

两个都返回相同的结果。这样,我们的start_date = end_date是无法预期的。 我们想要End_time = "2019-11-03 00:01:00" 有人可以帮忙!

q247877488 回答:HIVE时间转换问题

您遇到的问题是HIVE-14305

解决方案可以是使用bash计算日期并将其作为变量传递给脚本:

initial_date="2019-11-03 01:01:00"
datesec="$(date '+%s' --date="$initial_date")"
result_date=$( date --date="@$((datesec - 3600))" "+%Y-%m-%d %H:%M:%S")
echo $result_date

#result 2019-11-03 00:01:00

#call your script like this

hive -hiveconf result_date="$result_date" -f script_name

#In the script use '${hiveconf:result_date}'
本文链接:https://www.f2er.com/2571452.html

大家都在问