Repository navigation
fix(metadata): resolve missing primary-key catalog and schema - #379
Conversation
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
5e0a568 to
da39fb0
Compare
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
There was a problem hiding this comment.
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.
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
There was a problem hiding this comment.
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.
| 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() { |
There was a problem hiding this comment.
🔵 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).
There was a problem hiding this comment.
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_keysto resolve a missing catalog/schema from the current session and to preserve explicit-empty names (vianew_allow_empty), and exposes that through napi (catalog/schemanowOption<String>). The pyo3 wrapper was not updated to match:catalog/schemaremain requiredStrings converted withIdentifier::new, which rejects empty strings and offers no way to passNone. As a result Python callers cannot use the new session-fallback path, and an empty-string catalog/schema that napi now accepts raisesInvalidArgumentfrom 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.
Rebased onto
main, reusing the upstreamIdentifier::new_allow_emptyfrom #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.