HIve note 5

Data manipulation DML

5.1 Data Import

5.1.1 loading data into the table (the Load)
1. Syntax
Hive> Load Data [local] the inpath '/opt/module/datas/studnets.txt' Overwrite | INTO Table Student
[Partition (partcol1 = val1 is ...)] ;
(. 1) load data: indicates loading data
(2) local: indicates that the local loading data from the hive table; otherwise loaded from HDFS data into the hive table
(3) inpath: indicates the path load data
(4) overwrite: denotes a cover sheet in existing data, or that additional
(5) into table: where represents the loading tables
(6) student: shows a specific table
(7) partition: indicates the specified partition upload

2. The practical operation case

Insert data into a table by the query

1,创建一张分区表
create table student (id int, name string ) partitioned by (month string)
row format delimited fileds terminated by '\t';

2. insert data
insert into table student partition (month = '201709') values (1, 'xxx')

3. Insert the fundamental mode (single table according to the query result)
INSERT Overwrite Student Partition Table (= month The '201708')
SELECT ID, name from WHERE month The Student = '201709';

4. Multi-insert mode (multiple tables according to the query result)
from Student
INSERT Overwrite Student Partition Table (= month The '201707')
SELECT ID, month The WHERE name = '201706'
INSERT Overwrite Student Partition Table (= month The '201706')
SELECT id, name where month = '201709 ';

5.2 Data Export

5.2.1 insert derived
1. The results of the query to a local export
INSERT Overwrite local Directory '/ opt / Module1 / DATAS / Export / Student'
SELECT * from Student;

2. The results of the query format for export to local
INSERT Overwrite local Directory '/ opt / Module1 / DATAS / Export / studnet1'
the ROW the FORMAT the DELIMITED the FIELDS TERMINATED BY '\ T' SELECT * from Student;

  1. 将查询的结果导出到HDFS上(没有local)
    insert overwrite directory '/user/atguigu/student2'
    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
    select * from student;

Guess you like

Origin www.cnblogs.com/fanx-1995/p/11334993.html