Skip to content

[SEA] Fix list_schemas to return empty rowset instead of throwing on non-matching catalog patterns (PECO-3017)#443

Open
eric-wang-1990 wants to merge 1 commit into
mainfrom
fix/peco-3017-sea-list-schemas-patterns
Open

[SEA] Fix list_schemas to return empty rowset instead of throwing on non-matching catalog patterns (PECO-3017)#443
eric-wang-1990 wants to merge 1 commit into
mainfrom
fix/peco-3017-sea-list-schemas-patterns

Conversation

@eric-wang-1990

Copy link
Copy Markdown
Collaborator

Summary

  • SEA's GetObjects(depth=DbSchemas) threw DatabricksException for any catalog argument that was not an exact-match against an existing catalog name, instead of returning an empty rowset.
  • Affected inputs: %, compar%, comparator\_tests, "", "nonexistent". Additionally comparator_tests (unescaped _) returned empty instead of matching via wildcard semantics.
  • Root cause: GetSchemasAsync() passed the catalog pattern verbatim as a backtick-quoted SQL identifier, generating invalid SQL (e.g. SHOW SCHEMAS IN \%``) that the server rejected.
  • Fix: GetSchemasAsync() now classifies the catalog pattern and routes accordingly:
    1. nullSHOW SCHEMAS IN ALL CATALOGS (unchanged)
    2. Empty string → return empty rowset immediately
    3. Contains unescaped % or _SHOW SCHEMAS IN ALL CATALOGS then filter rows client-side using a regex built from the ADBC pattern
    4. Literal name (with possible \_/\% escapes) → decode escapes, execute SHOW SCHEMAS IN \catalog`, catch AdbcException` and return empty rowset for nonexistent catalogs

Test plan

  • 29 unit tests added in GetSchemasAsyncTests.cs covering all six bug-report scenarios and helper methods
  • dotnet build passes — 0 errors
  • All 746 unit tests pass

Fixes PECO-3017

🤖 Generated with Claude Code

Previously, GetSchemasAsync passed the catalogPattern argument directly to
ShowSchemasCommand as a literal backtick-quoted identifier. This caused
server errors for any pattern that wasn't an exact existing catalog name:
- "%" → SHOW SCHEMAS IN `%` (invalid)
- "compar%" → SHOW SCHEMAS IN `compar%` (invalid)
- "comparator\_tests" → SHOW SCHEMAS IN `comparator\_tests` (wrong catalog)
- "" (empty string) → SHOW SCHEMAS IN `` (invalid)
- "nonexistent" → server error if catalog doesn't exist

Fix: classify the catalogPattern and route accordingly:
- null → SHOW SCHEMAS IN ALL CATALOGS (unchanged)
- "" → return empty rowset immediately
- pattern with unescaped % or _ → SHOW SCHEMAS IN ALL CATALOGS, filter
  rows by catalog regex built from the ADBC pattern (client-side)
- literal name (may contain \_ or \% escapes) → decode escapes, try
  SHOW SCHEMAS IN `catalog`, catch AdbcException → return empty rowset

Three new internal static helpers power the fix:
- ContainsUnescapedWildcard: detects % or _ not preceded by backslash
- CatalogPatternToRegex: converts ADBC/SQL pattern to a case-insensitive
  Regex, mapping % → .*, _ → ., \_ → _, \% → %, \\ → \
- DecodeLiteralPattern: strips ADBC escape sequences from literal patterns

Add 29 unit tests in GetSchemasAsyncTests covering all six bug-report
cases plus edge cases for each helper.

Signed-off-by: Eric Wang <e.wang@databricks.com>
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.

1 participant