Skip to content

fix(metadata): handle empty catalog filters - #301

Merged
vuanhphung merged 6 commits into
mainfrom
vu-phung/empty-catalog-metadata
Aug 27, 2026
Merged

vuanhphung merged 6 commits into
mainfrom
vu-phung/empty-catalog-metadata

Conversation

@vuanhphung

Copy link
Copy Markdown
Collaborator

Treat empty catalog strings passed to list_schemas and list_columns as empty metadata patterns, returning typed empty results without a wire call. Non-empty catalog names remain exact identifiers, and the C ABI's existing empty-as-unset behavior is unchanged.

This supports databricks/databricks-sql-python#933 without weakening identifier validation globally.

Validated with the full Rust, PyO3, and N-API test suites, plus clippy and formatting checks.


This PR was created with GitHub MCP.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Looks good — the empty-catalog → empty-pattern routing is consistent with the existing LikePattern::new("") "match nothing" convention (src/metadata_v0.rs:237-262), the short-circuits sit before any wire call, and the change is well-covered by unit, wiremock, and pyo3 tests. One low note: the helper discards (and no longer validates) the supplied pattern in the empty-catalog branch.

Comment thread src/metadata_v0.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Looks good — clean, well-tested fix. Empty catalogs are mapped to an empty pattern that short-circuits to a typed empty result before any wire call, which is correct (empty LIKE matches nothing, matching JDBC parity) and consistent with the existing list_tables empty-pattern handling. Lifetimes, resource lifecycle, and error paths all check out; one minor test-coverage note for the napi binding is inline.

Comment thread napi/src/metadata.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Looks good — clean, well-scoped fix. Empty catalog is correctly encoded onto the schema-pattern dimension via exact_catalog_and_pattern, and the empty-pattern short-circuit is correctly placed before any wire call in both list_schemas and list_columns (the helper doc comment explicitly documents this ordering invariant). Schema constants (GET_SCHEMAS_SCHEMA/GET_COLUMNS_SCHEMA) and EmptyReader all exist and match the tests. One low-severity coverage note inline about the untested table/column empty-pattern branches.

Comment thread src/metadata_v0.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 2 Low

Looks good — a clean, well-tested change. Empty catalog is routed to an empty LikePattern that the kernel short-circuits before any wire call, consistent with the existing list_tables empty-catalog semantics, and covered by wiremock + unit tests across all three surfaces. Two low-severity notes: a #[cfg(test)] runtime-handle divergence in the napi binding that leaves the production get_handle() path unexercised by these tests, and relaxed pattern validation when the catalog is empty.

Comment thread napi/src/metadata.rs
// that global and race the cold-cache runtime test.
#[cfg(not(test))]
let handle = crate::runtime::get_handle().clone();
#[cfg(test)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — The run_on_blocking handle acquisition now diverges between build profiles: production uses crate::runtime::get_handle(), but #[cfg(test)] builds use tokio::runtime::Handle::current(). This is a reasonable way to keep the new in-crate wiremock test from mutating/racing the process-global runtime cache, but it means the napi crate's own tests (including the new empty_catalog_metadata_calls_return_empty_without_statement_request) never exercise the production get_handle() path. A regression in the global-handle capture would not be caught by these tests. The tradeoff is documented in the comment, so this is only a coverage note — consider a separate test that specifically covers the get_handle() path if it isn't covered elsewhere.

Comment thread src/metadata_v0.rs
/// to match nothing rather than fail validation. Encode that case as an empty
/// [`LikePattern`] on the accompanying pattern dimension; metadata methods
/// short-circuit empty patterns to a typed empty result before any wire call.
pub fn exact_catalog_and_pattern<'a>(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — When catalog == Some(""), exact_catalog_and_pattern returns early with (None, Some(LikePattern::new(""))) and never validates the caller-supplied pattern. Previously (LikePattern::from_opt(&schema_pattern)?) a whitespace-only / NUL / oversized schema pattern paired with an empty catalog would surface as InvalidArgument; now it is silently accepted and the call returns an empty result. This is arguably fine since an empty catalog matches nothing regardless of the pattern, but it is a behavior change in input validation strictness worth being intentional about. No action needed if the relaxed validation is the intent (the empty-catalog result is empty either way).

This branch was previously deployed

1 inactive deployment
azure-prod — eb44537f Deployed Aug 27, 2026 by oss-reviewer-bot[bot] via followup #1135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant