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 @@ -23,6 +23,9 @@ changes go in their respective binding's NEXT_CHANGELOG.

### Fixed

- Metadata: `Metadata::type_info()` now matches the established Thrift
`getTypeInfo` result shape and current 20-row type catalogue.

---
*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
5 changes: 3 additions & 2 deletions docs/migration-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ exercises `Session` end-to-end without needing PR 4 to land first.
JDBC and ODBC drivers already maintain a rename layer
(`MetadataResultConstants` / `metadata_transformer.cpp`) and
continue to use it. Two static methods (`type_info` /
`table_types`) have no server-native shape and are synthesised
in-memory using the JDBC `getTypeInfo` / `getTableTypes` schemas;
`table_types`) have no SEA response and are synthesised in memory:
`type_info` matches the exact Thrift/HiveServer2 `getTypeInfo`
contract, while `table_types` uses the JDBC `getTableTypes` schema;
see `src/metadata/schemas.rs`.
- A thin `ResultStream::from_reader(Box<dyn ResultReader>)` adapter
lands here — metadata results today fit in one batch from inline
Expand Down
90 changes: 59 additions & 31 deletions src/metadata/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
//! `functions` still pass server shape through; reshape for those is
//! deferred.
//!
//! Static methods (`type_info`, `table_types`) have no server-native
//! shape to mirror — there's no `SHOW TYPE_INFO` command — so the
//! kernel synthesises a result. The schemas live here so the
//! synthesiser sees one source of truth. We use the **JDBC
//! `getTypeInfo` / `getTableTypes`** column contract for the same
//! reason as the four core methods: it's the contract JDBC, ODBC,
//! and PySQL all agree on. ADBC restructures from this shape.
//! Static methods (`type_info`, `table_types`) have no SEA response to
//! reshape, so the kernel synthesises their results. `type_info` mirrors
//! the established Thrift/HiveServer2 `getTypeInfo` column contract;
//! wrappers can therefore switch transports without changing the schema
//! or row corpus. `table_types` uses the JDBC `getTableTypes` contract.

use arrow_schema::{DataType, Field, Schema, SchemaRef};
use std::sync::{Arc, LazyLock};
Expand All @@ -38,30 +36,34 @@ fn schema(fields: Vec<Field>) -> SchemaRef {
Arc::new(Schema::new(fields))
}

/// JDBC `getTypeInfo` — 19 columns. See the module-level docs for
/// why we pick the JDBC contract here even though the kernel is
/// otherwise pass-through.
fn thrift_field(name: &str, data_type: DataType) -> Field {
Field::new(name, data_type, true)
}

/// Thrift/HiveServer2 `getTypeInfo` — 18 columns.
///
/// Every field is nullable because the Node Thrift driver's
/// `hiveSchemaToArrowSchema` adapter represents the server schema that way.
pub(crate) static TYPE_INFO_SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| {
schema(vec![
Field::new("TYPE_NAME", DataType::Utf8, false),
Field::new("DATA_TYPE", DataType::Int32, false),
Field::new("COLUMN_SIZE", DataType::Int32, true),
Field::new("LITERAL_PREFIX", DataType::Utf8, true),
Field::new("LITERAL_SUFFIX", DataType::Utf8, true),
Field::new("CREATE_PARAMS", DataType::Utf8, true),
Field::new("NULLABLE", DataType::Int32, false),
Field::new("CASE_SENSITIVE", DataType::Boolean, false),
Field::new("SEARCHABLE", DataType::Int32, false),
Field::new("UNSIGNED_ATTRIBUTE", DataType::Boolean, true),
Field::new("FIXED_PREC_SCALE", DataType::Boolean, false),
Field::new("AUTO_UNIQUE_VALUE", DataType::Boolean, true),
Field::new("LOCAL_TYPE_NAME", DataType::Utf8, true),
Field::new("MINIMUM_SCALE", DataType::Int32, true),
Field::new("MAXIMUM_SCALE", DataType::Int32, true),
Field::new("SQL_DATA_TYPE", DataType::Int32, true),
Field::new("SQL_DATETIME_SUB", DataType::Int32, true),
Field::new("NUM_PREC_RADIX", DataType::Int32, true),
Field::new("INTERVAL_PRECISION", DataType::Int32, true),
thrift_field("TYPE_NAME", DataType::Utf8),
thrift_field("DATA_TYPE", DataType::Int32),
thrift_field("PRECISION", DataType::Int32),
thrift_field("LITERAL_PREFIX", DataType::Utf8),
thrift_field("LITERAL_SUFFIX", DataType::Utf8),
thrift_field("CREATE_PARAMS", DataType::Utf8),
thrift_field("NULLABLE", DataType::Int16),
thrift_field("CASE_SENSITIVE", DataType::Boolean),
thrift_field("SEARCHABLE", DataType::Int16),
thrift_field("UNSIGNED_ATTRIBUTE", DataType::Boolean),
thrift_field("FIXED_PREC_SCALE", DataType::Boolean),
thrift_field("AUTO_INCREMENT", DataType::Boolean),
thrift_field("LOCAL_TYPE_NAME", DataType::Utf8),
thrift_field("MINIMUM_SCALE", DataType::Int16),
thrift_field("MAXIMUM_SCALE", DataType::Int16),
thrift_field("SQL_DATA_TYPE", DataType::Int32),
thrift_field("SQL_DATETIME_SUB", DataType::Int32),
thrift_field("NUM_PREC_RADIX", DataType::Int32),
])
});

Expand All @@ -74,8 +76,34 @@ mod tests {
use super::*;

#[test]
fn type_info_schema_has_19_columns() {
assert_eq!(TYPE_INFO_SCHEMA.fields().len(), 19);
fn type_info_schema_matches_thrift() {
let expected = [
("TYPE_NAME", DataType::Utf8),
("DATA_TYPE", DataType::Int32),
("PRECISION", DataType::Int32),
("LITERAL_PREFIX", DataType::Utf8),
("LITERAL_SUFFIX", DataType::Utf8),
("CREATE_PARAMS", DataType::Utf8),
("NULLABLE", DataType::Int16),
("CASE_SENSITIVE", DataType::Boolean),
("SEARCHABLE", DataType::Int16),
("UNSIGNED_ATTRIBUTE", DataType::Boolean),
("FIXED_PREC_SCALE", DataType::Boolean),
("AUTO_INCREMENT", DataType::Boolean),
("LOCAL_TYPE_NAME", DataType::Utf8),
("MINIMUM_SCALE", DataType::Int16),
("MAXIMUM_SCALE", DataType::Int16),
("SQL_DATA_TYPE", DataType::Int32),
("SQL_DATETIME_SUB", DataType::Int32),
("NUM_PREC_RADIX", DataType::Int32),
];

assert_eq!(TYPE_INFO_SCHEMA.fields().len(), expected.len());
for (field, (name, data_type)) in TYPE_INFO_SCHEMA.fields().iter().zip(expected) {
assert_eq!(field.name(), name);
assert_eq!(field.data_type(), &data_type);
assert!(field.is_nullable(), "{name} must be nullable");
}
}

#[test]
Expand Down
Loading
Loading