Hive 如何更新配置单元表行
我有一张这样的桌子:Hive 如何更新配置单元表行,hive,presto,Hive,Presto,我有一张这样的桌子: id | Col2 | Col3 | Text -------------------------- 1 | ... | ... | "abc" 2 | ... | ... | "def 3 | ... | ... | "ghi" 4 | ... | ... | "jkl" id | Text ------------- 1 | &qu
id | Col2 | Col3 | Text
--------------------------
1 | ... | ... | "abc"
2 | ... | ... | "def
3 | ... | ... | "ghi"
4 | ... | ... | "jkl"
id | Text
-------------
1 | "qwe"
2 | "rty"
id | Col2 | Col3 | Text
--------------------------
1 | ... | ... | "qwe"
2 | ... | ... | "rty"
3 | ... | ... | "ghi"
4 | ... | ... | "jkl"
另一张表如下所示:
id | Col2 | Col3 | Text
--------------------------
1 | ... | ... | "abc"
2 | ... | ... | "def
3 | ... | ... | "ghi"
4 | ... | ... | "jkl"
id | Text
-------------
1 | "qwe"
2 | "rty"
id | Col2 | Col3 | Text
--------------------------
1 | ... | ... | "qwe"
2 | ... | ... | "rty"
3 | ... | ... | "ghi"
4 | ... | ... | "jkl"
最后我想得到一张像这样的桌子:
id | Col2 | Col3 | Text
--------------------------
1 | ... | ... | "abc"
2 | ... | ... | "def
3 | ... | ... | "ghi"
4 | ... | ... | "jkl"
id | Text
-------------
1 | "qwe"
2 | "rty"
id | Col2 | Col3 | Text
--------------------------
1 | ... | ... | "qwe"
2 | ... | ... | "rty"
3 | ... | ... | "ghi"
4 | ... | ... | "jkl"
其中col2和col3的原始值保持不变。本质上,我想使用表2中的值来更新表1中ID相同的值
我试过:
SELECT
A.id,
col1,
col2,
A.text
FROM table1 AS A
LEFT JOIN (
SELECT
id,
text
FROM table2
) AS B
ON A.product_id = B.product_id
但这只是返回了原来的表。有什么方法可以实现我在Presto/Hive中想要的吗?如果要更新表B中存在的值,而不存在则保持原样(请参阅代码中的注释),则从表a加载文本,应该从表B或
NVL(B.Text,a.Text)
您可以使用
coalesce(B.text,A.text)
而不是NVL
,正如@PiotrFindeisen所提到的,它也可以在Presto和Hive上正常工作。您可能希望用于标准的便携式解决方案。@PiotrFindeisen是的,您是对的。coalesce()代替NVL()在Presto和Hive上也能很好地工作。我使用了coalesce,它工作得很好!非常感谢,我以前不知道函数存在:)