我正在尝试执行此查询:
add FILE /home/user1/test/test_udf.py;
SELECT a.hash_code, col2
FROM (SELECT transform (col2, col3) using 'python test_udf.py' as hash_code, col2
FROM sample_table) a ;
我能够使用 udf 成功生成 hash_code,但另一列 (col2) 被填充为 NULL
。
示例输出:
sjhfshhalksjlkfj128798172jasjhas NULL
ajsdlkja982988290819189089089889 NULL
jhsad817982mnsandkjsahj982398290 NULL
最佳答案
我知道你的 HiveSql 有什么问题。
在 transform (col2, col3) using 'python test_udf.py' as hash_code, col2 FROM sample_table
中,hash_code, col2
的值是从 transform (col2, col3)
的返回值。
clo2
是从transform(col2, col3)
解析出来的,为NULL
。
我读了Transform doc , 提取相关信息如下。
转换/Map-Reduce 语法
SELECT TRANSFORM '(' expression (',' expression)* ')'
(inRowFormat)?
USING 'my_reduce_script'
( AS colName (',' colName)* )?
(outRowFormat)? (outRecordReader)?
您最好不要将 transform
与其他 select
混合使用,因为语法不支持。
更新:
有一个 hack 可以做你想做的事:让 test_udf.py
返回 hash_code\t col2
。
所以你可以从中解析hash_code, col2
。这将解决您的问题。
关于python - 在配置单元中使用 python udf 时如何查询多列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31960262/