I am using hive 1.1
hive> select country from releases limit 1;
OK
["us","ca","fr"]
For now country is of type string in hive . How do I convert that into Array[String]?
I tried the below, but it is throwing error
hive> select country, cast(country as Array[String]) from releases limit 1;
FAILED: ParseException line 1:48 cannot recognize input near 'Array' '[' 'String' in primitive type specification
Can someone help me to do the typecasting?
Converting a String column to an Integer column or converting a column from one type to another is quite simple in Hive. Simply use the cast function to cast the type from one to another.
Hive Array Function This function is used to create array out of integer or string values. Following is the syntax of array function. where, value is of type string or integer. For example, consider following example to create array out of integer values.
So how to convert String array to String in java. We can use Arrays. toString method that invoke the toString() method on individual elements and use StringBuilder to create String. We can also create our own method to convert String array to String if we have some specific format requirements.
hive> with releases as (select '["us","ca","fr"]' as country)
> select split(regexp_extract(country,'^\\["(.*)\\"]$',1),'","')
> from releases
> ;
OK
_c0
["us","ca","fr"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With