Hive表型別及其操作

2021-09-24 15:15:07 字數 2460 閱讀 5689

create database demo;    use demo;
create table table_1(

id int,

name varchar(8)

);

create external table table_2(

id int,

name varchar(8)

);

row format delimited 

fields terminated by 』,』

collection items terminated by 『-』 

map keys terminated by 『:』 :

lines terminated by 『\n』

1、load data local inpath '/root/test.txt' into table demo.table_1;

將本地的資料匯入到hive中

2、load data  inpath 'hdfs://node01:9000/user/tes.txt' into table demo.table_1;

從hdfs集群匯入資料(首先上傳test.txt到hdfs中)

3、insert into---內外部表,不適應於分割槽

4、from table1

insert into(overwrite) tables2

select id ,name

單分割槽

create table table_3 (id int, name varchar(8)) partitioned by (day int);

上傳資料:

load data local inpath '/root/tes.txt' into table demo.table_3 partition (day=10);

雙分割槽建表語句:

create table table_4(id int, name varchar(8)) partitioned by (day int, hour int);

上傳資料:

load data local inpath '/root/tes.txt' into table demo.table_4 partition (day=10,hour=20);

增加分割槽

alter table table_3 add partition(day=10,hour=40);

刪除分割槽

alert table table_4 drop partiton(day=10,hour=20)

修改許可權的方式:

1、conf/hive-site.xml

2、在hive內部使用set進行相應的設定

3、hive啟動的時候設定 hive --hiveconf hive.exec.dynamic.partiton=true

1、修改許可權

set hive.exec.dynamic.partiton=true //開啟動態分割槽

2、修改預設狀態

set hive.exec.dynamic.partiton.mode=nostrict //預設strict。至少有乙個靜態分割槽

建立分割槽:

create table table_11(

id int,

name varchar(8),

) partitioned by (day int ,hour int)

row format delimited

fields terminated by ' '

lines terminated by '\n'

;寫入資料:

insert into table table_11 partiton (day,hour)

select * table_3;

開啟分桶

set hive.enforce.bucketing=true

建立桶 create table table_111 (

id int,

name varchar(8),

) clustered by (id) into 4 buckets

row format delimited

fields terminated by ' '

載入資料

insert into table table_111 select id,name from table_2;

抽樣 select * from table_111 tablesample(bucket 1 out of 4 on id);

Hive中的map型別及其操作

建立表,並定義map型別 create table employee id string,perf map row format delimited fields terminated by t collection items terminated by map形式key value,key va...

hive,操作庫 不同型別的表

hive中有乙個預設的庫 庫名 default 庫目錄 hdfs hdp20 01 9000 user hive warehouse create database db order 庫建好後,在hdfs中會生成乙個庫目錄 hdfs hdp20 01 9000 user hive warehouse...

Hive中的表及其建立

內部表也稱之為managed table 預設儲存在 user hive warehouse下,也可以通過location指定 刪除表時,會刪除表資料以及元資料 create table if not exists t user id int,name string,boolean,age int,...