试图隐瞒ToDate格式

时间:2019-06-12 20:32:13

标签: apache-pig

我的输入内容很长“ 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"

1 个答案:

答案 0 :(得分:0)

问题是您将格式指定为yyyyMMdd,但原始输入是yyyyMMddHHmmss格式,因此当Pig到达143744而不是结尾时,会出现错误您的字符串。试试这个:

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