当前位置:网站首页>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.
边栏推荐
- Sword finger offer 26 Substructure of tree
- 【软件逆向-自动化】逆向工具大全
- Geo data mining (III) enrichment analysis of go and KEGG using David database
- Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
- 英雄联盟|王者|穿越火线 bgm AI配乐大赛分享
- Leecode brush question record sword finger offer 56 - ii Number of occurrences of numbers in the array II
- 【vulnhub】presidential1
- Uniapp uploads and displays avatars locally, and converts avatars into Base64 format and stores them in MySQL database
- File and image comparison tool kaleidoscope latest download
- Value Function Approximation
猜你喜欢
工程师如何对待开源 --- 一个老工程师的肺腑之言
AI super clear repair resurfaces the light in Huang Jiaju's eyes, Lecun boss's "deep learning" course survival report, beautiful paintings only need one line of code, AI's latest paper | showmeai info
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
建立自己的网站(17)
Idea automatically imports and deletes package settings
If the college entrance examination goes well, I'm already graying out at the construction site at the moment
.class文件的字节码结构
【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)
48页数字政府智慧政务一网通办解决方案
Linear algebra of deep learning
随机推荐
基於GO語言實現的X.509證書
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
以机房B级建设标准满足等保2.0三级要求 | 混合云基础设施
Stm32f407 ------- DAC digital to analog conversion
Service asynchronous communication
QT tutorial: creating the first QT program
Article management system based on SSM framework
Meet the level 3 requirements of ISO 2.0 with the level B construction standard of computer room | hybrid cloud infrastructure
深度学习之环境配置 jupyter notebook
Leecode brushes questions and records interview questions 01.02 Determine whether it is character rearrangement for each other
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
Advanced learning of MySQL -- basics -- multi table query -- self join
Sword finger offer 26 Substructure of tree
Uniapp uploads and displays avatars locally, and converts avatars into Base64 format and stores them in MySQL database
Core knowledge of distributed cache
Five different code similarity detection and the development trend of code similarity detection
【vulnhub】presidential1
Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
MySQL learning notes (mind map)
Idea automatically imports and deletes package settings