复杂类型
ARRAY
CREATE TABLE array_data_type(
c_array array<string>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
COLLECTION ITEMS TERMINATED BY '&';
用数据创建 data.csv
:
arr1&arr2
arr2&arr4
将 data.csv
放入/tmp
folde 并在 Hive 中加载此数据
LOAD DATA LOCAL INPATH '/tmp/data.csv' INTO TABLE array_data_type;
或者你可以把这个 CSV 放在 HDFS 中,在/tmp
说。使用 HDFS 从 CSV 加载数据
LOAD DATA INPATH '/tmp/data.csv' INTO TABLE array_data_type;
地图
CREATE TABLE map_data_type(
c_map map<int,string>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
COLLECTION ITEMS TERMINATED BY '&'
MAP KEYS TERMINATED BY '#';
data.csv
文件:
101#map1&102#map2
103#map3&104#map4
将数据加载到配置单元:
LOAD DATA LOCAL INPATH '/tmp/data.csv' INTO TABLE map_data_type;
STRUCT
CREATE TABLE struct_data_type(
c_struct struct<c1:smallint,c2:varchar(30)>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
COLLECTION ITEMS TERMINATED BY '&';
data.csv
文件:
101&struct1
102&struct2
将数据加载到配置单元:
LOAD DATA LOCAL INPATH '/tmp/data.csv' INTO TABLE struct_data_type;
UNIONTYPE
CREATE TABLE uniontype_data_type(
c_uniontype uniontype<int, double, array<string>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
COLLECTION ITEMS TERMINATED BY '&';
data.csv
文件:
0&10
1&10.23
2&arr1&arr2
将数据加载到配置单元:
LOAD DATA LOCAL INPATH '/tmp/data.csv' INTO TABLE uniontype_data_type;