Hive命令-复制表(数据&分区数据)

一、创建基础表

 > show create table dim_fei001;
OK
CREATE EXTERNAL TABLE `dim_fei001`(
  `zd_001` double COMMENT '字段一qqq', 
  `zd002` int COMMENT '222', 
  `zd003` float COMMENT '3333', 
  `zd004` string COMMENT 'vvv')
PARTITIONED BY ( 
  `dt` string)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.ql.io.orc.OrcSerde' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
  'hdfs://bipcluster/data/external_table/dim/dim_fei001'
TBLPROPERTIES (
  'last_modified_by'='master', 
  'last_modified_time'='1520410725', 
  'transient_lastDdlTime'='1520410725')
Time taken: 0.058 seconds, Fetched: 19 row(s)

二、复制表结构

create table dim_fei001_03 like dim_fei001;

查看生成的表结构

> show create table dim_fei001_03;
OK
CREATE TABLE `dim_fei001_03`(
  `zd_001` double COMMENT '字段一qqq', 
  `zd002` int COMMENT '222', 
  `zd003` float COMMENT '3333', 
  `zd004` string COMMENT 'vvv')
PARTITIONED BY ( 
  `dt` string)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.ql.io.orc.OrcSerde' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
  'hdfs://bipcluster/data/hive_warehouse/dim.db/dim_fei001_03'
TBLPROPERTIES (
  'transient_lastDdlTime'='1521121458')
Time taken: 0.255 seconds, Fetched: 17 row(s)

三、复制表

dfs -cp -f /data/external_table/dim/dim_fei001/*  /data/hive_warehouse/dim.db/dim_fei001_03;

四、修复分区元数据信息,hive cmd模式下:

MSCK REPAIR TABLE dim_fei001_03;
    原文作者:BestFei
    原文地址: https://www.jianshu.com/p/18061f932448
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞