博客
关于我
Hive 动态分区入门
阅读量:666 次
发布时间:2019-03-15

本文共 1155 字,大约阅读时间需要 3 分钟。

什么是动态分区?

动态分区是一种Hive表的存储机制,其独特之处在于分区键由导入数据时的实际数据决定,而非在创建表时手动指定。这与传统静态分区不同,后者通常依赖预先定义好的分区键。

如何使用动态分区?

动态分区的使用需要谨慎配置及优化,以避免资源浪费和性能瓶颈。

前提条件调优

在启用动态分区前,请确保以下设置:

  • hive.exec.dynamic.partition=true:启用动态分区支持。
  • hive.exec.dynamic.partition.mode=strict/nonstrict:选择合适的模式:
    • 严格模式:在动态分区导入数据时,必须指定一个静态分区列。
    • 非严格模式:可以不指定静态分区列,默认使用最后一个字段作为分区键。
  • hive.exec.max.dynamic.partitions=1000:定义允许动态分区数量最大值。
  • hive.exec.max.dynamic.partitions.pernode=100:确保每个节点的Map/Reduce任务不会超负荷运行。

表结构配置

动态分区表通常采用类似方式创建:

create external table dy_part1(    sid     int,    name    string,    gender  string,    age     int,    academy string,    dt      string) partitioned by (dt string)row format delimited fields terminated by ',';

数据导入流程

动态分区表的数据导入通常分为以下步骤:

  • 创建临时表:

    sql create external table tmp_part1(...)

  • 导入数据:

    sql load data local inpath '/data/student2.txt' into tmp_part1;

  • 分区数据:

    sql insert into dy_part1 partition(dt) select * from tmp_part1;

  • 注意事项

    • 动态分区表应选择合适的分区列,避免过多不同值造成小文件爆炸。
    • 在非严格模式下,默认使用最后一列作为分区键,需谨慎选择。
    • 动态分区适用于数据量有保障且分区键值稳定的场景。

    适用场景

    • 企事业务数据:适合将日期或时间作为分区键。
    • 多层次分析:支持多维度数据分析,便于动态扩展。

    优化建议

    • 定期清理过期分区:避免存储膨胀。
    • 监控分区数量:确保不超过最大限制值。
    • 优化写入查询:减少Map/Reduce任务负载。

    通过合理配置和使用场景分析,动态分区能够显著提升数据管理效率,同时在存储和查询速度上实现平衡使用。

    转载地址:http://nvsmz.baihongyu.com/

    你可能感兴趣的文章
    Pillow lacks the JPEG 2000 plugin
    查看>>
    SpringBoot之ElasticsearchRestTemplate常用示例
    查看>>
    ping 全网段CMD命令
    查看>>
    ping 命令的七种用法,看完瞬间成大神
    查看>>
    Pinia入门(快速上手)
    查看>>
    Pinia:$patch的使用场景
    查看>>
    Pinia:$subscribe()的使用场景
    查看>>
    Pinpoint对Kubernetes关键业务模块进行全链路监控
    查看>>
    Pinterest 大规模缓存集群的架构剖析
    查看>>
    pintos project (2) Project 1 Thread -Mission 1 Code
    查看>>
    PinYin4j库的使用
    查看>>
    PIP
    查看>>
    pip install goose-extractor // SyntaxError: Missing parentheses in call to 'print'
    查看>>
    pip install mysqlclient报错
    查看>>
    pip install 出现报asciii码错误的解决
    查看>>
    pip throws TypeError: parse() got an unexpected keyword argument ‘transport_encoding‘ 在尝试安装新软件包时
    查看>>
    pip 下载慢
    查看>>
    pip 升级报错AttributeError: ‘NoneType’ object has no attribute ‘bytes’
    查看>>
    pip 安装opencv-python卡死
    查看>>
    pip 安装出现异常
    查看>>