Repository navigation
Read the metadata before inserting the row in SqlCatalog.register_table - #4540
Open
rahulsmahadev wants to merge 1 commit into
Open
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
register_table committed the table row before load_table read the metadata file, so a missing or invalid file left the table registered: list_tables showed it, table_exists raised and the name could not be registered again. Check the name, read the metadata, then insert the row, as Java's registerTable does. Co-authored-by: Isaac <no-reply@databricks.com>
Contributor
Author
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
Bug:
SqlCatalog.register_tableinserts and commits the table row, then callsload_table, which reads the metadata file in_convert_orm_to_iceberg. When the file is missing or is not table metadata,register_tableraises, but the row stays. On main, with a fresh catalog:The name stays taken until
drop_tableremoves the row.InMemoryCatalogextendsSqlCatalog, so it has the same problem.Fix: check the name, read the metadata, then insert the row. Java's REST handler and Spark
register_tableprocedure pass an existing metadata-file location (from a table write or rewrite/copy) throughBaseMetastoreCatalog.registerTableto the JDBC insert; this PR changes the SQL registration step to use the same read-before-insert order. Unlike thetableExistscall in Java'sregisterTable, the name check is a primary-key lookup that does not load the existing table and also matches view rows, so an existing name still raisesTableAlreadyExistsErrorbefore the file is read, as on main. Concurrent inserts still translateIntegrityErrortoTableAlreadyExistsError.register_tablereturns the metadata read before the insert instead of reloading it afterward, so no read can fail after the row is committed.The Glue and Hive catalogs also read the file before they create the table.
Are these changes tested?
Yes. Two new tests fail on main and pass with this change:
test_register_table_with_unreadable_metadataintests/catalog/test_catalog_behaviors.pytries to register a missing file and a{}file, and checks that the table is not listed,table_existsreturnsFalseand the name can then be registered with a valid file. It runs on the in-memory and both SQL catalog fixtures, fails on main at the missing-filetable_existscheck withFileNotFoundErrorand passes with this change. It also checks that an existing name with a missing file still raisesTableAlreadyExistsError.test_register_table_on_v0_schemaintests/catalog/test_sql.pyregisters a missing file and then a valid one on the legacy schema; on main,list_tablesstill shows the table after the missing file.Two guards in
tests/catalog/test_sql.pyalso pass on main, and keep what the name check and the insert must preserve:test_register_table_rejects_view_and_unreadable_table_rows: registering the name of a view row, or of a table whose metadata file was removed, with a missing file raisesTableAlreadyExistsErrorand leaves both rows unchanged. It fails if the name check usestable_exists.test_register_table_concurrent_integrity_error: a registration that loses the race for the name raisesTableAlreadyExistsError, and the winner stays loadable. It fails if the insert stops translatingIntegrityError.Are there any user-facing changes?
Yes, when
register_tablecannot read the metadata,SqlCatalogandInMemoryCatalogno longer keep the table. Rows that earlier versions left behind stay untildrop_tableremoves them.Please add the
changeloglabel.This pull request and its description were written by Isaac.