当前位置:网站首页>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.
边栏推荐
- 【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
- Leetcode(547)——省份数量
- Three sentences to briefly introduce subnet mask
- Explain in detail the implementation of call, apply and bind in JS (source code implementation)
- Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
- 工程师如何对待开源 --- 一个老工程师的肺腑之言
- 2022/2/11 summary
- Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers
- X.509 certificate based on go language
- dynamic programming
猜你喜欢
沉浸式投影在线下展示中的三大应用特点
学习光线跟踪一样的自3D表征Ego3RT
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
智能运维应用之道,告别企业数字化转型危机
工程师如何对待开源 --- 一个老工程师的肺腑之言
The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation
Article management system based on SSM framework
Uniapp uploads and displays avatars locally, and converts avatars into Base64 format and stores them in MySQL database
stm32F407-------DAC数模转换
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
随机推荐
学习光线跟踪一样的自3D表征Ego3RT
509 certificat basé sur Go
Distributed cache
Operation test of function test basis
Web project com mysql. cj. jdbc. Driver and com mysql. jdbc. Driver differences
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
.class文件的字节码结构
Hero League | King | cross the line of fire BGM AI score competition sharing
37页数字乡村振兴智慧农业整体规划建设方案
File and image comparison tool kaleidoscope latest download
Mujoco finite state machine and trajectory tracking
Linear algebra of deep learning
Five different code similarity detection and the development trend of code similarity detection
Model-Free Prediction
37 page overall planning and construction plan for digital Village revitalization of smart agriculture
【软件逆向-自动化】逆向工具大全
Learn to use code to generate beautiful interface documents!!!
【vulnhub】presidential1
fastDFS数据迁移操作记录
Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions