You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "difin (via GitHub)" <gi...@apache.org> on 2026/08/10 20:12:34 UTC
[PR] HIVE-29808: Iceberg: Add guardrails to compaction with schema evolution [hive]
difin opened a new pull request, #6690:
URL: https://github.com/apache/hive/pull/6690
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
3. Ensure you have added or run the appropriate tests for your PR:
4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX: Your PR title ...'.
5. Be sure to keep the PR description updated to reflect all changes.
6. Please write your PR title to summarize what this PR proposes.
7. If possible, provide a concise example to reproduce the issue for a faster review.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
Added guardrails for Iceberg partition-scoped compaction on tables that have undergone partition spec evolution, where the same partition path can match more than one historical spec. This scenario is possible with partition schema evolution with Iceberg v1 tables. Also, added more tests for partition schema evolution that cover the following cases: unpartitioned to partitioned , spec change, back to unpartitioned.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
Iceberg compaction matches partitions by path and with Iceberg v1 tables that undergone partition schema evolution this can cause issues.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
If no, write 'No'.
-->
Yes, Iceberg compaction may be refused for Iceberg v1 tables that undergone partition schema evolution in case more than one partition matches the same path.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
Added more partition evolution cases to existing q-tests; Added new test class `TestIcebergTableUtil` that tests `IcebergTableUtil.getPartitionSpec()` against a real v1 Iceberg table built with `HadoopTables` and evolved via the Iceberg API: ambiguous resolution after repeated spec changes (identity → unpartitioned → identity), a unique match after a single spec change, and failure when no spec matches the partition path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29808: Iceberg: Add guardrails to compaction with schema evolution [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6690:
URL: https://github.com/apache/hive/pull/6690#issuecomment-5246311613
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6690) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6690&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6690&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6690&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6690&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6690&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6690)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29808: Iceberg: Add guardrails to compaction with schema evolution [hive]
Posted by "difin (via GitHub)" <gi...@apache.org>.
difin merged PR #6690:
URL: https://github.com/apache/hive/pull/6690
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29808: Iceberg: Add guardrails to compaction with schema evolution [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6690:
URL: https://github.com/apache/hive/pull/6690#issuecomment-5274062559
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6690) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6690&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6690&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6690&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6690&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6690&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6690)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29808: Iceberg: Add guardrails to compaction with schema evolution [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6690:
URL: https://github.com/apache/hive/pull/6690#issuecomment-5258739659
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6690) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6690&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6690&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6690&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6690&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6690&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6690)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29808: Iceberg: Add guardrails to compaction with schema evolution [hive]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6690:
URL: https://github.com/apache/hive/pull/6690#discussion_r3780315584
##########
ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveStorageHandler.java:
##########
@@ -901,6 +901,15 @@ default boolean canUseTruncate(org.apache.hadoop.hive.ql.metadata.Table hmsTable
return true;
}
+ /**
+ * Validates that partition compaction can resolve a unique partition spec for the given partition name.
+ * @param hmsTable table metadata stored in Hive Metastore
+ * @param partitionName fully qualified partition name
+ */
+ default void validateCompactionPartition(org.apache.hadoop.hive.ql.metadata.Table hmsTable, String partitionName)
+ throws HiveException {
+ }
Review Comment:
The Javadoc says `partitionName` is a "fully qualified partition name", but the Iceberg implementation and `IcebergTableUtil.getPartitionSpec` expect a Hive-style partition *path* like `dept_id=2` (or `a=1/b=2`). Updating the Javadoc avoids confusion for other storage handler implementers/callers.
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergTableUtil.java:
##########
@@ -775,15 +775,25 @@ public static PartitionSpec getPartitionSpec(Table icebergTable, String partitio
// Extract field names from the path: "field1=val1/field2=val2" → [field1, field2]
List<String> fieldNames = Lists.newArrayList(Warehouse.makeSpecFromName(partitionPath).keySet());
- return icebergTable.specs().values().stream()
+ List<PartitionSpec> matches = icebergTable.specs().values().stream()
.filter(spec -> {
List<String> specFieldNames = spec.fields().stream()
.map(PartitionField::name)
.toList();
return specFieldNames.equals(fieldNames);
})
- .findFirst() // Supposed to be only one matching spec
- .orElseThrow(() -> new HiveException("No matching partition spec found for partition path: " + partitionPath));
+ .toList();
+
+ if (matches.size() > 1) {
+ throw new HiveException(String.format(
+ "Ambiguous partition spec for partition path %s: matched spec ids %s",
+ partitionPath,
+ matches.stream().map(PartitionSpec::specId).map(String::valueOf).collect(Collectors.joining(", "))));
+ }
Review Comment:
The ambiguous-spec error message builds the spec id list from `icebergTable.specs().values()` iteration order, which can be non-deterministic depending on the backing map implementation. Sorting the spec ids makes the message stable (and prevents test flakiness / log churn).
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java:
##########
@@ -2209,6 +2209,20 @@ Boolean hasAppendsOnly(Iterable<Snapshot> snapshots, SnapshotContext since) {
return null;
}
+ @Override
+ public void validateCompactionPartition(org.apache.hadoop.hive.ql.metadata.Table hmsTable, String partitionName)
+ throws HiveException {
+ Table table = IcebergTableUtil.getTable(conf, hmsTable.getTTable());
+ if (!IcebergTableUtil.hasUndergonePartitionEvolution(table)) {
+ return;
+ }
+ try {
+ IcebergTableUtil.getPartitionSpec(table, partitionName);
+ } catch (MetaException e) {
+ throw new HiveException(e);
+ }
+ }
Review Comment:
When the partition spec resolution fails, the exception currently bubbles up as a generic `HiveException` message from `IcebergTableUtil.getPartitionSpec`. Wrapping it here with compaction context (table + operation) would make failures easier to diagnose for users running `ALTER TABLE .. COMPACT PARTITION(...)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29808: Iceberg: Add guardrails to compaction with schema evolution [hive]
Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6690:
URL: https://github.com/apache/hive/pull/6690#discussion_r3784463276
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java:
##########
@@ -2209,6 +2209,20 @@ Boolean hasAppendsOnly(Iterable<Snapshot> snapshots, SnapshotContext since) {
return null;
}
+ @Override
+ public void validateCompactionPartition(org.apache.hadoop.hive.ql.metadata.Table hmsTable, String partitionName)
+ throws HiveException {
+ Table table = IcebergTableUtil.getTable(conf, hmsTable.getTTable());
+ if (!IcebergTableUtil.hasUndergonePartitionEvolution(table)) {
+ return;
+ }
+ try {
+ IcebergTableUtil.getPartitionSpec(table, partitionName);
+ } catch (MetaException e) {
+ throw new HiveException(e);
+ }
+ }
Review Comment:
This suggestion doesn't make sense because the method `IcebergTableUtil.getPartitionSpec` is a generic util that can be used not only in Iceberg compaction.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29808: Iceberg: Add guardrails to compaction with schema evolution [hive]
Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6690:
URL: https://github.com/apache/hive/pull/6690#discussion_r3784428516
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergTableUtil.java:
##########
@@ -775,15 +775,25 @@ public static PartitionSpec getPartitionSpec(Table icebergTable, String partitio
// Extract field names from the path: "field1=val1/field2=val2" → [field1, field2]
List<String> fieldNames = Lists.newArrayList(Warehouse.makeSpecFromName(partitionPath).keySet());
- return icebergTable.specs().values().stream()
+ List<PartitionSpec> matches = icebergTable.specs().values().stream()
.filter(spec -> {
List<String> specFieldNames = spec.fields().stream()
.map(PartitionField::name)
.toList();
return specFieldNames.equals(fieldNames);
})
- .findFirst() // Supposed to be only one matching spec
- .orElseThrow(() -> new HiveException("No matching partition spec found for partition path: " + partitionPath));
+ .toList();
+
+ if (matches.size() > 1) {
+ throw new HiveException(String.format(
+ "Ambiguous partition spec for partition path %s: matched spec ids %s",
+ partitionPath,
+ matches.stream().map(PartitionSpec::specId).map(String::valueOf).collect(Collectors.joining(", "))));
+ }
Review Comment:
This is only an error message, no code depends on it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29808: Iceberg: Add guardrails to compaction with schema evolution [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6690:
URL: https://github.com/apache/hive/pull/6690#issuecomment-5270361616
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6690) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6690&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6690&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6690&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6690&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6690&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6690)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org