1. 程式人生 > >hive內部表,修改分割槽名字

hive內部表,修改分割槽名字

1,建立一個分割槽表
CREATE TABLE `stg.stu`(
  `id` string COMMENT '使用者唯一識別ID', 
  `name` string COMMENT '名字')
COMMENT '學生資訊'
PARTITIONED BY ( 
  `day` string, 
  `type` string)
ROW FORMAT DELIMITED 
  FIELDS TERMINATED BY '\t' 
  COLLECTION ITEMS TERMINATED BY ',' 
  MAP KEYS TERMINATED BY ':' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  'hdfs://journey/user/hive/warehouse/stg.db/stu'
TBLPROPERTIES (
  'transient_lastDdlTime'='1502360831');


2,模擬資料
day=20170101/type=102
1       lisi
2       zhangsan


3,上傳到hdfs上
hdfs dfs -put ./day\=20170101/ hdfs://journey/user/hive/warehouse/stg.db/stu


4,載入到hive表中
load data inpath 'hdfs://journey/user/hive/warehouse/stg.db/stu/day=20170101/type=102' into table stg.stu partition(day=20170101,type=102);


5,修改表名(內部表會移動目錄)
ALTER TABLE stg.stu RENAME TO stg.stu_bak;


6,創表表,修改分割槽
CREATE TABLE `stg.stu`(
  `id` string COMMENT '使用者唯一識別ID', 
  `name` string COMMENT '名字')
COMMENT '學生資訊'
PARTITIONED BY ( 
  `day` string, 
  `source` string)
ROW FORMAT DELIMITED 
  FIELDS TERMINATED BY '\t' 
  COLLECTION ITEMS TERMINATED BY ',' 
  MAP KEYS TERMINATED BY ':' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  'hdfs://journey/user/hive/warehouse/stg.db/stu'
TBLPROPERTIES (
  'transient_lastDdlTime'='1502360831');
7,將bak hdfs目錄上的資料load到stu表中
load data inpath 'hdfs://analysys/apps/hive/warehouse/stg.db/stu_bak/day=20170101/source=102' into table stg.stu partition(day=20170101,source=102);