How do I write out an array literal in Hive?
SELECT PERCENTILE(my_column, [0.5, 0.25, 0.50, 0.75, 0.95]) AS quantiles
FROM my_table
Returns the error
FAILED: ParseException line xx:xx cannot recognize input near '[' '0.5' ',' in select expression
arrays: It is an ordered collection of elements. The elements in the array must be of the same type. map: It is an unordered collection of key-value pairs. Keys must be of primitive types. Values can be of any type.
arrays. Array in Hive is an ordered sequence of similar type elements that are indexable using the zero-based integers. Arrays in Hive are similar to the arrays in JAVA.
In Hive, you can use a function named_struct in order to create a list of key value pairs; the keys are usually the column names and the values are the values in the corresponding column.
Similar to Spark, Hive also support complex data types which includes Array, Map, Struct and union. Array is used to store the list of elements. Map is used to store key/value pair. Struct is for parent and child assosiations.
Try using array
instead of []
SELECT PERCENTILE(my_column, array(0.5, 0.25, 0.50, 0.75, 0.95)) AS quantiles
FROM my_table
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