在带有分隔符的数据上配置 UDF
hive UDF on data with delimiters
我正在使用 python & hive UDF 来逆透视数据。 'python.py' 反透视数据,但我想 运行 在 Hive 上这样做。我无法处理包含 space 和句点的项目。
有什么好办法绕过它吗?
我的起始 table 看起来像:
store item flavor
------- ----------------- ------------
1 cupcake chocolate
1 cake pops red velvet
1 ice cream vanilla
1 cookies/candies lemon
2 cupcake red velvet
2 cake pops vanilla
2 ice cream chocolate
2 cookies/candies chocolate
我正在使用内码获取:
store cupcake cake pops ice cream cookies/candies
------- ------------ ------------ ----------- -----------------
1 chocolate red velvet vanilla lemon
2 red velvet vanilla chocolate chocolate
使用:
SELECT TRANSFORM(store, item, flavor) USING ‘python.py’
AS (store, cupcake, cake pops, ice cream, cookies/candies) FROM mytable;
报错:"Error while compiling statement: FAILED: ParseException line 3:25 mismatched input 'pops' expecting ) near 'cake' in transform clause"
尽量使用反引号或单引号。
如果你的udf用space定义了列名,我更喜欢反引号。但是,在这种情况下,我猜你需要使用单引号。
SELECT TRANSFORM(store, item, flavor) USING ‘python.py’ AS (store, cupcake, 'cake pops', ice cream, cookies/candies) FROM mytable;
我正在使用 python & hive UDF 来逆透视数据。 'python.py' 反透视数据,但我想 运行 在 Hive 上这样做。我无法处理包含 space 和句点的项目。
有什么好办法绕过它吗?
我的起始 table 看起来像:
store item flavor ------- ----------------- ------------ 1 cupcake chocolate 1 cake pops red velvet 1 ice cream vanilla 1 cookies/candies lemon 2 cupcake red velvet 2 cake pops vanilla 2 ice cream chocolate 2 cookies/candies chocolate
我正在使用内码获取:
store cupcake cake pops ice cream cookies/candies ------- ------------ ------------ ----------- ----------------- 1 chocolate red velvet vanilla lemon 2 red velvet vanilla chocolate chocolate
使用:
SELECT TRANSFORM(store, item, flavor) USING ‘python.py’
AS (store, cupcake, cake pops, ice cream, cookies/candies) FROM mytable;
报错:"Error while compiling statement: FAILED: ParseException line 3:25 mismatched input 'pops' expecting ) near 'cake' in transform clause"
尽量使用反引号或单引号。
如果你的udf用space定义了列名,我更喜欢反引号。但是,在这种情况下,我猜你需要使用单引号。
SELECT TRANSFORM(store, item, flavor) USING ‘python.py’ AS (store, cupcake, 'cake pops', ice cream, cookies/candies) FROM mytable;