複雜型別

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;