hive复杂类型字段使用

1.带Array字段的hive表结构,并导入数据
1.1创建表结构
CREATE TABLE stu (
    id INT COMMENT 'stdno',
    NAME VARCHAR (32) COMMENT 'stdname',
    scores Array < INT > COMMENT 'std all scores'
) COMMENT 'student info' 
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' 
COLLECTION ITEMS TERMINATED BY ':' 
LINES TERMINATED BY '\n' 
STORED AS textfile;
1.2导入数据
1.2.1根据表结构,构造数据
linux上家目录中student.txt文件内容:
001    张一    80:82:88
002    张二    78:80:90
003    张三    81:74:92
004    张四    85:80:83
1.2.2导入数据
load data local inpath './student.txt' overwrite into table stu;




2.带Struct字段的hive表结构,并导入数据


2.1创建表结构
CREATE TABLE STU01 (
    ID INT,
    INFO STRUCT < NAME : STRING,AGE : INT >
) ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '\t' 
COLLECTION ITEMS TERMINATED BY ':' 
LINES TERMINATED BY '\n' STORED AS textfile;
2.2导入数据
2.2.1根据表结构,构造数据
linux上家目录中stu01.txt文件内容:
001    张一:28
002    张二:29
003    张三:32
004    张四:19
2.2.2导入数据
load data local inpath './stu01.txt' overwrite into table stu01;




3.带Struct字段的hive表结构,并导入数据


3.1创建表结构
CREATE TABLE STU02(
    ID INT,
    INFO MAP
) ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '\t' 
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':'
LINES TERMINATED BY '\n' STORED AS textfile;
3.2导入数据
3.2.1根据表结构,构造数据
linux上家目录中stu02.txt文件内容:
001    张一:28,张二:29,张三:26
002    李一:29,李二:32,李三:30
003    王一:30,王二:31,王三:32
004    赵一:28,赵二:33,赵三:34
3.2.2导入数据
load data local inpath './stu02.txt' overwrite into table stu02;

你可能感兴趣的:(hive复杂类型字段使用)