Hive3 detailed tutorial (V) internal tables, external tables and imported data

Miss Zhu 2022-02-13 08:38:49 阅读数:204

hive3 hive detailed tutorial internal

Prepare one first stus.txt data :

Tom,male,20
Jim,male,21
jone,female,20

Internal table

Internal table is also called management table

1. stay hive Create a new internal table :

create table stu_m(
name string,
gender string,
age int
)
row format delimited
fields terminated by ','
;

Because in beeline Write... On the command line of sql, Unfriendly , Can be create Write the sentence to a stu_m.sql In the file of , Upload to linux The virtual machine /apps Under the table of contents ,
And then use source Command execution sql Statement implementation table creation :

source /apps/stu_m.sql;

As shown in the figure :
 Insert picture description here

Can pass desc formatted Command to view the table structure details and stored data hdfs File location information .

desc formatted stu_m;

2. Upload data

load data local inpath '/apps/stus.txt' overwrite into table stu_m;

3. verification :

select * from stu_m;

 Insert picture description here

Hdfs Upper position :
 Insert picture description here

External table :

When creating an external table, it has an advantage over an internal table external keyword , And you should specify that it is stored in hdfs The location of , The rest load、select Consistent with the internal standard .
1. Create an external table

create external table stu_e(
name string,
gender string,
age int
)
row format delimited
fields terminated by ','
location '/my_hive/stu_e'
;

among location '/my_hive/stu_e’ The designated one is hdfs The path of .
2.load Data on
Hdfs Upper position :
 Insert picture description here

Use drop Delete internal and external tables , You will find that after the internal table is deleted , The corresponding hdfs The data also disappeared , After the external table is deleted , Just deleted the metadata ,hdfs The data did not disappear .

copyright:author[Miss Zhu],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130838468400.html