Thursday, July 16, 2015

Hive Convert Array to String

It is simple if it is an array, there is an UDF called concat_ws(SEP, array). But concat_ws can only handle array, not for array, array. Hive doesn't support cast array to array or string. You cannot insert into a table with a string column for the array.

Run out of options? You can actually use TRANSFORM and /bin/cat to convert to string like this: when the column is passed to the script, it convert into a string same as when you run "select * from table".

create table regions(
  ...
  coordinates array<array<double>>,
  ...
)

from regions select transform(coordinates) using '/bin/cat' as (coordinates);