greenplumsql到hivesql迁移

bmp9r5qi  于 2021-07-13  发布在  Hive
关注(0)|答案(2)|浏览(375)

我们必须将greenplumsql迁移到hivesql,如下所示,请帮助我们。

to_date(b.birthday,'yyyymmddhh24miss')
extract(year from age(iDATE, to_date(b.birthday,'yyyymmddhh24miss')))

上面的两条语句需要将sql转换为hive。请帮帮我。
配置单元版本:3.1.x

nue99wik

nue99wik1#

相当于 to_date(b.birthday,'yyyymmddhh24miss')

from_unixtime(unix_timestamp(b.birthday,'yyyyMMddHHmmss'))

然而,我不明白这一点 extract(year from age(iDATE, to_date(b.birthday,'yyyymmddhh24miss'))) . 你需要不同的出生日期和出生日期吗?
如果是,您可以使用以年为单位获取日期差异。

datediff(iDate,from_unixtime(unix_timestamp(b.birthday,'yyyyMMddHHmmss')) )/365

Hive也有 extract (year from datetimestamp) 功能。

fruv7luv

fruv7luv2#

提取时间戳的另一种方法是使用regexp\u replace:

regexp_replace(b.birthday,'^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})$','$1-$2-$3 $4:$5:$6')

年龄单位为:

cast(datediff(current_date,
             regexp_replace(b.birthday,'^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})$','$1-$2-$3 $4:$5:$6')
             )/365.25 as int)

相关问题