Repository navigation
Add update_partition_statistics() to Table and Transaction - #4397
Open
rahulsmahadev wants to merge 1 commit into
Open
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
Add an UpdatePartitionStatistics builder with set_partition_statistics() and remove_partition_statistics(), so callers no longer build update objects by hand. Sets apply before removals and absent removals are no-ops, as in Java. The RemovePartitionStatisticsUpdate handler therefore no longer raises. Co-authored-by: Isaac <no-reply@databricks.com>
Contributor
Author
|
@rambleraptor, this adds Table and Transaction builders for the partition-statistics updates you introduced in #2192. Could you take a look at the API, and at the missing-file and operation-order semantics, when you have a chance? |
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.
Rationale for this change
PyIceberg already models partition statistics in the table metadata:
PartitionStatisticsFile,TableMetadata.partition_statistics, and theSetPartitionStatisticsUpdateandRemovePartitionStatisticsUpdatetable updates (#2192). Table and Transaction have no builder for these updates; callers currently need to construct the update objects and commit them through the catalog API.Java has this API.
Table.updatePartitionStatistics()andTransaction.updatePartitionStatistics()return anUpdatePartitionStatisticswithsetPartitionStatistics(file)andremovePartitionStatistics(snapshotId)(api/src/main/java/org/apache/iceberg/UpdatePartitionStatistics.java,core/src/main/java/org/apache/iceberg/SetPartitionStatistics.java).This PR adds the same API to PyIceberg:
Table.update_partition_statistics()andTransaction.update_partition_statistics(), next toupdate_statistics().UpdatePartitionStatisticsinpyiceberg/table/update/partition_statistics.py, modelled onUpdateStatistics. Pending operations are applied on commit, for chained andwithblock operations alike, with sets applied before removals as in Java.set_partition_statistics(file)replaces the file already set for the same snapshot.Noneis a no-op, as in Java.remove_partition_statistics(snapshot_id)uses the existingRemovePartitionStatisticsUpdate.Related open PRs: #4087 fixes
UpdateStatistics.remove_statistics, which replaces the pending operations instead of appending to them. This PR does not copy that pattern. #4364 removes partition statistics when their snapshots are removed. This PR changes only theRemovePartitionStatisticsUpdatehandler inpyiceberg/table/update/__init__.py, a different part of that file from the snapshot removal handler that #4364 changes, and does not touch the snapshot expiry code. #4364 only removes entries that exist, so the no-op change does not affect its path.Are these changes tested?
Yes. Five tests in
tests/table/test_statistics.pyuse thecatalogfixture (in-memory and SQL catalogs) and go through the public API:test_update_partition_statistics: set, replace the file for the same snapshot, set in awithblock, remove, and reload the table from the catalog.test_update_partition_statistics_set_and_remove_in_one_update: operations on different snapshots are both applied. On the same snapshot the removal wins in either call order, with or without an existing file. Repeated sets keep the last file, and repeated removals are no-ops.test_update_partition_statistics_in_transaction: pending changes are visible intransaction.table_metadata, but not intable.metadataor a catalog reload, until the transaction commits. An exception rolls them back.test_remove_partition_statistics_without_file_is_noop: removing a snapshot without a file, once or repeated, commits and leaves the metadata unchanged.test_set_partition_statistics_none_is_noop:set_partition_statistics(None)changes nothing.The low-level handler is covered by
test_remove_partition_statistics_update_without_file_is_noopintests/table/test_init.py.All five tests fail on main with
AttributeError: the transaction test reports thatTransactionhas noupdate_partition_statisticsattribute, and the other four report the missing attribute onTable. All five pass with this change. The low-level test intests/table/test_init.pyfails on main withValueErrorand passes with this change. I also checked that a copy of theUpdateStatisticspattern, where removal discards the pending sets, fails the set-and-remove test.Are there any user-facing changes?
Yes. New methods
Table.update_partition_statistics()andTransaction.update_partition_statistics(), and a newUpdatePartitionStatisticsclass. The docs are inmkdocs/docs/api.md. Two behaviours follow Java:RemovePartitionStatisticsUpdatehandler, which previously raisedValueError.Please add the
changeloglabel.This pull request and its description were written by Isaac.