hive中建表語句

2021-09-01 20:30:12 字數 2072 閱讀 5554

hive中一共有以下幾種建表方式:

create table person

(id int,

name string,

hobbies array,

address map)

row format delimited

fields terminated by ',';

collection items terminated by '-';

map keys terminated by ':';

建立外部表:

create external table person

(id int,

name string,

hobbies array,

address map)

row format delimited

fields terminated by ',';

collection items terminated by '-';

map keys terminated by ':';

location '/root/date/person'

根據已有的表建立表:

create table person1 as select id, name, hobbies, address from person0
like建立表:

create table person1 like person0
載入資料:

load data local inpath '/tmp/data/person0_data' into table person

load data local inpath'/tmp/date/person0' into table person

建立分割槽表:

create table person1

(id int,

name string,

hobbies array,

address map)

partition by (age int)/(*** string)

row format delimited

fields terminated by ',';

collection items terminated by '-';

map keys terminated by ':';

給分割槽表載入資料:

load data local iinpath '/root/data/person' into table person1 partition (age=1)
新增、刪除分割槽:

alter table person4 add partition(*** = '3',age = '1')

alter table person1 add partition(*** = '1')

alter table person2 drop partition(*** = '2')

alter table person3 drop partition(*** = '3')

dml:data manipulation language

在hive中多次load相同的檔案,資料會被追加,而不是覆蓋。

使用beeline的連線方式:

beeline -u jdbc:hive2//node04:10000 -n root
beeline
型別轉換函式:

內建聚合函式:

hive建表語句

1 只保留表的結構 create table table1 as select from table2 where 2 3 2 保留結構與資料 create table table1 as select from table 2 3 重新命名 create table table1 column1 ...

Hive建表語句解釋

drop table if exists tablename create external table tablename id string comment id name string comment 名字 price double comment comment 表名 partitioned...

批量生成hive建表語句

這裡以shell為例 bin bash db dim echo 匯出資料庫所有的表結構 hive e use db show tables root migration db tables.txt echo 迴圈遍歷表名 cat root migration db tables.txt while ...