Skip to content

fix(sql): make namespace_exists prefix check case-sensitive - #4168

Open
Shahzeb-DataEngineer wants to merge 1 commit into
apache:mainfrom
Shahzeb-DataEngineer:fix/namespace-exists-case-sensitive
Open

Shahzeb-DataEngineer wants to merge 1 commit into
apache:mainfrom
Shahzeb-DataEngineer:fix/namespace-exists-case-sensitive

Conversation

@Shahzeb-DataEngineer

Copy link
Copy Markdown
Contributor

Description

SqlCatalog.namespace_exists used a LIKE prefix check to detect parent namespaces. SQLite evaluates LIKE case-insensitively for ASCII, so with only sales.eu stored, namespace_exists("SALES") returned True, while the exact-match lookups in the same catalog and PostgreSQL (where LIKE is case-sensitive) said otherwise. That inconsistency leaked into create_table, create_namespace, and load_namespace_properties, which all go through namespace_exists.

This PR replaces the LIKE prefix check with a substr prefix 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 the LIKE pattern escaping. list_namespaces is unchanged: it already filters fuzzy matches in Python with exact tuple equality.

Related Issue

Closes #4163

Testing

  • Reproduced the reported case on SQLite before the fix (namespace_exists("SALES") was True, create_namespace("SALES") raised NamespaceAlreadyExistsError) and verified all of it is fixed after.
  • New regression test test_namespace_exists_is_case_sensitive in tests/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 check and ruff format --check clean on both touched files.

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>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 04:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SqlCatalog: namespace_exists matches parent namespaces case-insensitively on SQLite

2 participants