当前位置:网站首页>Chapter 5 DML data operation
Chapter 5 DML data operation
2022-07-07 00:46:00 【Sun Zhongming】
The first 5 Chapter DML Data manipulation
5.1 Data import —— important
5.1.1 Loading data into a table (Load)—— The key
1. grammar
hive> load data [local] inpath '/opt/module/datas/student.txt' overwrite | into table student [partition (partcol1=val1,…)]
(1)load data: Represents loading data
(2)local: Load data from local to hive surface ; Otherwise, from HDFS Load data to hive surface
(3)inpath: Indicates the path to load data
(4)overwrite: Represents the data already in the overlay table , Otherwise, it means additional
(5)into table: Indicates which table to load
(6)student: A specific table
(7)partition: It means to upload to the specified partition
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
2. Practical operation cases
-- Create a table
hive (default)> create table student(id string, name string) row format delimited fields terminated by '\t';
-- Load the local file into hive
hive (default)> load data local inpath '/opt/module/datas/student.txt' into table default.student;
-- load HDFS File to hive in
-- Upload files to HDFS
hive (default)> dfs -put /opt/module/datas/student.txt /user/atguigu/hive;
-- load HDFS Data on
hive (default)> load data inpath '/user/atguigu/hive/student.txt' into table default.student;
-- Load data to cover existing data in the table
-- Upload files to HDFS
hive (default)> dfs -put /opt/module/datas/student.txt /user/atguigu/hive;
-- Load data to cover existing data in the table
hive (default)> load data inpath '/user/atguigu/hive/student.txt' overwrite into table default.student;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
5.1.2 Insert data into a table through a query statement (Insert)—— The key
-- Create a partition table
hive (default)> create table student(id int, name string) partitioned by (month string) row format delimited fields terminated by '\t';
-- Basic insert data
hive (default)> insert into table student partition(month='201709') values(1,'wangwu');
-- Basic mode insertion ( According to the single table query results )
hive (default)> insert overwrite table student partition(month='201708') select id, name from student where month='201709';
-- Multiple insertion mode ( Query results based on multiple tables )
hive (default)> from student
insert overwrite table student partition(month='201707')
select id, name where month='201709'
insert overwrite table student partition(month='201706')
select id, name where month='201709';
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
5.1.3 Create table and load data in query statement (As Select)
See 4.5.1 Chapter create table .
Create a table based on the query results ( The results of the query are added to the newly created table )
create table if not exists student3
as select id, name from student;
- 1.
- 2.
- 3.
5.1.4 Passed while creating the table Location Specify the load data path —— The key
-- Create table , And designated at hdfs Position on
hive (default)> create table
if not exists student5(id int, name string)
row format delimited fields terminated by '\t'
location '/user/hive/warehouse/student5';
-- Upload data to hdfs On
hive (default)> dfs -put /opt/module/datas/student.txt
/user/hive/warehouse/student5;
-- Query data
hive (default)> select * from student5;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
5.1.5 Import Data to designated Hive In the table —— Not much
Be careful : First use export After export , Then import the data into .
hive (default)> import table student2 partition(month='201709') from '/user/hive/warehouse/export/student';
- 1.
5.2 Export data
5.2.1 Insert export
-- Export the results of the query to local
hive (default)> insert overwrite local directory '/opt/module/datas/export/student'
select * from student;
-- Format and export the query results to local
hive(default)>insert overwrite local directory '/opt/module/datas/export/student1'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
select * from student;
-- Export the results of the query to HDFS On ( No, local)
hive (default)> insert overwrite directory '/user/root/student2'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
select * from student;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
5.2.2 Hadoop Command export to local
hive (default)> dfs -get /user/hive/warehouse/student/month=201709/000000_0
/opt/module/datas/export/student3.txt;
- 1.
- 2.
5.2.3 Hive Shell Command export
Basic grammar :(hive -f/-e Execute statements or scripts > file)
[[email protected] hive]$ bin/hive -e 'select * from default.student;' > /opt/module/datas/export/student4.txt;
- 1.
边栏推荐
猜你喜欢
2022/2/12 summary
[yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
2022年PMP项目管理考试敏捷知识点(9)
C9高校,博士生一作发Nature!
The programmer resigned and was sentenced to 10 months for deleting the code. Jingdong came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
如何判断一个数组中的元素包含一个对象的所有属性值
The difference between redirectto and navigateto in uniapp
48 page digital government smart government all in one solution
互动滑轨屏演示能为企业展厅带来什么
MySQL learning notes (mind map)
随机推荐
Five different code similarity detection and the development trend of code similarity detection
Stm32f407 ------- DAC digital to analog conversion
String comparison in batch file - string comparison in batch file
2021 SASE integration strategic roadmap (I)
Learn to use code to generate beautiful interface documents!!!
深度学习之数据处理
2022/2/11 summary
Operation test of function test basis
Attention SLAM:一種從人類注意中學習的視覺單目SLAM
接口(接口相关含义,区别抽象类,接口回调)
建立自己的网站(17)
Advanced learning of MySQL -- basics -- multi table query -- external connection
How to set encoding in idea
VTK volume rendering program design of 3D scanned volume data
stm32F407-------SPI通信
Devops can help reduce technology debt in ten ways
Advanced learning of MySQL -- basics -- multi table query -- inner join
37頁數字鄉村振興智慧農業整體規劃建設方案
2022/2/10 summary
Everyone is always talking about EQ, so what is EQ?