如何在 impala 中将一行结果拆分为两行
how to split one row of result in to two rows in impala
以下是要求,需要转换成SQL。
我只会从源收到一条记录,但我需要验证以下条件并将其分成两行 impala。
final_columns
来源的预期值为 ('IC', 'OG', 'BK')
。
仅当我在 final_columns
中收到值 'BK'
时,我才需要检查以下条件。
if (final_columns in ('BK')) {
split into rows based on below conditions
when dr_type = 'IT' THEN dr_cid else dr_pid
when cr_type = 'OR' THEN cr_cid else cr_pid
}
else {
value as it is in source final columns
}
你能试试这个吗sql?我创建了虚拟内联视图来复制数据。
select
case when final_columns in ('BK') AND
case when dr_type = 'IT' THEN dr_cid
when dr_type <> 'IT' THEN dr_pid
when cr_type = 'OR' THEN cr_cid
when cr_type <> 'OR' THEN cr_pid
END
else final_columns
end
from
table,
( select 1 col union all select 1 union all select 2 ) dummy_record_creation
where
case when final_columns in ('BK') then 1 else 2 end = dummy_record_creation.col
以下是要求,需要转换成SQL。
我只会从源收到一条记录,但我需要验证以下条件并将其分成两行 impala。
final_columns
来源的预期值为 ('IC', 'OG', 'BK')
。
仅当我在 final_columns
中收到值 'BK'
时,我才需要检查以下条件。
if (final_columns in ('BK')) {
split into rows based on below conditions
when dr_type = 'IT' THEN dr_cid else dr_pid
when cr_type = 'OR' THEN cr_cid else cr_pid
}
else {
value as it is in source final columns
}
你能试试这个吗sql?我创建了虚拟内联视图来复制数据。
select
case when final_columns in ('BK') AND
case when dr_type = 'IT' THEN dr_cid
when dr_type <> 'IT' THEN dr_pid
when cr_type = 'OR' THEN cr_cid
when cr_type <> 'OR' THEN cr_pid
END
else final_columns
end
from
table,
( select 1 col union all select 1 union all select 2 ) dummy_record_creation
where
case when final_columns in ('BK') then 1 else 2 end = dummy_record_creation.col