HIVE-29754: Remove empty HIVE_UNION_SUBDIR moved directories after INSERT OVERWRITE UNION ALL#6625
Open
Indhumathi27 wants to merge 2 commits into
Open
HIVE-29754: Remove empty HIVE_UNION_SUBDIR moved directories after INSERT OVERWRITE UNION ALL#6625Indhumathi27 wants to merge 2 commits into
Indhumathi27 wants to merge 2 commits into
Conversation
Indhumathi27
force-pushed
the
tez_empty_dir
branch
from
July 22, 2026 07:36
031861f to
688bde0
Compare
Contributor
Author
|
@deniskuzZ / @abstractdog Please help to review. Thanks |
Contributor
Author
Indhumathi27
force-pushed
the
tez_empty_dir
branch
from
July 23, 2026 08:45
688bde0 to
eecbb93
Compare
Indhumathi27
force-pushed
the
tez_empty_dir
branch
from
July 23, 2026 09:06
eecbb93 to
779c9de
Compare
Indhumathi27
force-pushed
the
tez_empty_dir
branch
from
July 24, 2026 07:11
28154d8 to
e86838d
Compare
Indhumathi27
force-pushed
the
tez_empty_dir
branch
from
July 24, 2026 07:17
e86838d to
ccaa8cc
Compare
Indhumathi27
force-pushed
the
tez_empty_dir
branch
from
July 25, 2026 14:14
ccaa8cc to
b7d18a2
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses HIVE-29754 by ensuring Tez INSERT OVERWRITE ... UNION ALL commits do not leave behind empty -tmp.HIVE_UNION_SUBDIR_<N>.moved staging directories when a UNION branch produces zero rows, and adds a regression qtest to validate the behavior.
Changes:
- Add success-path cleanup for empty
.movedstaging directories inUtilities.mvFileToFinalPath(). - Refactor
mvFileToFinalPath()into smaller helpers (computeAvoidRename,renameTmpIfNeeded,removeDuplicatesAndFillBuckets,moveKeptFiles) and update call sites to the adjusted signature. - Add a new Tez positive qtest (query + expected output) and include it in the minitez test list.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java | Implements empty-branch .moved staging directory cleanup and refactors commit/move logic into helper methods. |
| ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java | Updates mvFileToFinalPath invocation to match the new signature. |
| ql/src/java/org/apache/hadoop/hive/ql/exec/AbstractFileMergeOperator.java | Updates mvFileToFinalPath invocation to match the new signature. |
| ql/src/java/org/apache/hadoop/hive/ql/io/rcfile/truncate/ColumnTruncateMapper.java | Updates mvFileToFinalPath invocation to match the new signature. |
| ql/src/test/queries/clientpositive/union_all_empty_branch_no_tmp_dir.q | Adds a Tez query test covering both non-empty and empty UNION branch scenarios (including flattened subdirs mode). |
| ql/src/test/results/clientpositive/tez/union_all_empty_branch_no_tmp_dir.q.out | Adds the expected output baseline for the new Tez qtest. |
| itests/src/test/resources/testconfiguration.properties | Registers the new qtest in the minitez query list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Indhumathi27
force-pushed
the
tez_empty_dir
branch
from
July 26, 2026 14:39
b7d18a2 to
8085a1e
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changes were proposed in this pull request?
Added cleanup of the empty
-tmp.HIVE_UNION_SUBDIR_N.movedstaging directoryin
Utilities.mvFileToFinalPath()when a UNION ALL branch produces 0 rows.Change: a single
else if (!avoidRename)block added after theif (statuses != null && statuses.length > 0)block inmvFileToFinalPath()to delete the
.movedstaging directory when it contains no output files.Why are the changes needed?
When executing INSERT OVERWRITE ... UNION ALL with the Tez execution engine,
if one UNION ALL branch produces 0 rows (e.g. an anti-join that returns no
results), an empty directory named
-tmp.HIVE_UNION_SUBDIR_<N>.movedis leftbehind in the final partition directory after the query completes successfully.
Root cause in Utilities.mvFileToFinalPath():
The success=false path at line 1515 correctly calls fs.delete(tmpPath, true),
but the equivalent cleanup was missing from the success=true + empty output path.
This does not occur with MapReduce execution engine.
Does this PR introduce any user-facing change?
No
How was this patch tested?
q file has been added