hive基本操作指令

2021-08-31 21:35:38 字數 2249 閱讀 4848

create table mytable(

id int,

name string)

row format delimited fields terminated by '\t' stored as textfile;

附:

mytable是表名

id int是引數名字和引數型別

as textfile是代**式,可以省略,預設都是text格式

create external table mytable2(

id int,

name string)

row format delimited fields terminated by '\t' location '/user/hive/warehouse/mytable2';

create table mytable3(

id int,

name string)

partitioned by(gender string) row format delimited fields terminated by '\t'stored as textfile;

load data local inpath '/root/hivedata/girl.txt' overwrite into table mytable3 partition(gender='girl');
show partitions mytable3;
select * from mytable3;
alter table student rename to student_mdf
alter table student_mdf add columns (gender string);
alter table student_mdf change *** gender string;
alter table student_mdf replace columns (id string, name string);
drop table if exists mytable;
alter table mytable3 add partition(***='unknown') localtion /user/hive/warehouse/mydb.db/mytable3/***=unknown;
alter table mytable3 drop if exists partition(***='unknown');
load data [local] inpath 'filepath' [overwrite] into table tablename [partition (partcol1=val1, partcol2=val2 ...)]
附:

load:操作只是單純的複製/移動操作,將資料檔案移動到 hive 表對應的位置

filepath:包括相對路徑、絕對路徑和包含模式的完整uri

local:如果指定了local,load命令會去查詢本地檔案系統中的 filepath。如果沒有指定local關鍵字,則根據inpath中的uri查詢檔案

如果使用了overwrite關鍵字,則目標表(或者分割槽)中的內容會被覆蓋

insert into table student_mdf values('1','zhangsan');
set hive.exec.dynamic.partition.mode=nonstrict
create table mytable5 as select id, name from mytable3;
insert into birthdays partition(month) select id,name,month from persons;
附:

預設使用的是嚴格模式,是不允許動態分割槽的,我們需要在命令列執行set hive.exec.dynamic.partition.mode=nonstrict

使用動態分割槽會將查詢結果集的最後乙個作為分割槽條件,所以select查詢要注意.

hive基本操作

1.顯示所有資料庫 show databases 2.使用某個資料庫 use xx xx表示某個資料庫名 3.顯示某資料庫下的所有表 show tables 4.檢視表結構 顯示各欄位 desc 表名 5.資料匯出到本地 在hive中操作 insert overwrite local directo...

hive 基本操作

檢視表的詳細資訊 desc 表名 desc formatted 表名 建立外部表 create external table emp ext empno int,ename string,job string,mgr int,hiredate string,sal double,comm doubl...

HIVE基本操作

hive操作 一 建立分割槽 乙個表可以有多個分割槽,為避免過多的小檔案,建議只能對離散字段進行分割槽 create table if not exists stocks ymd date,price open float,price high float,price low float,price...