I have a integer array represented with String. For example, "[1,2,2,3]"
And the field type in Hive table is the array integer, I was wondering if there is any Hive build-in UDF that can cast the above string into the array integer.
Thanks
I have a integer array represented with String. For example, "[1,2,2,3]"
And the field type in Hive table is the array integer, I was wondering if there is any Hive build-in UDF that can cast the above string into the array integer.
Thanks
tl;dr I do not know of a Hive UDF that will do this for you, and casting on your own can be gross.
No, there isn't a UDF. As for building your own solution:
Casting to array[string] would be easy enough - just drop the square brackets using
regexp_replace
and split the resulting string on,
.The problem is converting an array[string] to array[int] for arrays of arbitrary size. You can individually cast the array elements one by one:
but this approach only works because I know I have arrays of length 3.