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
3 changes: 3 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ changes go in their respective binding's NEXT_CHANGELOG.

### Fixed

- `list_tables` now matches `table_types` case-sensitively, matching Thrift
`GetTables`: `["table"]` no longer matches `TABLE` rows.

---
*Note: When making changes, please add your change under the appropriate
section with a brief description. At release time, move the entries here
Expand Down
38 changes: 24 additions & 14 deletions src/metadata/thrift_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ pub(crate) fn reshape_tables(
// earlier #72 reading (empty == null) after establishing that
// databricks-jdbc's `listTables` has always short-circuited an empty
// array to "return nothing". An empty `Some(&[])` therefore flows
// through `filter_tables_by_type`, whose `types.iter().any(..)` is
// through `filter_tables_by_type`, whose `types.contains(..)` is
// `false` for every row → an empty (correctly-typed) batch.
let filtered = match table_types {
None => reshaped,
Expand Down Expand Up @@ -1010,13 +1010,10 @@ fn filter_tables_by_type(batch: &RecordBatch, types: &[&str]) -> Result<RecordBa
if types_arr.is_null(i) {
false
} else {
let t = types_arr.value(i);
// Case-insensitive match: callers may pass `"view"` /
// `"Table"` (JDBC `getTables` allows any case) while the
// warehouse reports canonical uppercase (`TABLE` / `VIEW`
// / `SYSTEM_TABLE` / `METRIC_VIEW`). An exact match would
// silently drop all rows for a mixed-case request.
types.iter().any(|req| req.eq_ignore_ascii_case(t))
// Exact (case-sensitive) match, for parity with the Thrift
// server's `GetTables` and the JDBC driver's client-side
// filter: `["view"]` matches no `VIEW` row.
types.contains(&types_arr.value(i))
}
})
.collect();
Expand Down Expand Up @@ -1441,10 +1438,16 @@ mod tests {
}

#[test]
fn native_tables_apply_case_insensitive_catalog_and_type_filters() {
fn native_tables_apply_case_insensitive_catalog_and_exact_type_filters() {
let native = reshape_tables(&server_tables_full(), Some("main"), None).unwrap();

let views = process_native_tables(&native, Some("MAIN"), Some(&["view"])).unwrap();
assert_eq!(
process_native_tables(&native, Some("MAIN"), Some(&["view"]))
.unwrap()
.num_rows(),
0
);
let views = process_native_tables(&native, Some("MAIN"), Some(&["VIEW"])).unwrap();
assert_eq!(views.num_rows(), 1);
assert_eq!(
views
Expand Down Expand Up @@ -2098,14 +2101,21 @@ mod tests {
}

#[test]
fn filter_tables_by_type_is_case_insensitive() {
// Warehouse reports canonical uppercase; a lowercase / mixed-case
// request must still match (JDBC getTables allows any case).
fn filter_tables_by_type_matches_exact_case() {
let batch = tables_with_types(&["TABLE", "VIEW", "SYSTEM_TABLE"]);
let out = filter_tables_by_type(&batch, &["view", "Table"]).unwrap();
let out = filter_tables_by_type(&batch, &["VIEW", "TABLE"]).unwrap();
assert_eq!(kept_types(&out), vec!["TABLE", "VIEW"]);
}

#[test]
fn filter_tables_by_type_is_case_sensitive() {
// Thrift parity: the server matches requested types exactly, so a
// lowercase / mixed-case request returns no rows.
let batch = tables_with_types(&["TABLE", "VIEW", "SYSTEM_TABLE"]);
let out = filter_tables_by_type(&batch, &["view", "Table"]).unwrap();
assert_eq!(out.num_rows(), 0);
}

#[test]
fn filter_tables_by_type_drops_non_matching_and_nulls() {
let batch = tables_with_types(&["TABLE", "VIEW"]);
Expand Down
Loading