我正在尝试将一个大整数数组转换为hive SQL中的字符串数组
我试过用
concat_ws但这给了我一个错误
Argument 2 of function CONCAT_WS must be "string or array<string>", but "array<bigint>" was found.我试着用
transform(mycolumn) using '/bin/cat' as mycolumn_as_string它给出的错误是
cannot recognize input near 'transform' '(' 'mycolumn' in selection target如何将此bigint数组转换为数组字符串?
发布于 2018-02-27 01:09:48
假设您的表如下所示:
tb_name mycolumn
------- --------
tblname [111,222,333]
tblname [1234,123456,3423]则以下查询将不起作用,因为concat_ws只接受字符串或字符串数组:
select tb_name, concat_ws('-', mycolumn) from mytable;
FAILED: Argument 2 of function CONCAT_WS must be "string or array<string>", but "array<int>" was found.基于这一点:How to concatenate the elemets of int array to string in Hive
不正确:
select concat_ws('-', transform(mycolumn) using '/bin/cat') as mycolumnstr from mytable;
FAILED: ParseException line 1:22 cannot recognize input near 'transform' '(' 'mycolumn' in select expression正确:
with tbl as (select transform(mycolumn, tb_name) using '/bin/cat' as (mycolumnstr, tb_name) from mytable)
select concat_ws('-', tb_name, mycolumnstr) from tbl;
Result:
tblname-[111,222,333]
tblname-[1234,123456,3423]https://stackoverflow.com/questions/48990589
复制相似问题