Skip to content

Commit 765a95b

Browse files
committed
refactor(kernel): simplify metadata filter forwarding
1 parent 74d883f commit 765a95b

5 files changed

Lines changed: 16 additions & 40 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Release History
22

33
# Unreleased
4-
- Kernel metadata filters now preserve empty strings as empty patterns, matching no catalogs, schemas, tables, or columns. Only `None` leaves a filter unset; `%` and `*` retain their existing wildcard behavior (PECOBLR-4221).
4+
- Kernel metadata filters now preserve empty strings, matching no catalogs, schemas, tables, or columns. Only `None` leaves a filter unset; other values retain their exact-identifier or pattern semantics (PECOBLR-4221).
55
- Kernel backend (`use_kernel=True`): OAuth **M2M with a JWT private-key client assertion** (RFC 7523) is now supported. Pass `oauth_client_id` + `oauth_jwt_key_file` + `oauth_jwt_kid` (with optional `oauth_jwt_passphrase` for an encrypted PKCS#8 key, `oauth_jwt_algorithm` defaulting to `RS256`, `oauth_scopes`, and `token_url` for the IdP token endpoint) and the connector routes them to the kernel's `auth_type="oauth-m2m-jwt"`, which signs a short-lived assertion with the private key instead of sending a client secret. The kernel owns the token lifecycle. A private-key file is treated as unambiguous JWT M2M intent and is mutually exclusive with `oauth_client_secret` / `credentials_provider` (both raise `NotSupportedError`). Verified end-to-end against an Azure Databricks workspace with the service principal's public certificate registered on its Entra ID app registration. Requires `databricks-sql-kernel >= 0.2.0` with JWT support.
66
- Kernel backend (`use_kernel=True`): OAuth U2M with `auth_type="databricks-oauth"` now forwards the connector's `databricks-sql-python` OAuth-app bundle (`client_id` + `sql offline_access` scopes + redirect port) into the kernel, so a bare U2M connection authenticates as `databricks-sql-python` — parity with the Thrift path — instead of inheriting the kernel's own `databricks-sql-connector` default. A caller-supplied `oauth_client_id` (with its coupled `oauth_redirect_port`) is honored, as is a caller-supplied `oauth_scopes`; absent one, the connector default (`sql offline_access`) is forwarded. Note: the kernel binds a single U2M redirect port, so unlike the Thrift path (which tries the full `8020..8024` range) the kernel path uses only one port and does not fall back to the next port if it is already bound — pass `oauth_redirect_port` (with `oauth_client_id`) to pick a free one on a port collision (PECOBLR-4040)
77
- Kernel backend (`use_kernel=True`): **Azure Entra (Azure AD) service-principal M2M is now supported.** `auth_type="azure-sp-m2m"` forwards `azure_client_id` / `azure_client_secret`; the kernel is the Azure-aware auth core — it builds the Entra v2.0 token endpoint and the `{app_id}/.default` scope, and **auto-discovers the tenant** from the workspace's `/aad/auth` redirect when `azure_tenant_id` is omitted (matching Thrift). The `Authorization` bearer is the Databricks-audience data token, which alone authenticates a workspace-member SP. Set `azure_workspace_resource_id` and the kernel also sends the Azure SP management token (`X-Databricks-Azure-SP-Management-Token`) + `X-Databricks-Azure-Workspace-Resource-Id` header (matching the JDBC driver), so a service principal with an Azure RBAC role but no workspace membership can authenticate; omit it and no ARM management-scope token is fetched. Azure AD **U2M** (`auth_type="azure-oauth"`) now routes to the kernel's OAuth U2M flow, identically to `auth_type="databricks-oauth"`: the kernel runs the in-house workspace-federated browser flow, which Azure workspaces support (the workspace federates login to Entra). It forwards the connector's `databricks-sql-python` OAuth app, not the Thrift Azure app (`96eecda7` / port 8030), which is registered for Thrift's direct-Entra flow the kernel does not perform (PECOBLR-4141; PECOBLR-4120)

src/databricks/sql/backend/databricks_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def get_schemas(
248248
max_rows: Maximum number of rows to fetch in a single batch
249249
max_bytes: Maximum number of bytes to fetch in a single batch
250250
cursor: The cursor object that will handle the results
251-
catalog_name: Optional catalog name pattern to filter by. ``None``
251+
catalog_name: Optional exact catalog name to filter by. ``None``
252252
leaves the filter unset; an empty string matches nothing.
253253
schema_name: Optional schema name pattern to filter by. ``None``
254254
leaves the filter unset; an empty string matches nothing.
@@ -327,7 +327,7 @@ def get_columns(
327327
max_rows: Maximum number of rows to fetch in a single batch
328328
max_bytes: Maximum number of bytes to fetch in a single batch
329329
cursor: The cursor object that will handle the results
330-
catalog_name: Optional catalog name pattern to filter by. ``None``
330+
catalog_name: Optional exact catalog name to filter by. ``None``
331331
leaves the filter unset; an empty string matches nothing.
332332
schema_name: Optional schema name pattern to filter by. ``None``
333333
leaves the filter unset; an empty string matches nothing.

src/databricks/sql/backend/kernel/client.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,36 +117,13 @@ def _is_not_found(exc: BaseException) -> bool:
117117
)
118118

119119

120-
def _catalog_or_none(value: Optional[str]) -> Optional[str]:
121-
"""Map all-catalog wildcards to the kernel's unfiltered representation.
122-
123-
This makes ``columns(catalog='%')`` behave like
124-
``tables(catalog='%')`` / ``schemas(catalog='%')`` — the kernel
125-
treats the catalog as an exact identifier for SHOW COLUMNS. ``None``
126-
remains the only absent filter. Other strings must be preserved as real
127-
filters; in particular, an empty string matches nothing just as it does
128-
on the Thrift backend. Non-empty whitespace-only strings remain invalid
129-
and are left for kernel validation.
130-
"""
131-
if value is None or value in ("%", "*"):
132-
return None
133-
return value
134-
135-
136120
def _exact_catalog_and_pattern(
137121
catalog: Optional[str], pattern: Optional[str]
138122
) -> Tuple[Optional[str], Optional[str]]:
139-
"""Adapt an empty exact catalog to an empty subordinate pattern.
140-
141-
At ``KERNEL_REV``, ``Identifier("")`` is invalid while
142-
``LikePattern("")`` means match-nothing. Schema and column metadata
143-
take an exact catalog, so represent an empty catalog as all catalogs
144-
constrained by an empty schema pattern. This preserves empty-catalog
145-
semantics without passing an invalid identifier to the kernel.
146-
"""
123+
"""Avoid constructing the kernel's invalid empty ``Identifier``."""
147124
if catalog == "":
148125
return None, ""
149-
return _catalog_or_none(catalog), pattern
126+
return catalog, pattern
150127

151128

152129
def _is_staging_statement(operation: str) -> bool:
@@ -966,7 +943,7 @@ def get_tables(
966943
# do the work — no connector-side drain + refilter. Passing it
967944
# through preserves streaming for large schemas.
968945
stream = self._kernel_session.metadata().list_tables(
969-
catalog=_catalog_or_none(catalog_name),
946+
catalog=catalog_name,
970947
schema_pattern=schema_name,
971948
table_pattern=table_name,
972949
table_types=table_types if table_types else None,

src/databricks/sql/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,8 +1577,8 @@ def schemas(
15771577
"""
15781578
Get schemas corresponding to the catalog_name and schema_name.
15791579
1580-
``None`` leaves a filter unset. An empty string is a real empty
1581-
pattern and matches nothing. Names can contain % wildcards.
1580+
``None`` leaves a filter unset and an empty string matches nothing.
1581+
``catalog_name`` is exact; ``schema_name`` can contain % wildcards.
15821582
:returns self
15831583
"""
15841584
self._check_not_closed()
@@ -1604,8 +1604,8 @@ def tables(
16041604
"""
16051605
Get tables corresponding to the catalog_name, schema_name and table_name.
16061606
1607-
``None`` leaves a filter unset. An empty string is a real empty
1608-
pattern and matches nothing. Names can contain % wildcards.
1607+
``None`` leaves a filter unset and an empty string matches nothing.
1608+
Names can contain % wildcards.
16091609
:returns self
16101610
"""
16111611
self._check_not_closed()
@@ -1634,8 +1634,8 @@ def columns(
16341634
"""
16351635
Get columns corresponding to the catalog_name, schema_name, table_name and column_name.
16361636
1637-
``None`` leaves a filter unset. An empty string is a real empty
1638-
pattern and matches nothing. Names can contain % wildcards.
1637+
``None`` leaves a filter unset and an empty string matches nothing.
1638+
``catalog_name`` is exact; other names can contain % wildcards.
16391639
16401640
``catalog_name=None`` is accepted on all backends and matches
16411641
columns across every catalog (the kernel issues ``SHOW COLUMNS``

tests/unit/test_kernel_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,9 +1564,8 @@ def test_sync_execute_leaves_rowcount_default_when_num_modified_rows_none():
15641564
# ---------------------------------------------------------------------------
15651565

15661566

1567-
@pytest.mark.parametrize("wildcard", ["%", "*"])
1568-
def test_get_columns_normalizes_wildcard_catalog_to_none(wildcard):
1569-
"""The kernel represents the supported all-catalog wildcards as ``None``."""
1567+
@pytest.mark.parametrize("exact_catalog", ["%", "*"])
1568+
def test_get_columns_preserves_exact_catalog(exact_catalog):
15701569
c = _make_client()
15711570
c._kernel_session = MagicMock()
15721571
list_columns = c._kernel_session.metadata.return_value.list_columns
@@ -1580,14 +1579,14 @@ def test_get_columns_normalizes_wildcard_catalog_to_none(wildcard):
15801579
max_rows=1,
15811580
max_bytes=1,
15821581
cursor=cursor,
1583-
catalog_name=wildcard,
1582+
catalog_name=exact_catalog,
15841583
schema_name="s",
15851584
table_name="t",
15861585
column_name="c",
15871586
)
15881587

15891588
list_columns.assert_called_once_with(
1590-
catalog=None,
1589+
catalog=exact_catalog,
15911590
schema_pattern="s",
15921591
table_pattern="t",
15931592
column_pattern="c",

0 commit comments

Comments
 (0)