agentsclimarketplace

Hive optimization skill

Skill reverie2129/hive-optimization-skill

Agent Skill for optimizing Apache Hive on MapReduce — 26 actionable best-practice rules covering storage, query, JOIN, data skew, and MR parameter tuning. Works with Cursor & Claude Code.

Install
npx -y skills add reverie2129/hive-optimization-skill

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

审查或优化 Hive on MapReduce 任务(建表、HQL 查询、JOIN、数据倾斜、参数调优)时必须使用。包含 26 条规则,给出建议前必须先检查相关规则,并在回答中引用具体规则名。

The file declares its own license as Apache-2.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

8.7 KB, as published. Nobody here has run it

Hive 最佳实践(面向 MapReduce 任务优化)

面向 Hive on MapReduce 的优化指南,覆盖存储与表设计、查询优化、JOIN 优化、数据倾斜、MapReduce 参数调优与引擎选择。包含 6 大类共 26 条规则,按对作业性能的影响排序。

官方文档: Apache Hive Wiki

重要:如何应用本 Skill

在回答任何 Hive 优化问题前,按以下优先级处理:

  1. 检查 rules/ 目录中是否有适用规则
  2. 若有规则: 应用它,并在回答中用"依据 rule-name……"的形式引用
  3. 若无规则: 使用通用 Hive 知识或查阅官方文档
  4. 若不确定: 搜索当前版本的最佳实践
  5. 始终注明来源: 规则名、"通用 Hive 指南"或文档 URL

为什么规则优先: Hive on MapReduce 有一套特定的执行机制(每个 MR 作业中间结果落 HDFS、Shuffle 成本、单 Reducer 瓶颈、数据倾斜长尾),通用数据库直觉常常失效。规则编码的是针对 Hive/MR 验证过的具体经验。


审查流程

建表 / 表结构审查 (CREATE TABLE)

按顺序阅读这些规则文件:

  1. rules/storage-file-format.md — 用 ORC/Parquet 列式存储
  2. rules/storage-compression.md — 启用压缩
  3. rules/storage-partition.md — 按查询维度分区(低基数)
  4. rules/storage-bucketing.md — 对 JOIN 键分桶
  5. rules/storage-small-files.md — 规避小文件

检查项:

  • 存储格式为 ORC/Parquet(非 TextFile)
  • 已配置压缩(存储/中间/输出)
  • 按低基数高频过滤列分区(通常是 dt),无高基数分区键
  • 大表 JOIN 场景已按 JOIN 键分桶并排序
  • 有避免小文件的写入策略

查询审查 (SELECT / 聚合)

阅读这些规则文件:

  1. rules/query-partition-pruning.md — 命中分区裁剪
  2. rules/query-column-pruning.md — 避免 SELECT *
  3. rules/query-predicate-pushdown.md — 谓词下推
  4. rules/query-cbo-stats.md — 开启 CBO + 统计信息
  5. rules/query-vectorization.md — 矢量化执行
  6. rules/query-count-distinct.md — count(distinct) 改写
  7. rules/query-order-by.md — ORDER BY/SORT BY 选择

检查项:

  • WHERE 命中分区裁剪(未对分区列套函数)
  • 只取必要列,无 SELECT *
  • 谓词可下推(PPD 开启,外连接过滤放 ON)
  • 已开启 CBO 且表有统计信息
  • ORC 表已开启矢量化
  • 无单 Reducer 瓶颈(count distinct / ORDER BY 已改写)

JOIN 审查

阅读这些规则文件:

  1. rules/join-map-join.md — 小表 Map Join
  2. rules/join-bucket-smb.md — 大表 Bucket Map Join / SMB Join
  3. rules/join-order.md — JOIN 顺序与提前过滤
  4. rules/join-skew.md — JOIN 数据倾斜
  5. rules/skew-null.md — NULL 关联键倾斜

检查项:

  • 大表 JOIN 小表已走 Map Join(hive.auto.convert.join=true
  • 大表 JOIN 大表已用分桶 + SMB Join
  • 先过滤后关联,大表放 JOIN 序列最后
  • 已处理热点 key 与 NULL 关联键倾斜

数据倾斜审查

阅读这些规则文件:

  1. rules/skew-groupby.md — GROUP BY 倾斜
  2. rules/join-skew.md — JOIN 倾斜
  3. rules/skew-null.md — NULL 倾斜

检查项:

  • GROUP BY 倾斜已开 Map 端聚合,必要时开 groupby.skewindata
  • JOIN 热点 key 已用 skew join 或加盐
  • NULL/默认值关联键已过滤或打散

参数调优审查

阅读这些规则文件:

  1. rules/mr-mapper-count.md — Mapper 数量(split 大小)
  2. rules/mr-reducer-count.md — Reducer 数量
  3. rules/mr-map-aggr.md — Map 端聚合
  4. rules/mr-parallel.md — 并行执行
  5. rules/mr-speculative.md — 推测执行
  6. rules/mr-merge-output.md — 输出合并

检查项:

  • Mapper 数量合理(小文件用 CombineHiveInputFormat)
  • Reducer 按 bytes.per.reducer 自动估算,未盲目写死
  • 已开 Map 端聚合
  • 无依赖阶段已并行
  • 推测执行按倾斜/写外部表场景正确开关
  • 输出小文件已合并

输出格式

按如下结构组织回答:

## 已检查规则
- `rule-name-1` - 合规 / 发现违规
- `rule-name-2` - 合规 / 发现违规
...

## 发现

### 违规
- **`rule-name`**: 问题描述
  - 现状: [当前 HQL/建表的做法]
  - 要求: [应该怎么做]
  - 修复: [具体改法,附 SQL/参数]

### 合规
- `rule-name`: 简述为何正确

## 建议
[按优先级列出的改动清单,引用规则名]

规则分类与优先级

优先级分类影响前缀规则数
1存储格式CRITICALstorage-file-1
2分区设计CRITICALstorage-partition1
3分区裁剪CRITICALquery-partition-1
4Map JOINCRITICALjoin-map-1
5JOIN 倾斜CRITICALjoin-skew1
6压缩/分桶/小文件HIGHstorage-3
7列裁剪/谓词下推/CBO/矢量化HIGHquery-4
8SMB JOINHIGHjoin-bucket-1
9GROUP BY 倾斜HIGHskew-groupby1
10Mapper/Reducer/Map聚合/输出合并HIGHmr-4
11count distinct / 排序 / JOIN 顺序MEDIUM多种3
12NULL 倾斜 / 并行 / 推测执行MEDIUM多种3
13动态分区 / 引擎选择MEDIUMengine-2

快速参考

存储与表设计 (storage)

  • storage-file-format — 用 ORC/Parquet 列式存储,禁止大表 TextFile [CRITICAL]
  • storage-partition — 按低基数高频过滤列分区,禁高基数分区键 [CRITICAL]
  • storage-compression — 开启存储/中间/输出压缩(Snappy 默认)
  • storage-bucketing — 对 JOIN 键分桶以支撑 Bucket Map / SMB Join
  • storage-small-files — 写入合并 + 读取 CombineHiveInputFormat

查询优化 (query)

  • query-partition-pruning — WHERE 命中分区裁剪,勿对分区列套函数 [CRITICAL]
  • query-column-pruning — 只取必要列,避免 SELECT *
  • query-predicate-pushdown — 谓词下推,外连接过滤放 ON
  • query-cbo-stats — 开启 CBO 并 ANALYZE 收集统计
  • query-vectorization — ORC 表开启矢量化执行
  • query-count-distinct — 两阶段改写避免单 Reducer
  • query-order-by — 慎用 ORDER BY,按需用 SORT/DISTRIBUTE/CLUSTER BY

JOIN 优化 (join)

  • join-map-join — 小表广播为 Map Join,跳过 Reduce [CRITICAL]
  • join-skew — 处理热点 key 倾斜(skew join / 加盐) [CRITICAL]
  • join-bucket-smb — 大表 JOIN 大表用 Bucket Map / SMB Join
  • join-order — 先过滤后关联,大表放最后

数据倾斜 (skew)

  • skew-groupby — Map 端聚合 + groupby.skewindata 两阶段
  • skew-null — NULL/默认值关联键的过滤或加盐

MapReduce 参数 (mr)

  • mr-mapper-count — 用 split 大小与 CombineHiveInputFormat 控 Mapper 数
  • mr-reducer-count — 用 bytes.per.reducer 自动估算 Reducer 数
  • mr-map-aggr — 开启 Map 端聚合减少 Shuffle
  • mr-merge-output — 作业末尾合并输出小文件
  • mr-parallel — 并行执行无依赖阶段
  • mr-speculative — 按倾斜/写外部表场景管理推测执行

引擎与高级 (engine)

  • engine-dynamic-partition — 动态分区正确配置 + DISTRIBUTE BY 控文件数
  • engine-consider-tez — MR 成瓶颈时评估切换 Tez/Spark

何时触发本 Skill

遇到以下情况时启用:

  • CREATE TABLE / ALTER TABLE 语句
  • HQL 查询慢、跑得久、卡在某个阶段
  • JOIN 优化需求(大表关联、广播、分桶)
  • "作业卡在 99%" / Reduce 长尾 / 数据倾斜
  • 小文件过多、Mapper/Reducer 数量异常
  • GROUP BY / COUNT(DISTINCT) / ORDER BY 性能问题
  • 动态分区写入、ETL 调度任务优化
  • 考虑从 MapReduce 切换执行引擎

规则文件结构

rules/ 中每个规则文件包含:

  • YAML frontmatter:title、impact 影响等级、tags
  • 简要说明:为什么重要(对 MR 作业的影响)
  • 错误示例:反模式及问题说明
  • 正确示例:最佳实践及参数/SQL
  • 补充:对照表、适用场景、官方文档链接

完整汇编文档

需要一次性速查所有规则时,阅读:AGENTS.md(所有规则内联展开,无需逐个打开文件)。

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.