【问题标题】:PIG - convert input date into UTC timezonePIG - 将输入日期转换为 UTC 时区
【发布时间】:2016-02-09 04:37:34
【问题描述】:

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

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

我需要一个猪语法来将此日期转换为 UTC。我尝试使用 ToDate(input_date_column,'yyyy-MM-dd HH:mm:ss.SS','UTC') 但它不起作用。

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

任何帮助表示赞赏:)

【问题讨论】:

标签: hadoop timezone apache-pig utc


【解决方案1】:

我真的找不到这个的构建方法

所以我写了一个用户定义的函数并将其用于我的猪脚本

事情是这样的——

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);
            }
        }
    }

【讨论】:

    猜你喜欢
    • 2011-08-30
    • 2021-03-12
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 2021-07-03
    相关资源
    最近更新 更多