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
36 changes: 18 additions & 18 deletions src/metadata/thrift_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,12 @@ pub(crate) fn reshape_schemas(
/// when they're missing.
///
/// `requested_catalog` fills `TABLE_CAT` rows for server responses
/// that omit it (single-catalog form). `table_types`, when `Some`,
/// filters rows to those whose `TABLE_TYPE` appears in the slice
/// (matches JDBC `DatabaseMetaData.getTables` behaviour).
/// that omit it (single-catalog form). `table_types`, when `Some` with
/// at least one entry, filters rows to those whose `TABLE_TYPE` appears
/// in the slice (matches JDBC `DatabaseMetaData.getTables` behaviour).
/// A `Some(&[])` (explicit empty slice) is treated like `None` and
/// matches all table types — see the inline note in the filter block
/// below (METADATA-035 conformance / C# ADBC parity).
///
/// Catalog *matching* is not done here: a wildcard catalog is resolved
/// in `list_tables` by enumerating catalogs and issuing one scoped
Expand Down Expand Up @@ -522,17 +525,14 @@ pub(crate) fn reshape_tables(
// Apply table_types filter, if requested. The JDBC `DatabaseMetaData.
// getTables(...)` Javadoc specifies that `null` types returns all
// types, but is silent on what an *explicit empty array* means.
// Two interpretations exist in the wild:
// - Empty == null (returns all rows). Convenient, but conflates
// "I didn't filter" with "I asked for nothing".
// - Empty == "filter accepting nothing" (returns zero rows). Literal
// reading of the filter contract.
// The Databricks Thrift backend follows the literal reading: zero
// rows on `types=[]`. We match Thrift here for cross-backend parity
// (verified via the python-comparator). Callers that want "all
// types" should pass `None`, not `Some(&[])`.
// Per the multi-language conformance spec (METADATA-035) and the C#
Comment thread
oss-reviewer-bot[bot] marked this conversation as resolved.
Resolved
// ADBC driver, an explicit *empty* array is equivalent to `null`:
// it matches ALL table types, not none. Only a `Some` with at least
// one entry actually restricts the result set. This mirrors JDBC
// #1570 / hiveserver2 #72, which align the same way.
let filtered = match table_types {
None => reshaped,
Some([]) => reshaped,
Some(types) => filter_tables_by_type(&reshaped, types)?,
};
// Sort to match the JDBC driver's `getTables` row order
Expand Down Expand Up @@ -1068,14 +1068,14 @@ mod tests {
}

#[test]
fn tables_empty_types_filter_returns_zero_rows() {
// Matches Thrift's behavior: explicit `Some(&[])` is a filter
// that accepts no table types, so the result is empty.
// `None` (caller didn't pass a type filter at all) is the
// separate "all types" path — see `tables_none_types_passes_all`.
fn tables_empty_types_matches_all() {
// Per the JDBC/ADBC contract (spec METADATA-035), an explicit
// empty `table_types` slice is equivalent to `None`: it matches
// ALL table types, not none. This is the same result as the
// `None` path — see `tables_none_types_passes_all`.
let b = server_tables_full();
let out = reshape_tables(&b, Some("main"), Some(&[])).unwrap();
assert_eq!(out.num_rows(), 0);
assert_eq!(out.num_rows(), 3);
}

#[test]
Expand Down
81 changes: 81 additions & 0 deletions tests/v0_metadata_empty_types_e2e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) 2026 Databricks, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! E2E repro for issue #187: `Metadata::list_tables` must treat an empty
//! `table_types` slice (`Some(&[])`) the same as `None` — match ALL table
//! types — per the JDBC/ADBC contract (spec METADATA-035), not "match none".
//!
//! Run with:
//! ```sh
//! cargo test --test v0_metadata_empty_types_e2e -- --ignored --nocapture
//! ```

mod common;

use databricks_sql_kernel::{LikePattern, ResultBatch, ResultStream};

async fn count_rows(mut stream: ResultStream) -> usize {
let mut rows = 0;
while let Some(rb) = stream.next_batch().await.expect("next_batch") {
let ResultBatch::Arrow(rb) = rb else {
panic!("expected Arrow batch in v0");
};
rows += rb.num_rows();
}
rows
}

#[tokio::test]
#[ignore]
async fn empty_table_types_matches_all_like_none() {
let session = common::live_session().await;

// `samples.information_schema` is a UC-managed schema present in every
// workspace and exposes many objects (a mix of views), so both the
// `None` and `Some(&[])` calls should return a positive, equal count.
let catalog = || Some(LikePattern::new("samples").unwrap());
let schema = || Some(LikePattern::new("information_schema").unwrap());

let none_rows = count_rows(
session
.metadata()
.list_tables(catalog(), schema(), None, None)
.await
.expect("list_tables(None)"),
)
.await;

let empty_rows = count_rows(
session
.metadata()
.list_tables(catalog(), schema(), None, Some(&[]))
.await
.expect("list_tables(Some(&[]))"),
)
.await;

assert!(
none_rows > 0,
"precondition: samples.information_schema should expose tables via None filter; got 0"
);
// The bug: with the unfixed kernel, `Some(&[])` drops every row → 0,
// while `None` returns `none_rows`. This assertion is red pre-fix.
assert_eq!(
empty_rows, none_rows,
"empty table_types slice must match all types (same as None): \
None returned {none_rows} rows, Some(&[]) returned {empty_rows}"
);

session.close().await.expect("close");
}
Loading