【问题标题】:Insert record in impala table based on datatype and column name根据数据类型和列名在 impala 表中插入记录
【发布时间】:2016-02-24 14:42:13
【问题描述】:

我有一些格式是这样的黑斑羚表。

+--------------------------+-----------+---------+
| name                     | type      | comment |
+--------------------------+-----------+---------+
| col_key                   | bigint    |         |
| col_cd                    | smallint  |         |
| col_desc                  | string    |         |
| col_type_cd               | string    |         |
| col_scheme_cd             | string    |         |
| name                      | string    |         |
| source_cd                 | string    |         |
| source_cd1                | bigint    |         |
| load_dt                   | timestamp |         |
| effective_start_dt        | timestamp |         |
| effective_end_dt          | timestamp |         |
+--------------------------+-----------+---------+

我必须像这样插入值

如果数据类型是

bigint then insert      0
smallint then insert    0
decimal then  insert    0.0
float then insert       0.0
string then insert      unknown
timestamp then insert   1970-01-01 00:00:00

如果列名是

effective_start_dt then insert 1970-01-01 00:00:00
effective_end_dt then insert   3499-12-31 00:00:00

我已经实现了一种解决方案,我能够识别数据类型并基于 我正在插入记录,但它不适用于我的第二种情况,即我根据列名插入记录并插入 1970-01-01 00:00:00 vale for effective_end_dt

在这方面寻求帮助。 其他表的列位置可能会有所不同,因此我正在尝试一些通用解决方案。我正在尝试从 shell 脚本中实现此解决方案。

【问题讨论】:

    标签: linux shell hadoop hive impala


    【解决方案1】:

    您需要将字符串转换为时间戳

    cast("1979-01-01 00:00:00" as timestamp)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-07
      相关资源
      最近更新 更多