Skip to content

fix(metadata): resolve missing primary-key catalog and schema - #379

Merged
vuanhphung merged 4 commits into
mainfrom
fix/primary-keys-null-empty-namespace
Oct 5, 2026
Merged

vuanhphung merged 4 commits into
mainfrom
fix/primary-keys-null-empty-namespace

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Rebased onto main, reusing the upstream Identifier::new_allow_empty from #373. Resolve missing primary-key catalog and schema independently from the current session, preserve explicit empty names, accept nullable NAPI arguments, and retain strict table-name validation.

Tested: 1,181 kernel tests and 84 NAPI tests passed; 63 kernel tests ignored. Formatting and Clippy passed. The rebuilt native binding passed all 16 JavaScript null/undefined/empty/explicit namespace combinations against a localhost mock.

Companion Node driver PR: databricks/databricks-sql-nodejs#537. The Node change remains draft until an updated native kernel package is available.

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: 2 Low

Looks good — a clean, well-tested change that makes primary_keys resolve a missing catalog/schema from the session, with solid wiremock + napi coverage for the null/empty/explicit matrix and lookup-failure propagation. Two low-severity notes: (1) when an explicit non-current catalog is paired with an omitted schema, the resolved current schema may belong to a different catalog; (2) the kernel contract change silently alters the C-ABI null-catalog behavior (now resolves instead of InvalidArgument) without doc/test updates, and leaves pyo3 unable to use the feature.

Comment thread src/metadata_v0.rs Resolved
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 — a clean, well-tested fix that makes primary_keys resolve a missing catalog/schema from the session (via a new current_catalog_and_schema helper mirroring the existing current_catalog), preserves explicit empty names through Identifier::new_allow_empty, and relaxes the NAPI args to nullable. Error propagation, statement close-on-error, and the telemetry test migration to foreign_keys all check out; one low-severity note on mixed explicit-catalog/resolved-schema pairing is inline.

Comment thread src/metadata_v0.rs
let schema = schema.ok_or_else(|| {
Error::invalid_argument().message("primary_keys requires a schema identifier")
})?;
let (current_catalog, current_schema) = if catalog.is_none() || schema.is_none() {

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 exactly one of catalog/schema is supplied and the other is None, the omitted dimension is filled from the session's current namespace independently of the supplied dimension. For primary_keys(Some("other_cat"), None, table) this pairs the explicit catalog other_cat with the session's CURRENT_SCHEMA() — a schema name that is only meaningful inside the current catalog, not inside other_cat. The resulting SHOW KEYS IN CATALOG \other_cat` IN SCHEMA `<current_schema>` IN TABLE ...` can target a schema that doesn't exist under the explicit catalog, yielding a confusing not-found rather than the keys the caller expected.

This matches the PR's stated "resolve independently from the current session" intent and the all-None / all-explicit paths are correct, so this is a minor edge. If the mixed case is intended to be supported, consider only resolving the current schema when the catalog is also unspecified (or documenting that a partial override is not supported).

@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 — a focused, correctly-tested fix. The kernel's current_catalog_and_schema lookup and the primary_keys resolution block are sound (resources closed on all paths, errors propagated, telemetry test correctly re-pointed to foreign_keys), and the napi/C-ABI surfaces line up. One low note: pyo3's primary_keys was not updated to the new nullable/empty semantics, leaving the Python binding diverged from napi.

Other findings

  • 🔵 Low — This PR teaches the kernel's primary_keys to resolve a missing catalog/schema from the current session and to preserve explicit-empty names (via new_allow_empty), and exposes that through napi (catalog/schema now Option<String>). The pyo3 wrapper was not updated to match: catalog/schema remain required Strings converted with Identifier::new, which rejects empty strings and offers no way to pass None. As a result Python callers cannot use the new session-fallback path, and an empty-string catalog/schema that napi now accepts raises InvalidArgument from pyo3. If leaving pyo3 strict is intentional (Node-driver-only scope), this is fine to defer — flagging so the binding divergence is a conscious choice rather than an oversight.

@vuanhphung
vuanhphung added this pull request to the merge queue Oct 5, 2026
Merged via the queue into main with commit 4278294 Oct 5, 2026
23 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — d08c2df4 Deployed Oct 5, 2026 by vuanhphung via review #883
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