- hive是不支持13位的時(shí)間戳的,只支持10位的時(shí)間戳
解決方式:
1,除以1000后,轉(zhuǎn)化為bigint
select from_unixtime(cast(1483675004884/1000 as bigint),"yyyy-MM-dd HH:mm:ss");
2,自己寫個(gè)udf.
時(shí)間戳轉(zhuǎn)化問題 vtime是string類型,值為 1483675004884,使用hive中的from_unixtime轉(zhuǎn)化是一下情況,年份錯(cuò)誤.

Paste_Image.png
udf樣例如下:
create function sda_db.formatTimes as 'com.sda.udf.FormatTimes';
然后使用 formatTimes(vtime,'yyyy-MM-dd') 就可以了.
public class FormatTimes extends UDF {
public String evaluate(String s, String format) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
long lt = new Long(s);
Date date = new Date(lt);
return simpleDateFormat.format(date);
}
}