创建表:
from person0 p
insert overwrite table psn4
select p.id, p.name
insert overwrite table psn5
select p.likes
先创建表,然后再插入数据
Hive 建表
CREATE TABLE person5
(
id INT,
name STRING,
age INT,
sex STRING,
likes ARRAY<STRING>,
address MAP<STRING,STRING>
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
COLLECTION ITEMS TERMINATED BY '-'
MAP KEYS TERMINATED BY ':'
LINES TERMINATED BY '\n';
Hive字段的默认值
from person0 p
insert overwrite table psn4
select p.id, p.name
insert overwrite table psn5
select p.likes
查询插入数据:
hive> insert overwrite local directory '/user/hive/warehouse/person2' select * from person0;
Query ID = root_20181227194555_f1c54fdf-2b36-4cd1-960a-64f26d19fb34
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator