如何根据 Hive 中的另一个 table b 替换 table a 中的值?
How to replace values in table a according another table b in Hive?
由于 Hive 不支持更新...
所以我想知道如何在 Hive 中实现它。
例如,我有 table A 和 Table B,它们与名为 user_id 的密钥链接。
那么register_date中有一些缺失值在tableA中,那些缺失的情况可以用b_date[=26来填补=] 在 table B.
因此,对于每个 user_id,如果 register_date(在 table A ) 丢失,那么我想用 b_date 中相应的值填充 table B.
有什么想法吗?非常感谢!
UPDATE 从 Hive 0.14 as mentioned here 开始可用。您有充分的理由立即升级。
如果你不能升级 Hive,你可以通过连接 table-A 和 table-B 然后删除 table-A 来创建一个新的 temp-table并将 temp-table 重命名为 table-A。
获取 Update Hive 0.14。
将tableA的数据移动到tableC。
然后在 Table B 和 Table C 上做一个连接(给出你的条件并相应地选择)。
然后插入到table A。
然后降 Table C.
插入TableC
Select * 来自 Table A
插入 TableA
Select user_id,if(TableC.register_date IS NULL ,TableB.b_date) FROM TableB 在 TableB.user_id=[= 上加入 TableC 23=]
下降 Table TableC;
您可以使用 case 语句来这样做:
假设您要更新 table_a 列名称 user_id .
如果 user_id 为 null 那么你想用 table B 的列更新 b_date 然后你可以通过触发下面的查询来做到这一点:
select 当 a.user_id 为 null 或 len(trim(user_id)==0) then b.b_date else a.user_id 的情况结束为 user_id from table_A a join table_B b on a.id=b.id;
由于 Hive 不支持更新... 所以我想知道如何在 Hive 中实现它。
例如,我有 table A 和 Table B,它们与名为 user_id 的密钥链接。 那么register_date中有一些缺失值在tableA中,那些缺失的情况可以用b_date[=26来填补=] 在 table B.
因此,对于每个 user_id,如果 register_date(在 table A ) 丢失,那么我想用 b_date 中相应的值填充 table B.
有什么想法吗?非常感谢!
UPDATE 从 Hive 0.14 as mentioned here 开始可用。您有充分的理由立即升级。
如果你不能升级 Hive,你可以通过连接 table-A 和 table-B 然后删除 table-A 来创建一个新的 temp-table并将 temp-table 重命名为 table-A。
获取 Update Hive 0.14。
将tableA的数据移动到tableC。 然后在 Table B 和 Table C 上做一个连接(给出你的条件并相应地选择)。 然后插入到table A。 然后降 Table C.
插入TableC Select * 来自 Table A
插入 TableA Select user_id,if(TableC.register_date IS NULL ,TableB.b_date) FROM TableB 在 TableB.user_id=[= 上加入 TableC 23=]
下降 Table TableC;
您可以使用 case 语句来这样做: 假设您要更新 table_a 列名称 user_id .
如果 user_id 为 null 那么你想用 table B 的列更新 b_date 然后你可以通过触发下面的查询来做到这一点:
select 当 a.user_id 为 null 或 len(trim(user_id)==0) then b.b_date else a.user_id 的情况结束为 user_id from table_A a join table_B b on a.id=b.id;