【问题标题】:Impala convert timestamp AM/PMImpala 转换时间戳 AM/PM
【发布时间】:2021-12-29 15:51:11
【问题描述】:

我在 hive 中有表,字符串格式为 12 小时 每天都会在其中附加数据。我无法控制蜂巢表。转换后需要在 impala 中公开为视图。 to_timestamp() 不支持 AM/PM 格式。

我们有没有更好的方法将 12 小时格式的字符串转换为时间戳。

遇到了这个支持 AM/PM 的函数。它支持 ISO SQL:2016 标准模式。

CAST(表达式 AS 类型 FORMAT 模式)

impala conversion functions

我正在使用的 impala 版本不支持此功能。

我遇到的其他方式:

  1. 如果是下午,则将 hh:mm 添加 12 小时。
  2. 使用 unix_timestamp 将其在 Hive 中转换为 24 小时格式到其他表或视图,并通过 impala(需要在 impala 中将表公开为视图)

【问题讨论】:

    标签: hive impala


    【解决方案1】:

    你可以使用下面的函数吗?
    这将为您提供从带有 am/pm 的字符串到日期时间格式的数据。

    from_unixtime(unix_timestamp(string_with_ampm, 'MM/dd/yyyy hh:mm:ss a'))
    

    例子

    select from_unixtime(unix_timestamp('01/25/2021 09:58:37 AM', 'MM/dd/yyyy hh:mm:ss a')) c 
    union 
    select from_unixtime(unix_timestamp('01/25/2021 07:58:37 PM', 'MM/dd/yyyy hh:mm:ss a'))
    

    结果

    【讨论】:

    • 此查询仅适用于 hive,不适用于 impala,我直接尝试在 impala 中进行转换。 Impala 不支持时间格式的“a”。我唯一剩下的就是我提到的这两种方式。
    猜你喜欢
    • 2021-12-31
    • 2022-01-19
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2018-06-12
    • 2011-12-29
    • 1970-01-01
    • 2021-10-09
    相关资源
    最近更新 更多