create database review01; use review01; -- 1. Operation of internal and external tables --1. Internal table operations --Three ways to create: create table stu(id int,name string); insert into stu values (1,'Zhang San'); create table stu1 like stu; create table stu2 as select * from stu; --Delete internal tables drop table stu2; --View internal table structure desc formatted stu; --Clear table data truncate table stu1; --2. Operation of external tables, note: external tables cannot be created and deleted using as, because there is no absolute control over the data. --Two ways to create create EXTERNAL table pp(id int,name string); create EXTERNAL table pp1 like pp; --Delete external table drop table pp1; --View external table structure desc formatted pp; --2. View table and modify table --1.View table show databases;--View all tables show create table pp;--View table creation statements desc pp;--View table information desc formatted pp;--View table structure --2. Modify the table alter table pp rename to ps;--modify table name alter table ps set location 'storage path in hdfs';--Modify the storage path of the table. If the path does not exist, it will be created when inserting data alter table ps set tblproperties ('c'='v');--Modify table properties alter table ps set tblproperties ('EXTERNAL'='FALSE');--Change external table to internal table alter table stu1 set tblproperties ('EXTERNAL'='TRUE'); --change internal table to external table alter table ps add columns (pid int);--Add fields alter table stu replace columns (id int,name varchar(100));--Replace fields alter table ps change pid product string;--change field name --3. Default delimiter and specified delimiter and quick mapping table --The default delimiter is generally /0001,□,SOH create table tz( dt string,id string,name string,url string ) row format delimited fields terminated by '\t';--specify delimiter load data inpath '/search_log.txt' into table tz;--Quickly load the table, the essence is to move, the original file will disappear select * from tz limit 5;--verification table -- 4. Import and export of Hive data --import/load load data local inpath '/search_log.txt' into table tz1;--Import from linux to hive table, the original file is retained load data inpath '/user/hive/warehouse/review01.db/tz2' overwrite into table tz3;--When importing from one hdfs table to another, the original data will disappear and the data in the new table will be overwritten. insert into table tz select * from tz1;--load data from other tables insert overwrite table tz3 select * from tz1;--overwrite and load data from other tables --export insert overwrite local directory '/home' select * from tz;--Export from hive to linux, default separator, ensure the directory is empty insert overwrite local directory '/home' row format delimited fields terminated by '-' select * from tz;--Specify delimiter insert overwrite directory '/output' row format delimited fields terminated by '/' select * from tz;--Export from hive to hdfs --bin/hive -e "select * from myhive.test_load;" > /home/hadoop/export3/export4.txt--Input and export hive data in linux --bin/hive -f export.sql > /home/hadoop/export4/export4.txt --script output
Internal and external table operations, hive data export and import operations
Guess you like
Origin blog.csdn.net/MSJ3917/article/details/134353493
Ranking