ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

hive分区表快速复制

2021-01-19 19:01:30  阅读:496  来源: 互联网

标签:COMMENT string dwt sale hive 复制 分区表 activity


1、快速建表

drop table if exists dwt.dwt_activity_auction_house_activity_sale_full_1d_0805forliuqian;
create table dwt.dwt_activity_auction_house_activity_sale_full_1d_0805forliuqian like dwt.dwt_activity_auction_house_activity_sale_full_1d;

2、查看复制好的表结构

hive> show create table dwt.dwt_activity_auction_house_activity_sale_full_1d_0805forliuqian;
OK
CREATE TABLE `dwt.dwt_activity_auction_house_activity_sale_full_1d_0805forliuqian`(
  `activity_sale_id` bigint COMMENT '拍卖会拍品信息主键id', 
  `activityid` bigint COMMENT '拍卖会活动id', 
  `userinfoid` bigint COMMENT '拍卖行id', 
  `lot` int COMMENT 'lot号', 
  `title` string COMMENT '标题', 
  `bidbzj` bigint COMMENT '保证金', 
  `increase` bigint COMMENT '加价幅度', 
  `startprize` bigint COMMENT '起拍价', 
  `min_referenceprice` bigint COMMENT '最小估值', 
  `max_referenceprice` bigint COMMENT '最大估值', 
  `category` int COMMENT '分类', 
  `seccategory` int COMMENT '二级分类', 
  `seccategory_template` string COMMENT '发拍模板', 
  `content` string COMMENT '拍品详情', 
  `illustration` string COMMENT '拍品说明', 
  `state` int COMMENT '0:草稿;1-待审核;2-审核通过;3-审核驳回;4-已上拍;5-已隐藏;6-已下架', 
  `upload_time` string COMMENT '上拍时间', 
  `sale_id` bigint COMMENT '拍品id,sale表id', 
  `end_time` string COMMENT '截拍时间', 
  `open_time` string COMMENT '开拍时间', 
  `sale_status` int COMMENT '拍品状态: -1:unsold 1:等待支付保证金 2:sale 3:deal', 
  `enable_return` int COMMENT '是否包退 0-不包退;1-包退', 
  `express_fee` int COMMENT '是否包邮 0-不包邮;1-包邮', 
  `last_edit_username` string COMMENT '最后编辑人记录', 
  `last_edit_time` string COMMENT '最后编辑时间', 
  `reject_reason` string COMMENT '拒绝原因', 
  `sort_num` bigint COMMENT '排序值', 
  `is_del` int COMMENT '是否删除', 
  `create_time` string COMMENT '创建时间', 
  `update_time` string COMMENT '更新时间')
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
  '/usr/hive/warehouse/dwt.db/dwt_activity_auction_house_activity_sale_full_1d_0805forliuqian'
TBLPROPERTIES (
  'orc.compress'='snappy')
Time taken: 0.903 seconds, Fetched: 44 row(s)

跟原始表一模一样,有分区,就是没有数据。

3、拷数据

hadoop fs -cp /usr/hive/warehouse/dwt.db/dwt_activity_auction_house_activity_sale_full_1d/* /usr/hive/warehouse/dwt.db/dwt_activity_auction_house_activity_sale_full_1d_0805forliuqian/

4、修复分区元数据

MSCK REPAIR TABLE dwt.dwt_activity_auction_house_activity_sale_full_1d_0805forliuqian;

5、查询和校验

select dt,count(*)
from dwt.dwt_activity_auction_house_activity_sale_full_1d_0805forliuqian
group by dt;

select dt,count(*)
from dwt.dwt_activity_auction_house_activity_sale_full_1d
group by dt;

6、动态分区数据插入方式

以上步骤3、4也可以通过动态分区数据插入来做

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table ds_parttion partition(state='china',ct)
select id ,city from mytest_tmp2_p; 
set hive.exec.dynamici.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table ds_parttion partition(state,ct)
select id ,country,city from  mytest_tmp2_p; 


使用动态分区表必须配置的参数:

set hive.exec.dynamic.partition =true(默认false),表示开启动态分区功能
set hive.exec.dynamic.partition.mode = nonstrict(默认strict),表示允许所有分区都是动态的,否则必须有静态分区字段

动态分区相关的调优参数:

set hive.exec.max.dynamic.partitions.pernode=100
set hive.exec.max.dynamic.partitions =1000
set hive.exec.max.created.files =10000 (默认) 全局可以创建的最大文件个数,超出报错。

标签:COMMENT,string,dwt,sale,hive,复制,分区表,activity
来源: https://blog.csdn.net/BabyFish13/article/details/107818273

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有