HIVE動態分割槽

2021-09-25 10:52:24 字數 1313 閱讀 6969

set hive.exec.dynamic.partition=true;  -- 開啟動態分割槽,預設是false

set hive.exec.dynamic.partition.mode=nonstrict; -- 開啟允許所有分割槽都是動態的,否則必須要有乙個靜態分割槽才能使用

-- 建立分割槽表

create table test(id int ,name string )

partitioned by(ct string); -- 分割槽欄位為ct

-- 向分割槽表中插入資料(動態分割槽的方式)

insert overwrite table test

partition(ct)

select id ,name,city from test_partiton;

說明:select了兩個字段,前兩個欄位為表結構,最後乙個預設為分割槽字段,注意select的順序,分割槽字段應該在後面

insert...select 往表中匯入資料時,select的字段個數必須和目標的字段個數相同,不能多,也不能少,否則會報錯。如果欄位的型別不一致的話,則會使用null值填充,不會報錯。而使用load data形式往hive表中裝載資料時,則不會檢查。如果欄位多了則會丟棄,少了則會null值填充。同樣如果字段型別不一致,也是使用null值填充。

create table test_table as select * from table_one

注意ctas建立表不能複製源表的預設值(主鍵、分割槽等),只是複製了欄位名,型別和資料

create like 可以複製表結構和預設值,但是不會有源資料

hive建表

create table if not exists employee(

eid int comment "主鍵",

name string,

salary string,

destination string

hobby arrayadd map)

comment 『employee 表』

partitioned by (『dt』 string comment '時間做分割槽') -- 分割槽字段

row format delimipted

fields terminated by 『,』 -- 列分隔符 ,

lines terminated by 『\n』 -- 行分隔符 回車

map keys terminated by ':' -- map

stored as textfile; -- 預設儲存為文字格式

HIVE動態分割槽

一 前段時間因為導表需求 從一張表中查詢出資料,按日期分割槽overwrite 到指定分割槽表中 在hive裡面研究了一下自動分割槽。步驟 1 建好所需分割槽表 2 設定分割槽引數?1 2 3 4 sethive.exec.dynamic.partition true 可通過這個語句檢視 sethi...

Hive動態分割槽

動態分割槽指不需要為不同的分割槽新增不同的插入語句,分割槽不確定,需要從資料中獲取。相關引數設定 set hive.exec dynamic partition true 使用動態分割槽 可通過這個語句檢視 set hive.exec dynamic partition set hive.exec ...

hive動態分割槽

不需要為不同的分割槽新增不同的插入語句 分割槽不確定,需要從資料中獲取 幾個引數 set hive.exec dynamic partition true 使用動態分割槽 set hive.exec dynamic partition mode nonstrick 無限制模式,如果模式是strict...