1. 程式人生 > >hive建表語句(包括txt、Orc和分割槽)

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

--------------------------------

txt格式  無分割槽

-------------------------------

use sx_360_safe;
create table sx_360_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 sx_360_safe;


 create table sx_360_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 sx_360_safe;
 drop table sx_360_safe.life_mbi_epics_info_yb;
 create table sx_360_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;


insert ove
 create table sx_360_safe.life_mbi_epics_info_yb1
(
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;


















use sx_360_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  sx_360_safe.life_mbi_epics_info_yb 
partition(day)
select * from sx_360_safe.life_mbi_epics_info_yb1  


insert overwrite table  sx_360_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'  ;