hive建表語句(包括txt Orc和分割槽)

2021-08-13 09:58:08 字數 3490 閱讀 1643

txt格式  無分割槽

use an_pafc_safe;

create table an_pafc_safe.sx_ela_bp_info

(id_ela_bp_info   string,

code             string,

agent_no         string,

operation_time   string,

product_no       string,

info_no         string,

created_by       string,

created_date     string,

updated_by       string,

updated_date     string,

openid           string,

page             string

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

----delimited fields terminated by '\t'  通過'\t'分割字段

----lines terminated by '\n'            通過'\n'結束一行字段

orc格式  無分割槽

use an_pafc_safe;

create table an_pafc_safe.dim_olp_bank_table_grade_l

(branch_grade    decimal(38,0),

branch0_code    string,

branch0_name    string,

branch1_code    string,

branch1_name    string,

branch2_code    string,

branch2_name    string,

branch3_code    string,

branch3_name    string,

branch4_code    string,

branch4_name    string,

branch5_code    string,

branch5_name    string,

branch6_code    string,

branch6_name    string       

)stored as orcfile;

有分割槽的hive表

use an_pafc_safe;

drop table an_pafc_safe.life_mbi_epics_info_yb;

create table an_pafc_safe.life_mbi_epics_info_yb

(deptno       string,

polno   string,

plan_code              string,

payment_date           string,

tot_modal_prem         string,

region_code         string,

amt_type           string,

prem_type string,

business_type string,

business_src string,

op_type string,

pol_yr string,

lcd string,

fcd string,

pk_serial string,

bank_channel_type string

)partitioned by ( `day` string)  

stored as orcfile;

進入hive後,使用對應的集市庫和設定相應的引數,然後執行表資料插入操作:

示例一:

use an_pafc_safe;

set mapred.job.queue.name=queue_0101_01;

set hive.exec.dynamic.partition=true;  

set hive.exec.dynamic.partition.mode=nonstrict; 

set hive.exec.max.dynamic.partitions.pernode = 1000;

set hive.exec.max.dynamic.partitions=1000;

insert overwrite table  an_pafc_safe.life_mbi_epics_info_yb partition(day)

select * from an_pafc_safe.life_mbi_epics_info_yb1

示例二:

insert overwrite table  an_pafc_safe.bas_ela_agent_info partition(day) 

select 

id            

,code          

,parent_code   

,type          

,type_no       

,type_name     

,channel       

,agent         

,openid            

,created_date as share_read_time

,referer       

,share_source  

,share_channel 

,detail_no     

,wxbind       

,substr(created_date,1,10) as statis_date

from sx_360_safe.sx_lvl_trace_info

where substr(created_date,1,10) <'2017-01-01'

and substr(created_date,1,10) <'2017-09-28'  ;

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中建表語句

hive中一共有以下幾種建表方式 create table person id int,name string,hobbies array,address map row format delimited fields terminated by collection items terminate...

Hive建表語句解釋

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