SQL Catalog: Filter on iceberg_type in commit_table (#3337) - #3846
Open
hedger9487 wants to merge 1 commit into
Open
SQL Catalog: Filter on iceberg_type in commit_table (#3337)#3846hedger9487 wants to merge 1 commit into
hedger9487 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes SqlCatalog.commit_table so it consistently filters SQL catalog rows by iceberg_type (matching TABLE or NULL), preventing accidental operations on VIEW rows created by other Iceberg implementations.
Changes:
- Apply
self._iceberg_type_filter()to thecommit_tableUPDATE statement (rowcount-based path) and theSELECT ... FOR UPDATEquery (fallback path) inpyiceberg/catalog/sql.py. - Add a regression unit test ensuring commits fail (and do not modify the row) when the underlying row has
iceberg_type='VIEW'.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pyiceberg/catalog/sql.py | Adds the iceberg_type predicate to commit_table’s update/locking queries to avoid touching VIEW rows. |
| tests/catalog/test_sql.py | Adds a unit test covering the commit_table behavior when the backing row is tampered into a VIEW. |
Suppressed comments (1)
tests/catalog/test_sql.py:413
- The assertion query filters only on table_name, which can become ambiguous if additional rows with the same name exist (e.g., different namespaces). Include catalog_name and table_namespace in the WHERE clause to ensure the test checks the intended row.
with catalog.engine.connect() as conn:
row = conn.execute(text("SELECT iceberg_type FROM iceberg_tables WHERE table_name = 'a_view'")).fetchone()
assert row is not None
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+400
to
+403
| # Tamper the table row into a VIEW (simulating external writer) | ||
| with catalog.engine.connect() as conn: | ||
| conn.execute(text("UPDATE iceberg_tables SET iceberg_type = 'VIEW' WHERE table_name = 'a_view'")) | ||
| conn.commit() |
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.
Description
Fixes #3337.
In
SqlCatalog,_iceberg_type_filter()was added in #3263 to filter oniceberg_type(matchingTABLEorNULL) and avoid operating onVIEWrows written by other Iceberg implementations (e.g., Java or Rust). Whileload_table,drop_table,rename_table, andlist_tablesincorporate this filter,commit_tableomittedtype_filterin its SQL update statement.This PR applies
type_filter = self._iceberg_type_filter()to thecommit_tableupdate query inpyiceberg/catalog/sql.py.Testing
test_commit_table_ignores_view_rowsintests/catalog/test_sql.py.