Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions napi/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,17 @@ impl Connection {
.await
}

/// Tables filtered by catalog (exact), schema (pattern), table (pattern).
/// Tables filtered by catalog (**pattern**), schema (pattern), table
/// (pattern).
///
/// The catalog is an ODBC/JDBC LIKE pattern (`%` / `_`), matching
/// Thrift `getTables`: a wildcard catalog matches multiple catalogs;
/// a literal name (or an escaped `\_` / `\%`) takes the fast exact
/// path. `undefined`/omitted catalog means "all catalogs", while an
/// **empty string** means "match nothing" (zero rows) — pass
/// `undefined`, not `""`, for all catalogs. The catalog pattern is
/// validated (whitespace-only / NUL / >255 bytes are rejected with an
/// error).
///
/// JDBC `getTables` shape: 10 columns. `tableTypes`, when provided,
/// filters rows by `TABLE_TYPE` kernel-side.
Expand All @@ -172,7 +182,7 @@ impl Connection {
let meta = take_metadata(&self.inner).await?;
guarded(async move {
let stream = run_on_blocking(move || async move {
let cat = Identifier::from_opt(&catalog)?;
let cat = LikePattern::from_opt(&catalog)?;
let sch = LikePattern::from_opt(&schema_pattern)?;
let tbl = LikePattern::from_opt(&table_pattern)?;
let types_owned: Option<Vec<&str>> = table_types
Expand Down
16 changes: 11 additions & 5 deletions pyo3/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ impl Metadata {
Ok(ResultStream::new(stream, self.runtime.clone()))
}

/// Tables filtered by catalog (exact), schema (pattern), table
/// (pattern). `table_types` is advisory — Databricks does not
/// honour it server-side; wrappers filter the returned
/// `tableType` column themselves.
/// Tables filtered by catalog (**pattern**), schema (pattern),
/// table (pattern). The catalog is an ODBC/JDBC LIKE pattern
/// (`%` / `_`), matching Thrift `getTables`; a literal catalog name
/// still works and takes the fast exact path. `catalog=None`
/// (the default) means "all catalogs", while `catalog=""` means
/// "match nothing" (zero rows) — pass `None`, not `""`, for all
/// catalogs. The catalog pattern is validated (whitespace-only / NUL
/// / >255 bytes raise `InvalidArgument`). `table_types` is advisory —
/// Databricks does not honour it server-side; wrappers filter the
/// returned `tableType` column themselves.
#[pyo3(signature = (*, catalog=None, schema_pattern=None, table_pattern=None, table_types=None))]
fn list_tables(
&self,
Expand All @@ -108,7 +114,7 @@ impl Metadata {
table_types: Option<Vec<String>>,
) -> PyResult<ResultStream> {
let stream = run_kernel_block!(py, self.runtime, {
let cat = Identifier::from_opt(&catalog)?;
let cat = LikePattern::from_opt(&catalog)?;
let sch = LikePattern::from_opt(&schema_pattern)?;
let tbl = LikePattern::from_opt(&table_pattern)?;
let types_owned: Option<Vec<&str>> = table_types
Expand Down
22 changes: 19 additions & 3 deletions src/c_abi/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,24 @@ pub unsafe extern "C" fn kernel_metadata_list_schemas(
})
}

/// List tables filtered by catalog (exact), schema / table patterns,
/// and an optional comma-separated `table_types` filter.
/// List tables filtered by catalog (**pattern**), schema / table
/// patterns, and an optional comma-separated `table_types` filter.
///
/// The catalog is an ODBC/JDBC LIKE pattern here (`%` / `_`),
/// matching Thrift's `TGetTablesReq.catalogName` and ODBC `SQLTables`
/// under the default `SQL_ATTR_METADATA_ID = SQL_FALSE`. A literal
/// catalog (no wildcards, or `SQL_ATTR_METADATA_ID = SQL_TRUE`
/// identifier semantics) still works — it takes the fast exact
/// single-catalog path. See [`Metadata::list_tables`](crate::metadata_v0::Metadata::list_tables).
///
/// **Empty-string catalog:** at this C ABI boundary a `NULL` **or an
/// empty / whitespace-only** `catalog` is normalized to "all catalogs"
/// (the ODBC convention where drivers pass `""` for "no catalog
/// filter"). This differs from the Rust / pyo3 / napi surface, where an
/// empty-string catalog is a valid `LikePattern` meaning "match
/// nothing" (zero rows). C / ODBC callers who want "match nothing"
/// should not rely on `""`; the pattern-value distinction only exists
/// on the typed surfaces.
///
/// # Safety
/// `session` must be a live session handle; the string args, if
Expand All @@ -190,7 +206,7 @@ pub unsafe extern "C" fn kernel_metadata_list_tables(
) -> KernelStatusCode {
run_metadata(session, out, |session| {
Box::pin(async move {
let catalog = opt_ident(catalog, "catalog")?;
let catalog = opt_pattern(catalog, "catalog")?;
let schema_pattern = opt_pattern(schema_pattern, "schema_pattern")?;
let table_pattern = opt_pattern(table_pattern, "table_pattern")?;
// Split the comma-separated table types into a borrowed slice.
Expand Down
Loading
Loading