Level 6: Hive/Tez Integration
Hive-on-Tez is the single largest consumer of the Tez API in existence. The overwhelming majority of Tez bug reports that reach the mailing list — a slow query, a shuffle fetch failure, a reducer OOM, a counter that reads wrong — originate as a Hive query. If you want to fix the bugs real operators file, you must be able to stand at the boundary between the two projects and say, with confidence, "this half is Hive's job, that half is Tez's job, and the symptom lives here."
This level is the on-ramp to that skill. It teaches you the layering
end-to-end — HiveQL down to a submitted Tez DAG — and it teaches you to read
a Hive-on-Tez failure like a stack of layers, peeling from the console message
down to the AM diagnostics down to the task logs. The deeper, PR-grade
treatment lives in the hive-on-tez-labs
section; this level positions you to work through it.
Learning Objectives
By the end of Level 6 you must be able to:
- Draw the full translation pipeline —
HiveQL → SemanticAnalyzer → TezCompiler → TezWork → DagUtils → Tez DAG API → TezClient.submitDAG— and name, for each hop, the class that owns it and which project it belongs to. - State precisely what is Hive's job and what is Tez's job: Hive owns
compilation, the operator tree, physical
Workunits, and DAG construction; Tez owns DAG execution — scheduling, vertices, edges, shuffle, and theShuffleVertexManagerthat Hive attaches. - Map an
EXPLAINplan's vertices (Map 1,Reducer 2) onto the TezDAGImplruntime objects of the same name, and back again. - Take a Hive-on-Tez failure and locate its layer — compile-time, DAG-submit, runtime task, or shuffle — from the shape of the diagnostic string alone.
- Read a
Vertex failed, vertexName=...diagnostic emitted by Tez and walk it back to the Hive operator tree that produced that vertex. - Decide, for a given fix, whether the patch belongs in Tez or in Hive — and articulate why.
What Hive Does With Tez, and Where the Seam Is
Every Hive query that runs on the Tez engine (SET hive.execution.engine=tez)
travels this path:
flowchart TD
SQL["HiveQL text"] --> AST["ParseDriver → AST (ANTLR)"]
AST --> SA["SemanticAnalyzer<br/>AST → QB → Operator tree (logical plan)"]
SA --> TC["TezCompiler<br/>logical → physical: MapWork / ReduceWork"]
TC --> TW["TezWork<br/>graph of BaseWork nodes + edges"]
TW --> DU["DagUtils.createVertex / createEdge<br/>TezWork → Tez DAG objects"]
DU --> API["Tez DAG API<br/>DAG / Vertex / Edge / VertexManagerPluginDescriptor"]
API --> SUB["TezTask → TezClient.submitDAG(DAG)"]
SUB --> EXEC["Tez AM: DAGImpl / VertexImpl / TaskImpl<br/>schedule, shuffle, run"]
subgraph HIVE["Hive (hive-exec / ql)"]
AST
SA
TC
TW
DU
SUB
end
subgraph TEZ["Tez (tez-api / tez-dag / tez-runtime-library)"]
API
EXEC
end
Read the seam carefully, because it is the whole point of this level:
- Hive owns everything above the API call. Parsing, semantic analysis,
the operator tree, the physical plan (
MapWork/ReduceWork), and the construction of theDAGobject — assembling vertices, wiring edges, choosing theShuffleVertexManager, and setting the payload that controls auto-parallelism — are all Hive code.DagUtilsis the factory; it produces Tez API objects but it is a Hive class. - Tez owns everything below the API call. Once
TezClient.submitDAG(dag)returns aDAGClient, Hive is a spectator. The Tez AM (DAGImpl,VertexImpl,TaskImpl,TaskAttemptImpl) schedules and runs the DAG;tez-runtime-libraryexecutes the shuffle; the vertices are named exactly what Hive named them (Map 1,Reducer 2).
The consequence is a rule you will use constantly when triaging bugs: if the
wrong thing happened during compilation or DAG construction, it is a Hive
bug; if the wrong thing happened during execution of a correctly-built DAG,
it is a Tez bug. A GROUP BY that produced the wrong number of reducers may
be a Hive planning bug or a Tez ShuffleVertexManager reconfiguration bug —
and telling them apart is exactly the discrimination this level trains.
How This Level Relates to hive-on-tez-labs
This level is deliberately smaller than the full Hive-on-Tez labs. Think of the relationship this way:
| This level (Level 6) | The hive-on-tez-labs section |
|---|---|
| Two labs: trace one query, debug one failure | Six labs: SQL→DAG, DAG inspection, query debugging, bug attribution, reproduction, diagnostics |
| Builds the mental model of the layering | Drills each layer to PR-grade depth |
| "Which layer is this?" | "Write the patch and the test that proves it" |
Do the two labs here first. They give you the vocabulary — TezWork,
DagUtils, vertex names, the diagnostic stack — that the deeper section
assumes. When you finish, go to
Lab H1: SQL → DAG and work forward.
Required Reading
Before the labs, read (or skim and bookmark):
- Deep dive: Hive integration — the architecture of the seam.
- Hive-on-Tez Labs — overview — where this level hands off.
- Lab H1: SQL → DAG and Lab H3: Debug a Query — the full versions of this level's two labs.
- This level's labs:
Source Areas
Hive side — verify in your own Hive checkout
Hive source is not part of your Tez checkout. Clone Hive alongside it and use
grep/find to confirm every class before you cite it — Hive moves classes
between releases, so trust your checkout, not this table.
| Area | Typical path (verify with find) | Role |
|---|---|---|
| Parse / semantic analysis | ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java | AST → operator tree |
| Physical compilation | ql/src/java/org/apache/hadoop/hive/ql/parse/TezCompiler.java | logical → MapWork/ReduceWork |
| DAG spec container | ql/src/java/org/apache/hadoop/hive/ql/plan/TezWork.java | graph of BaseWork |
| DAG construction | ql/src/java/org/apache/hadoop/hive/ql/exec/tez/DagUtils.java | TezWork → Tez DAG |
| Execution boundary | ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezTask.java | submit + wait + surface diagnostics |
# In your Hive checkout, confirm the classes exist before trusting any claim:
for c in SemanticAnalyzer TezCompiler TezWork DagUtils TezTask; do
find . -name "$c.java" -path "*org/apache/hadoop/hive*"
done
Tez side — in your Tez checkout
These are the Tez classes Hive drives. Cite them by module + class, never by line number.
| Area | Path in the Tez checkout | Role |
|---|---|---|
| DAG runtime | tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/DAGImpl.java | executes the submitted DAG; emits Vertex failed diagnostics |
| Vertex runtime | tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexImpl.java | per-vertex state machine; emits Task failed diagnostics |
| Reduce scheduling | tez-runtime-library/src/main/java/org/apache/tez/dag/library/vertexmanager/ShuffleVertexManager.java | the plugin Hive attaches to reduce vertices; auto-parallelism |
| Reduce output | tez-runtime-library/src/main/java/org/apache/tez/runtime/library/output/OrderedPartitionedKVOutput.java | Hive's default map/reduce shuffle output |
| Reduce input | tez-runtime-library/src/main/java/org/apache/tez/runtime/library/input/OrderedGroupedKVInput.java | the grouped, sorted reduce input |
| Edge configuration | tez-runtime-library/src/main/java/org/apache/tez/runtime/library/conf/OrderedPartitionedKVEdgeConfig.java | the SCATTER_GATHER edge Hive builds |
| Submission API | tez-api/src/main/java/org/apache/tez/client/TezClient.java | submitDAG — the boundary Hive calls |
# In your Tez checkout, confirm the auto-parallelism config key is real:
grep -rn "enable.auto-parallel" \
tez-runtime-library/src/main/java/org/apache/tez/dag/library/vertexmanager/ShuffleVertexManager.java
Key Classes — Quick Reference
| Class | Project | What it does | Why you care |
|---|---|---|---|
SemanticAnalyzer | Hive | AST → operator tree | wrong plan starts here |
TezCompiler | Hive | operator tree → MapWork/ReduceWork | vertex count / edge shape decided here |
TezWork | Hive | graph of BaseWork | the spec DagUtils reads |
DagUtils | Hive | TezWork → Tez DAG | where ShuffleVertexManager + payloads are attached |
TezTask | Hive | submit + wait + report | translates DAGStatus back to the user |
DAGImpl | Tez tez-dag | run the DAG | emits Vertex failed, vertexName=... |
VertexImpl | Tez tez-dag | run a vertex | emits Task failed, taskId=... |
ShuffleVertexManager | Tez tez-runtime-library | schedule reducers, auto-parallelism | reducer-count surprises live here |
TezClient | Tez tez-api | submitDAG | the seam between the two projects |
Note: The vertex names in the Tez runtime —
Map 1,Reducer 2— are strings chosen by Hive inDagUtils. That is why a Tez-side diagnostic likevertexName=Reducer 2can be read straight off a HiveEXPLAINplan. This naming coincidence is your single most useful debugging bridge.
Deliverables
Before advancing to Level 7, you must produce:
-
A labelled diagram of one real query (a
GROUP BY) traced from HiveQL to a submitted Tez DAG, with every vertex, edge type, and theShuffleVertexManageron the reduce vertex — attributed to the Hive class that created each piece (Lab 6.1). -
The
EXPLAINoutput for that query with each vertex line mapped to a Tez runtime vertex of the same name, confirmed against the DAG summary (hive.tez.exec.print.summary=true). -
A failure-triage writeup: given a
Vertex faileddiagnostic, the layer it belongs to, the exact log you would pull next (console → AM →yarn logs), and the Hive operator subtree behind the named vertex (Lab 6.2). -
A one-paragraph, from-memory statement of the Hive/Tez seam: what
each project owns and where
submitDAGdivides them.
Common Mistakes
| Mistake | Consequence | Correction |
|---|---|---|
Treating DagUtils as a Tez class | You grep the Tez checkout and can't find it | DagUtils is Hive code; it produces Tez API objects |
| Assuming reducer count is decided at compile time | You misdiagnose auto-parallelism surprises | Hive may attach ShuffleVertexManager, which reconfigures reducer count at runtime |
| Reading the Hive console message and stopping | You miss the real cause | The console shows the first Vertex failed; the cause is deeper, in the AM/task logs |
Confusing Map 1 the operator with Map 1 the vertex | You look in the wrong project | Same name, two objects: a Hive MapWork and a Tez VertexImpl |
| Blaming Tez for a bad plan | Wrong project, wasted PR | A wrong plan is a Hive bug; wrong execution of a correct plan is Tez |
| Ignoring the Hive/Tez version pairing | "Works on my cluster" | Compatibility across Hive×Tez versions is a real, common release blocker |
How to Verify Success
You are ready to move on when you can, without notes:
# 1) Point at the seam in the Tez checkout — the method Hive calls.
grep -rn "public.*submitDAG" tez-api/src/main/java/org/apache/tez/client/TezClient.java
# 2) Show the Tez-side diagnostic strings you will read in Lab 6.2.
grep -rn "\"Vertex failed\"" tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/DAGImpl.java
grep -rn "\"Task failed\"" tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexImpl.java
# 3) Show the reduce-vertex plugin Hive attaches, and its auto-parallelism flag.
grep -rn "enable.auto-parallel" \
tez-runtime-library/src/main/java/org/apache/tez/dag/library/vertexmanager/ShuffleVertexManager.java
If each command lands where you expect and you can narrate why — that
submitDAG is the boundary, that DAGImpl/VertexImpl emit the diagnostics
Hive surfaces, and that the reduce plugin is Hive-attached but Tez-executed —
you understand the seam.
PR Profile: Level 6 Graduate
A contributor who has completed this level can credibly open or review these kinds of PRs:
- Triage a "Hive query is slow/broken" report and correctly route it: "this
is a Hive planning issue, closing as not-a-Tez-bug" or "this is a Tez
ShuffleVertexManagerreconfiguration bug, here is the failing vertex." - Add or improve a diagnostic in
DAGImpl/VertexImplso the string Hive surfaces to the user names the offending vertex and cause more precisely — the kind of small, high-value change reviewers love. - Reproduce a Hive-reported bug as a pure Tez DAG, stripping Hive out of
the picture so the fix and its test live entirely in Tez (the skill the
hive-on-tez-labssection makes production-grade). - Review a Hive-side
DagUtilschange for its Tez consequences: does it set a legalEdgeProperty? does itsShuffleVertexManagerpayload parse?
You cannot yet write the runtime-library fix that a shuffle bug demands — that is Level 7, where you drop below the seam and modify the shuffle and processor code itself. But you can now find which side of the seam any Hive-on-Tez bug lives on, which is where every one of those PRs begins.