【问题标题】:How to update table in Hive 0.13?如何更新 Hive 0.13 中的表?
【发布时间】:2017-11-28 22:18:02
【问题描述】:

我的 Hive 版本是 0.13。我有两张桌子,table_1table_2

table_1 包含:

customer_id | items | price | updated_date
------------+-------+-------+-------------
10          | watch | 1000  | 20170626
11          | bat   | 400   | 20170625

table_2 包含:

customer_id | items    | price | updated_date
------------+----------+-------+-------------
10          | computer | 20000 | 20170624

如果customer_id已经存在,我想更新table_2的记录,如果没有,它应该追加到table_2

由于 Hive 0.13 不支持更新,我尝试使用 join,但失败了。

【问题讨论】:

    标签: hadoop hive hiveql acid


    【解决方案1】:

    您可以使用row_numberfull join。这是使用row_number 的示例:

    insert overwrite table_1 
    select customer_id, items, price, updated_date
    from
    (
    select customer_id, items, price, updated_date,
           row_number() over(partition by customer_id order by new_flag desc) rn
    from 
        (
         select customer_id, items, price, updated_date, 0 as new_flag
           from table_1
         union all
         select customer_id, items, price, updated_date, 1 as new_flag
           from table_2
        ) all_data
    )s where rn=1;
    

    另请参阅此答案以使用FULL JOIN进行更新:https://stackoverflow.com/a/37744071/2700344

    【讨论】:

      猜你喜欢
      • 2020-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-01
      • 2017-08-12
      • 2019-08-20
      • 1970-01-01
      相关资源
      最近更新 更多