我有一个hive字段,类型为字符串,其时间戳的格式如下:hh:mm:ss mm:ss ss 我需要将它们转换为以下格式。
Input:
10:30:40
30:40
40
Output Expected:
10:30:40 = (10*3600) + (30 * 60) + 40 = 37,840
30:40 = (30 * 60) + 40 = 1840
40 = 40 = 40
我试着做这样的事情
case
when duration like '%:%:%' then
split(duration, ':')[0] * 3600 +
split(duration, ':')[1] * 60 +
split(duration, ':')[2]
when duration like '%:%' then
split(duration, ':')[0] * 60 +
split(duration, ':')[1]
else
duration
end
当我要处理数十亿条记录时,是否有更好的方法来完成同样的工作。
1条答案
按热度按时间fd3cxomn1#
你的表达式在hive中执行时不会产生很多额外的负载。你可以使用
unix_timestamp
函数来简化查询,但它的运行速度不会更快。结果。
或者更简单。
返回完全一样的。