Hive(四)——Hive框架基礎(二)
阿新 • • 發佈:2019-08-26
一、Hive建立表的方式
- 使用create命令建立一個新表
例如:create table if not exists dbname.tbname(欄位)
partitioned by (date string,hour string) ## 分割槽
row format delimited fields terminated by '\t';
- 把一張表的某些欄位抽取出來,建立成一張新表
create table backup_tbname as select * from dbname.tbname; ## 會複製屬性以及屬性值到新的表中
- 複製表結構
create table like_tbname like db_web_data.track_log ## 不會複製屬性值,只會複製表結構。
二、Hive表匯入資料方式
- 本地匯入
load data local inpath 'local_path/file' into table 表名稱 ;
- HDFS匯入
load data inpath 'hdfs_path/file' into table 表名稱 ;
- 覆蓋匯入
load data local inpath 'path/file' overwrite into table 表名稱 ;
load data inpath 'path/file' overwrite into table 表名稱 ;
- 查詢匯入
create table tbname_temp as select * from dbname.tbname;
- insert匯入
** 追加-append-預設方式
insert into table 表名 select * from tbname;
** 覆蓋-overwrite-顯示指定-使用頻率高
insert overwrite table 表名 select * from tbname;
三、Hive表匯出資料方式
- 本地匯出
例如:insert overwrite local directory "/home/hadoop/doc/1/2" row format delimited fields terminated by '\t' select * from db_hive_demo.emp ;## 會遞迴建立目錄
- HDFS匯出
例如:insert overwrite diretory "path/" select * from staff;
- Bash shell覆蓋追加匯出
例如:$ bin/hive -e "select * from staff;" > /home/hadoop