Repository navigation
fix(sql): make namespace_exists prefix check case-sensitive - #4168
Open
Shahzeb-DataEngineer wants to merge 1 commit into
Open
Shahzeb-DataEngineer wants to merge 1 commit into
Shahzeb-DataEngineer wants to merge 1 commit 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 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.
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.