HIVeQL:有没有办法使用 SQL 将分号分隔值转换为多列,如附图中所述
HIveQL: Is there any way to convert semi colon separated value to multiple columns using SQL as mentioned in image attached
列 vasm 具有多个人的值(用户名和 ID),用分号分隔。要求是将用户名和 ID 分开,作为两个不同的 columns.Please 建议如何在 HiveQL 或 SQL.
中执行此操作
您可以使用 split
函数创建一个字符串数组,然后 select 每个数组元素:
with base as (
select split(vasm, ";") as part
from mytable
)
select part[0] as vasm_fullname, part[1] as vasm_username
from base
这是我的需求解决方案版本。如果有任何优化是可能的,那么请告诉我。
带底座
作为 (
SELECT 不同的案例
当 c.vasm 喜欢 '%;%'
然后拆分(c.vasm,“;”)
当 c.vasm 像 '%),%'
然后拆分(c.vasm,“,”)
否则分裂(c.vasm,“^”)
结束部分
FROM gcs_stage.apjgc_seller_report_renewals c 其中 c.vasm 不为 NULL
)
SELECT
部分 [1] 为 NULL 的情况
然后
substr(trim(部分[0]),1,instr(trim(部分[0]),'(')-1)
别的
concat((substr(trim(part [0]),1,instr(trim(part [0]),'(')-1)), (concat(', ',( substr(trim([1]部分),1,instr(trim([1]部分),'(')-1) ))))
结束为 vasm_fullname,
当 part[1] 为 NULL 时的 CASE
然后
substr(trim(部分[0]),instr(trim(部分[0]),'(')+1,(instr(trim(部分[0]), ')')-instr(trim(part [0]),'('))-1)
别的
concat((substr(trim(部分[0]),instr(trim(部分[0]),'(')+1,(instr(trim(部分[0] ]),')')-instr(trim(part [0]),'('))-1)), (concat(', ', (substr(trim(part [ 1]),instr(trim([1]部分),'(')+1 ,(instr(trim([1]部分),')')-instr(trim([1]部分),'('))-1)))))
结束为 vasm_username
从基地;
列 vasm 具有多个人的值(用户名和 ID),用分号分隔。要求是将用户名和 ID 分开,作为两个不同的 columns.Please 建议如何在 HiveQL 或 SQL.
中执行此操作您可以使用 split
函数创建一个字符串数组,然后 select 每个数组元素:
with base as (
select split(vasm, ";") as part
from mytable
)
select part[0] as vasm_fullname, part[1] as vasm_username
from base
这是我的需求解决方案版本。如果有任何优化是可能的,那么请告诉我。
带底座
作为 (
SELECT 不同的案例
当 c.vasm 喜欢 '%;%'
然后拆分(c.vasm,“;”)
当 c.vasm 像 '%),%'
然后拆分(c.vasm,“,”)
否则分裂(c.vasm,“^”)
结束部分
FROM gcs_stage.apjgc_seller_report_renewals c 其中 c.vasm 不为 NULL
)
SELECT
部分 [1] 为 NULL 的情况
然后
substr(trim(部分[0]),1,instr(trim(部分[0]),'(')-1)
别的
concat((substr(trim(part [0]),1,instr(trim(part [0]),'(')-1)), (concat(', ',( substr(trim([1]部分),1,instr(trim([1]部分),'(')-1) ))))
结束为 vasm_fullname,
当 part[1] 为 NULL 时的 CASE
然后
substr(trim(部分[0]),instr(trim(部分[0]),'(')+1,(instr(trim(部分[0]), ')')-instr(trim(part [0]),'('))-1)
别的
concat((substr(trim(部分[0]),instr(trim(部分[0]),'(')+1,(instr(trim(部分[0] ]),')')-instr(trim(part [0]),'('))-1)), (concat(', ', (substr(trim(part [ 1]),instr(trim([1]部分),'(')+1 ,(instr(trim([1]部分),')')-instr(trim([1]部分),'('))-1)))))
结束为 vasm_username
从基地;