更新表 |黑斑羚 | SQL | Hadoop
Posted
技术标签:
【中文标题】更新表 |黑斑羚 | SQL | Hadoop【英文标题】:Updates to a Table | Impala | SQL | Hadoop 【发布时间】:2021-07-29 03:55:55 【问题描述】:我在 Hadoop 上构建了表。这些是黑斑羚表。 (不是 Kudu)。
问题:我必须为 final_up_2 表中的一组键(dw、auth、ulti_date)更新 ulti_up_2 表中的几个 cols 值(例如:load_date、fraud_type)。
我有以下提到的用例:- 表一:
create table dbo.ulti_up_2 (
dw string
,auth int
,ulti_date string
,load_date string
,fraud_type string
),
insert into dbo.ulti_up_2
values ('b',1,'2021-07-25','2021-07-27','x'),
('c',0,'2021-07-25','2021-07-27','y');
Table 2:
create table dbo.final_up_2 (id int,auth_date string,dw string,auth int,ulti_date string,load_date string,fraud_type string)
insert into dbo.final_up_2 values
(1,'2021-07-24','a',1,'2021-07-25','2021-07-25','p'),
(2,'2021-07-24','b',1,'2021-07-25','2021-07-25','q'),
(3,'2021-07-24','c',0,'2021-07-25','2021-07-25','t'),
(4,'2021-07-24','d',1,'2021-07-25','2021-07-25','r');
create table dbo.refresh_table1 as
select df_prep.id,df_prep.auth_date,df_prep.dw,df_prep.auth,df_prep.ulti_date,
ulti_prep.fraud_type,ulti_prep.load_date
from dbo.final_up_2 df_prep
left join
dbo.ulti_up_2 ulti_prep
on df_prep.dw=ulti_prep.dw and
df_prep.auth=ulti_prep.auth and
df_prep.ulti_date=ulti_prep.ulti_date;
Output Coming :
id|auth_date|dw|auth|ulti_date|fraud_type|load_date
(1,'2021-07-24','a',1,'2021-07-25',NULL,NULL),
(2,'2021-07-24','b',1,'2021-07-25','x','2021-07-27'),
(3,'2021-07-24','c',0,'2021-07-25','y','2021-07-27'),
(4,'2021-07-24','d',1,'2021-07-25',NULL,NULL);
Output I need :
id|auth_date|dw|auth|ulti_date|fraud_type|load_date
(1,'2021-07-24','a',1,'2021-07-25','p','2021-07-25'),
(2,'2021-07-24','b',1,'2021-07-25','x','2021-07-27'),
(3,'2021-07-24','c',0,'2021-07-25','y','2021-07-27'),
(4,'2021-07-24','d',1,'2021-07-25','r','2021-07-25');
Thanks in Advance. Please Help.
【问题讨论】:
【参考方案1】:这是因为 ulti_up_2
的左连接在某些情况下会失败。如果你处理它们,你应该得到数据。
create table dbo.refresh_table1 as
select df_prep.id,df_prep.auth_date,df_prep.dw,df_prep.auth,df_prep.ulti_date,
ifnull(ulti_prep.fraud_type,df_prep.fraud_type) as fraud_type , --This will fetch data from final_up_2 in case left join fails.
ifnull(ulti_prep.load_date,df_prep.load_date) as load_date --This will fetch data from final_up_2 in case left join fails.
from dbo.final_up_2 df_prep
left join
dbo.ulti_up_2 ulti_prep
on df_prep.dw=ulti_prep.dw and
df_prep.auth=ulti_prep.auth and
df_prep.ulti_date=ulti_prep.ulti_date;
【讨论】:
以上是关于更新表 |黑斑羚 | SQL | Hadoop的主要内容,如果未能解决你的问题,请参考以下文章