【问题标题】:Unable to create a generic date conversion class in DataFlow Apache beam无法在 DataFlow Apache Beam 中创建通用日期转换类
【发布时间】:2017-08-03 12:44:40
【问题描述】:

我正在尝试使用以下代码在DataFlow 中创建一个用于日期转换的通用类:

class DateConversion
{
    private static final StringBuffer appendable = null;

    public String dateConversion(String InputdateFormat, String OutputdateFormat, String date1) throws ParseException
    {
        DateFormat CurrentDateFormat = new SimpleDateFormat(InputdateFormat);
        DateFormat RequireDateFormat = new SimpleDateFormat(OutputdateFormat);
        Date theDate = CurrentDateFormat.parse(date1);
        return theDate.toString();
    }
}

如果我以 YYYY-MM-DD HH:MM:SS 格式传递日期输入日期格式日期,那么我可以使用 DF 作业在 BigQuery 的 datetime/timestamp 列中成功加载数据。如果我以不同的格式(如 YYMMDD 或 MMDDYY)传递输入日期格式,则程序加载不正确的日期或由于不正确的日期格式而失败。请帮我把上面的代码通用化。

【问题讨论】:

    标签: google-bigquery google-cloud-dataflow apache-beam


    【解决方案1】:

    那么问题是您需要支持许多不同的日期格式吗?也许这样的事情会有所帮助?

    How to parse dates in multiple formats using SimpleDateFormat

    【讨论】:

    • SimpleDateFormat 不是线程安全的,因此在Embarrassigly parallel 环境中使用它是一个坏主意
    猜你喜欢
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多