如題
目錄
1、簡單描述
2、測試
arrays: <code>ARRAY<data_type></code>
maps: <code>MAP<primitive_type, data_type></code>
structs: <code>STRUCT<col_name : data_type [COMMENT col_comment], ...></code>
union: <code>UNIONTYPE<data_type, data_type, ...></code>
Hive 中對該類型的完全支援仍然不完整。如果 JOIN、WHERE 和 GROUP BY 子句中引用的 UNIONTYPE 字段的查詢将會失敗,Hive 沒有定義文法來提取 UNIONTYPE 的 tag 或 value 字段。
複雜資料類型的構造函數:
構造函數
操作數
描述
map
(key1, value1, key2, value2, ...)
Creates a map with the given key/value pairs.
struct
(val1, val2, val3, ...)
Creates a struct with the given field values. Struct field names will be col1, col2, ....
named_struct
(name1, val1, name2, val2, ...)
Creates a struct with the given field names and values. (As of Hive 0.8.0.)
array
(val1, val2, ...)
Creates an array with the given elements.
create_union
(tag, val1, val2, ...)
Creates a union type with the value that is being pointed to by the tag parameter.
注:create_union 中的 tag 讓我們知道 union 的哪一部分正在被使用。
複雜資料類型通路元素:
A[n]
A is an Array and n is an int
Returns the nth element in the array A. The first element has index 0. For example, if A is an array comprising of ['foo', 'bar'] then A[0] returns 'foo' and A[1] returns 'bar'.
M[key]
M is a Map<K, V> and key has type K
Returns the value corresponding to the key in the map. For example, if M is a map comprising of {'f' -> 'foo', 'b' -> 'bar', 'all' -> 'foobar'} then M['all'] returns 'foobar'.
S.x
S is a struct
Returns the x field of S. For example for the struct foobar {int foo, int bar}, foobar.foo returns the integer stored in the foo field of the struct.
參考:http://querydb.blogspot.com/2015/11/hive-complex-data-types.html