Hive:如何计算时差 [英] Hive: How to calculate time difference

查看:638
本文介绍了Hive:如何计算时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求很简单,就是如何计算配置单元中两列之间的时间差

示例 p>


Time_Start: 10:15:00

Time_End : 11:45:00



我需要做的(Time_End-Time_Start)= 1:30:00


请注意,这两列都在String数据类型中,有助于获得所需的结果..

解决方案

语言手册包含所有可用日期时间函数的说明。以秒为单位的差值可以这样计算: hour(time_end)* 3600 + minute(time_end)* 60 + second(time_end) - hour(time_start)* 3600 - minute(time_start)* 60 - second (TIME_START)。您可以用 from_unixtime(...,'HH:mm:ss')来包装它以获得格式化的时差。



编写UDF 可能会更好而不是将所有这些放到您的查询中。


My requirement is simple how to calculate the time difference between two column in hive

Example

Time_Start: 10:15:00

Time_End: 11:45:00

I need to do (Time_End-Time_Start) =1:30:00

Note both the columns are in String datatype kindly help to get required result..

解决方案

Language manual contains description of all available datetime functions. Difference in seconds can be calculated in such way: hour(time_end) * 3600 + minute(time_end) * 60 + second(time_end) - hour(time_start) * 3600 - minute(time_start) * 60 - second(time_start). You can wrap it with from_unixtime(..., 'HH:mm:ss') to get formatted time diff.

It might be better to write a UDF instead of putting all this into your query.

这篇关于Hive:如何计算时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆