数据:
1,100|3,20|2,70|5,100
建表:
CREATE TABLE complex (
col1 MAP<INT, INT>
)
ROW FORMAT DELIMITED
COLLECTION ITEMS TERMINATED BY '|'
MAP KEYS TERMINATED BY ','
STORED AS TEXTFILE;
;
LOAD DATA LOCAL INPATH '/home/tianzhao/book/complex.txt'
OVERWRITE INTO TABLE complex;
SELECT col1[1] FROM complex; 是 100
SELECT col1[3] FROM complex; 是20
SELECT col1[2] FROM complex; 是70
SELECT col1[5] FROM complex; 是100
SELECT col1 FROM complex; 出来的是
{1:100,3:20,2:70,5:100}
Hive自带的示例是:
ql/src/test/queries/clientpositive$ cat create_nested_type.q
DROP TABLE table1;
CREATE TABLE table1 (
a STRING,
b ARRAY<STRING>,
c ARRAY<MAP<STRING,STRING>>,
d MAP<STRING,ARRAY<STRING>>
) STORED AS TEXTFILE;
DESCRIBE table1;
DESCRIBE EXTENDED table1;
LOAD DATA LOCAL INPATH '../data/files/create_nested_type.txt' OVERWRITE INTO TABLE table1;
SELECT * from table1;
DROP TABLE table1;
分享到:
相关推荐
其次,Hive 支持的数据类型包括 Primitive Type 和 Complex Type。Primitive Type 包括 Tiny int、Small int、Int、Big int、Boolean、Float、Double、String 和 Binary 等,Complex Type 包括 Struct、Map 和 Array...
CREATE TABLE complex ( col1 ARRAY, col2 MAP, INT>, col3 STRUCT, b: INT, c: DOUBLE> ); ``` ##### 2.3 类型转换 Hive 支持在一定范围内的隐式类型转换,例如,任何整数类型都可以隐式转换为更宽泛的类型,...
CREATE TABLE complex_example ( array_col ARRAY, map_col MAP, INT>, struct_col STRUCT, name: STRING>, union_col UNIONTYPE, INT> ); ``` - **其他类型** - `BOOLEAN`: 存储布尔值 - `BINARY`: 存储二...
Build functional, type-safe routines to interact with relational and NoSQL databases with the help of the tutorials and examples provided Leverage your expertise in Scala programming to create and ...
目录 第一部分 Spark学习 ....................................................................................................................... 6 第1章 Spark介绍 .........................................