Repository navigation
fix(sql): make namespace_exists prefix check case-sensitive - #4168
Shahzeb-DataEngineer wants to merge 4 commits into
Conversation
SQLite evaluates LIKE case-insensitively for ASCII, so namespace_exists reported e.g. "SALES" as existing when only "sales.eu" was stored, while the exact-match lookups and PostgreSQL disagreed. Replace the LIKE prefix check with a substr prefix comparison, which is case-sensitive on both backends, and add a regression test. Signed-off-by: Shahzeb Ali <126076773+Shahzeb-DataEngineer@users.noreply.github.com>
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
|
Hi @FokkoDriesprong, just checking in on this one. It is still ready for review whenever you have a moment, and I am happy to rebase if needed. Thanks! |
Thanks for the patience, @Shahzeb-DataEngineer. I took a look, and I think one thing needs to change before this can go in.
SQL Server only has One more thing: on MySQL/MariaDB (and SQL Server) with their default Could we keep a filter that works on every backend in SQL, either the escaped |
Signed-off-by: Shahzeb Ali <126076773+Shahzeb-DataEngineer@users.noreply.github.com>
|
Hi @Fokko, thanks for the review. I reworked namespace_exists along the lines you suggested: the SQL filter now keeps only the escaped LIKE prefix match, with no func.substr, and fetches only the namespace column. The exact case-sensitive prefix check happens in Python on the returned rows, for both the tables query and the namespace-properties query. This also fixes the SQL Server breakage, since no substr is emitted anymore. All checks are green on the latest head. Let me know if anything else needs changing. |
Description
SqlCatalog.namespace_existsused aLIKEprefix check to detect parent namespaces. SQLite evaluatesLIKEcase-insensitively for ASCII, so with onlysales.eustored,namespace_exists("SALES")returnedTrue, while the exact-match lookups in the same catalog and PostgreSQL (whereLIKEis case-sensitive) said otherwise. That inconsistency leaked intocreate_table,create_namespace, andload_namespace_properties, which all go throughnamespace_exists.This PR replaces the
LIKEprefix check with asubstrprefix comparison, which is case-sensitive on both SQLite and PostgreSQL, in both the tables and the namespace-properties queries. It also removes the need for theLIKEpattern escaping.list_namespacesis unchanged: it already filters fuzzy matches in Python with exact tuple equality.Related Issue
Closes #4163
Testing
namespace_exists("SALES")wasTrue,create_namespace("SALES")raisedNamespaceAlreadyExistsError) and verified all of it is fixed after.test_namespace_exists_is_case_sensitiveintests/catalog/test_sql.py, plus edge cases verified manually (namespaces containing%/_no longer risk pattern-matching surprises).tests/catalog/test_sql.py: 25 passed.ruff checkandruff format --checkclean on both touched files.