pig-将输入日期转换为utc时区

dfuffjeb  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(514)

我有一个pst格式的日期输入文件

example => 2014-02-04 05:46:36.0

我需要一个pig语法来将这个日期转换成utc。我尝试使用todate(input\u date\u column,'yyyy-mm-dd hh:mm:ss.ss','utc'),但是没有成功。

Error shown - java.lang.IllegalArgumentException: Invalid format: ""2014-02-04 05:46:36.0""

感谢您的帮助:)

rjee0c15

rjee0c151#

我真的找不到这种方法的内部构建方法
因此,我编写了一个用户定义的函数,并将其用于我的pig脚本中
就像这样-

public class convertToUTC extends EvalFunc<String> {
        @Override
        public String exec(final Tuple input) throws IOException {
            if (input == null || input.size() == 0) {
                return null;
            }
            try {
                String date = input.get(0).toString();
                Timestamp timestamp = Timestamp.valueOf(date);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(timestamp);
                calendar.add(Calendar.HOUR, 8);
                Timestamp UTCTimestamp = new Timestamp(calendar.getTime().getTime());
                return UTCTimestamp.toString();
            }
            catch (Exception e) {
                throw WrappedIOException.wrap("Caught exception processing input row ", e);
            }
        }
    }

相关问题