Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array literal in Hive

Tags:

hive

hiveql

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
like image 998
John McDonnell Avatar asked Sep 15 '14 04:09

John McDonnell


People also ask

What is array in Hive?

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.

Does Hive support array?

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.

What is Named_struct in Hive?

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.

What are complex data types in Hive?

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.


1 Answers

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
like image 150
FuzzyTree Avatar answered Sep 30 '22 05:09

FuzzyTree