Repository navigation
Conversation
deniskuzZ
force-pushed
the
HIVE-30253
branch
from
November 26, 2026 12:18
17b5c36 to
c6dbb5a
Compare
…ed=false are sorted, but always written by the fanout writer - the V2 position delete writer follows the data writer's rule: ClusteredPositionDeleteWriter unless the fanout writer is used (Context.useFanoutWriter), so with fanout disabled the deletes the rewrite sorts by spec, partition key, file and position are streamed - before, the clustered writer needed input marked sorted by the sorted dynamic partition optimization, which never applies to a merge-on-read delete (no DynamicPartitionCtx, HIVE-26156): since HIVE-28510 every such statement sorted, then wrote with FanoutPositionOnlyDeleteWriter - needs the exact PARTITION__KEY sort of HIVE-30113: the clustered writer takes each partition once - iceberg_v2_deletes_fanout_disabled.q: EXPLAIN and rows of the DELETE, the split UPDATE and the MERGE; partitions (1, 31) and (2, 0), which PARTITION__HASH mapped alike, with interleaved object storage paths
|
This branch has not been deployed
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.



Depends on #6925 (HIVE-30113): the clustered writer needs its exact
PARTITION__KEYsort. Until it is merged this branch carries its commits; the change of this PR is the last commit.What changes were proposed in this pull request?
HiveIcebergWriterBase.newDeleteWriterpicks the position delete writer of a V2 table by the same rule as the datawriter:
ClusteredPositionDeleteWriterwhen fanout is disabled (!Context.useFanoutWriter()),FanoutPositionOnlyDeleteWriterotherwise. Before, it built the clustered writer only when the input was marked sortedby the sorted dynamic partition optimization, which a merge-on-read delete never is.
WriterBuilder.Context.inputOrdered()is removed:nothing reads it now (the flag still feeds
useFanoutWriter).With
write.fanout.enabled=false, a merge-on-read DELETE, split UPDATE or MERGE on a V2 table sorts its deleted recordsby
PARTITION__SPEC__ID,PARTITION__KEY,FILE__PATH,ROW__POSITION(HiveIcebergStorageHandler.acidSortColumns,since HIVE-28510) so that the clustered writer can stream them. But
HiveIcebergStorageHandler.createDPContextreturnsno dynamic partition context for a merge-on-read delete (HIVE-26156: the rewrite's sort already clusters the records;
since HIVE-30112
SemanticAnalyzerskips it instead), soFileSinkOperatornever marks the write sorted, andHIVE-28510's
inputOrdered ? clustered : fanoutalways took the fanout writer. Every such statement paid for the sort andwrote with
FanoutPositionOnlyDeleteWriter. The data writer does not have this gap: it already uses the clustered writerwhenever fanout is disabled, with the sort that the SerDe forces through the dynamic partition threshold.
Why are the changes needed?
write.fanout.enabled=falseasks for writers that take clustered input and keep one partition open at a time. Sparkhonours it the same way for position deletes: with fanout disabled its position-delta writes are ordered by
(_spec_id, _partition, _file, _pos)(SparkWriteUtil), with fanout enabled they are not sorted.The clustered writer takes each (spec, partition) once and throws if one comes back, so the sort has to cluster the
partitions exactly.
PARTITION__KEY(HIVE-30113, the serialized partition values) does; the formerPARTITION__HASH(
Objects.hashof the values) could give two partitions one key and interleave them by file path. Hence the base.Both sides read
write.fanout.enabledfrom the table: the rewrite from the metastore parameters, the writer from theIceberg table properties, the same pairing the data writer relies on.
Data and delete writers now take the same rule (
!useFanoutWriter()= sorted input or fanout disabled), with onedifference in where sorted input comes from: data writes are sorted either for
write.fanout.enabled=false(the SerDeforces the threshold to 1) or by the sorted dynamic partition optimization's own decision
(
hive.optimize.sort.dynamic.partition.threshold: 1 always, N above N writers, 0 by the NDV-estimated partition count,HIVE-25948). Merge-on-read deletes are sorted by the rewrite, at parse time and before any statistics, and only for
write.fanout.enabled=false, so they follow the property alone, as Spark does. A statistics-based choice for deleteswould move their sort into the optimizer; the max-writers estimate prices ORC stripe buffers, while a position delete
writer holds a bitmap per data file.
Does this PR introduce any user-facing change?
No. With
write.fanout.enabled=false, V2 merge-on-read DML now writes with the clustered position delete writer, as theproperty asks. Plans and rows are unchanged.
How was this patch tested?
iceberg_v2_deletes_fanout_disabled.q(TestIcebergCliDriver): EXPLAIN of the DELETE, the split UPDATE and the MERGE(the delete sink behind the
++++sort) and the rows after each; a table partitioned on two int columns withpartitions (1, 31) and (2, 0), which
Objects.hashmaps alike, and object storage paths that interleave their files:rows after a DELETE in both partitions as expected.
ROW__POSITION(mutation, on this change), the DELETE fails withClusteredWriter's "Incoming records violate the writer assumption that records are clustered by spec and bypartition within each spec"; the fanout writer accepts any order. (EXPLAIN does not show the writer.)
iceberg_dml_deleted_record_columns,delete_iceberg_partitioned_{orc,parquet},update_iceberg_partitioned_parquet,merge_iceberg_{orc,partitioned_orc},vectorized_iceberg_merge_mixed,write_iceberg_branch,dynamic_partition_writes,ctas_iceberg_partitioned_orc,iceberg_v3_dml_distribution.PARTITION__KEYand Iceberg's comparator differ only for float/double identitypartition values that are NaN with different payloads.