数据湖探索 DLI-trans_array:示例代码

时间:2024-11-11 14:11:03

示例代码

为便于理解函数的使用方法,本文为您提供源数据,基于源数据提供函数相关示例。创建表salary,并添加数据,命令示例如下:
CREATE EXTERNAL TABLE salary (
dept_id STRING, -- 部⻔
user_id string, -- 员⼯ID
sal INT -- 薪⽔
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' 
stored as textfile;

添加数据如下:

d1,user1/user4,1000/6000
d1,user2/user5,2000/7000
d1,user3/user6,3000
d2,user4/user7,4000
d2,user5/user8,5000/8000

执行SQL

select trans_array(1, "/", dept_id, user_id, sal) as (dept_id, user_id, sal) from salary; 

返回结果如下:

d1,user1,1000
d1,user4,6000
d1,user2,2000
d1,user5,7000
d1,user3,3000
d1,user6,NULL
d2,user4,4000
d2,user7,NULL
d2,user5,5000
d2,user8,8000
support.huaweicloud.com/sqlref-spark-dli/dli_spark_trans_array.html