Tips: If you use a computer to view the picture is not clear, you can use the phone to open the text of the article click photo to enlarge view high-definition picture.
Fayson the GitHub:
https://github.com/fayson/cdhproject
Tip: block portion can slide see Oh
1
Documents written in Objective
Hive when using TimeStamp, timestamp default is accurate to the second, how to deal with a time stamp that require accurate to the millisecond in the Hive in it? This article Fayson mainly explained under conversion and use Hive timestamp.
- test environment
1.RedHat7.2
2.CM and CDH version 5.15.0
2
Hive in TimeStamp acquisition and conversion
In 1.Hive use current_timestamp () function to get the current time
select current_timestamp();
Hive using the CURRENT_TIMESTAMP () function to get the current time to the millisecond.
2.Hive get the current timestamp default unix_timestamp () function
select unix_timestamp(current_timestamp());
The Hive UNIX_TIMESTAMP use () function to get the current time stamp is 10-bit type bigint value which is only accurate to the second level.
3.Hive will be converted to a date stamp type, default FROM_UNIXTIME ()
select from_unixtime(1543735779, 'yyyy-MM-dd HH:mm:ss:SSS');
The results can be seen above the conversion time is millisecond can not obtain, because the timestamp is only accurate to the second level, from_unixtime () function only supports the second level of the timestamp conversion.
4.Hive acquired millisecond level timestamp
select current_timestamp(), cast(current_timestamp() as double) * 1000 as timestamp;
Here you can see obtained a 13-bit value which is the current precise time to the millisecond timestamp.
5.Hive processing milliseconds timestamp
select to_utc_timestamp(1543736635303, 'GMT');
Hive to_utc_timestamp provided using time stamp () function to convert milliseconds corresponding to time and precisely millisecond, and the step of obtaining a consistent time stamp.
3
to sum up
1.Hive acquired timestamp way UNIX_TIMESTAMP () function, which is only accurate to the level of the second time, the exact time for the demanding applications are not suitable for the function.
2.Hive获取当前时间毫秒级别的时间戳时需要使用cast函数将current_timestamp()转为double类型并乘以1000,则得到毫秒级别的时间戳。
3.对于Hive库中存储的毫秒精度的时间戳,为了确保时间精度不损失则需要使用to_utc_timestamp()函数,该函数支持毫秒级别的时间错,但需要指定当前时区。
提示:代码块部分可以左右滑动查看噢
为天地立心,为生民立命,为往圣继绝学,为万世开太平。
温馨提示:如果使用电脑查看图片不清晰,可以使用手机打开文章单击文中的图片放大查看高清原图。
推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。