[英]How to update table in Hive 0.13?
我的 Hive 版本是 0.13。 我有兩個表, table_1
和table_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,但失敗了。
您可以使用row_number
或full 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.