尝试将long转换为todate格式

fnatzsnv  于 2021-06-24  发布在  Pig
关注(0)|答案(1)|浏览(384)

我的输入是长“20190503143744”,希望转换为格式“2019-09-06 11:46:22”
尝试以下代码:

A = LOAD 'stp_master_subscriber_profile' using org.apache.hive.hcatalog.pig.HCatLoader() as (mdn:chararray, imei:chararray, imsi:chararray, subscriber_id:long, manufacturer:chararray, model:chararray, update_time:long, scenario:chararray, vz_customer:chararray, commit_time:long);
B = FOREACH A GENERATE ToString(ToDate((chararray)commit_time,'yyyyMMdd'),'yyyy-MM-dd HH:mm:ss') as event_date_gmt:chararray;

获取错误:

ERROR 1066: Unable to open iterator for alias B. Backend error : org.apache.pig.backend.executionengine.ExecException: ERROR 0: Exception while executing [POUserFunc (Name: POUserFunc(org.apache.pig.builtin.ToDate2ARGS)[datetime] - scope-15 Operator Key: scope-15) children: null at []]: java.lang.IllegalArgumentException: Invalid format: "20190503143744" is malformed at "143744"
8gsdolmq

8gsdolmq1#

问题是您将格式指定为 yyyyMMdd 但你最初的想法是 yyyyMMddHHmmss 格式,所以当pig到达 143744 而不是你的绳子的末端。试试这个:

B = FOREACH A GENERATE ToString(ToDate((chararray)commit_time,'yyyyMMddHHmmss'),
    'yyyy-MM-dd HH:mm:ss') as event_date_gmt;

相关问题