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.
- Add authenticated connector-service feature flags with a bounded,
process-wide workspace cache and kernel-internal typed readers for all six
SAFE types.
- Result schemas now carry the Thrift-compatible `Spark:DataType:SqlName`
field metadata key, set to the manifest's `type_text`, matching Thrift
results and the C# ADBC SEA path.

### Changed

Expand Down
64 changes: 61 additions & 3 deletions src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ impl ResultReaderFactory {
/// the kernel does on the way out to consumers:
///
/// - manifest-driven metadata attachment (`databricks.type_name`,
/// `databricks.type_text`, precision / scale / interval kind);
/// `databricks.type_text`, precision / scale / interval kind,
/// `Spark:DataType:SqlName`);
/// - optional complex-type JSON stringification when the session
/// has `complex_types_as_json = true`.
///
Expand Down Expand Up @@ -885,13 +886,18 @@ impl ResultReader for EmptyReader {
/// without reverse-engineering from Arrow type IDs.
///
/// Keys use the `databricks.` prefix to avoid conflicts with other metadata
/// conventions (e.g., Arrow's own `ARROW:extension:name`).
/// conventions (e.g., Arrow's own `ARROW:extension:name`), except
/// [`SPARK_SQL_NAME`](metadata_keys::SPARK_SQL_NAME), which mirrors the Thrift
/// server's key.
pub mod metadata_keys {
pub const TYPE_NAME: &str = "databricks.type_name";
pub const TYPE_TEXT: &str = "databricks.type_text";
pub const TYPE_PRECISION: &str = "databricks.type_precision";
pub const TYPE_SCALE: &str = "databricks.type_scale";
pub const TYPE_INTERVAL_TYPE: &str = "databricks.type_interval_type";
/// Thrift-compatible type key, set to the same value as [`TYPE_TEXT`].
/// Consumers written against Thrift results (e.g. Power BI, JDBC) read it.
pub const SPARK_SQL_NAME: &str = "Spark:DataType:SqlName";
}

/// Adapter to make ResultReader work as arrow's RecordBatchReader.
Expand Down Expand Up @@ -926,7 +932,8 @@ impl ResultReaderAdapter {
/// positional placeholders (`col_0`, …) in the Arrow payload; the
/// authoritative names live in the manifest;
/// - attach `databricks.*` type metadata (type_name, type_text,
/// precision, scale, interval_type) for the Arrow C Data FFI boundary.
/// precision, scale, interval_type) for the Arrow C Data FFI boundary;
/// - attach the Thrift-compatible `Spark:DataType:SqlName` (= type_text).
///
/// Fields with no matching `ColumnInfo` are left unchanged.
pub(crate) fn augment_schema_with_manifest(
Expand Down Expand Up @@ -956,6 +963,12 @@ impl ResultReaderAdapter {
.insert(metadata_keys::TYPE_NAME.to_string(), info.type_name.clone());
metadata
.insert(metadata_keys::TYPE_TEXT.to_string(), info.type_text.clone());
// SEA copies `type_text` from the Thrift server's
// `Spark:DataType:SqlName`, so this matches Thrift results.
metadata.insert(
metadata_keys::SPARK_SQL_NAME.to_string(),
info.type_text.clone(),
);
if let Some(prec) = info.type_precision {
metadata.insert(
metadata_keys::TYPE_PRECISION.to_string(),
Expand Down Expand Up @@ -1524,6 +1537,51 @@ mod tests {
);
}

/// Thrift consumers read the literal `Spark:DataType:SqlName` key, so pin
/// the wire string rather than the constant.
#[test]
fn test_augment_schema_sets_thrift_sql_name_from_type_text() {
let schema = Arc::new(Schema::new(vec![
Field::new("amount", DataType::Decimal128(10, 2), true),
Field::new(
"tags",
DataType::List(Arc::new(Field::new("item", DataType::Utf8, true))),
true,
),
]));
let manifest = make_manifest(vec![
make_column_info(
"amount",
"DECIMAL",
"DECIMAL(10,2)",
0,
Some(10),
Some(2),
None,
),
make_column_info("tags", "ARRAY", "ARRAY<STRING>", 1, None, None, None),
]);

let augmented = ResultReaderAdapter::augment_schema_with_manifest(&schema, &manifest);

assert_eq!(
augmented
.field(0)
.metadata()
.get("Spark:DataType:SqlName")
.map(String::as_str),
Some("DECIMAL(10,2)")
);
assert_eq!(
augmented
.field(1)
.metadata()
.get("Spark:DataType:SqlName")
.map(String::as_str),
Some("ARRAY<STRING>")
);
}

#[test]
fn test_augment_schema_preserves_geospatial_identity_and_srid() {
let binary_geo = DataType::Struct(Fields::from(vec![
Expand Down
7 changes: 7 additions & 0 deletions src/reader/post_processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,13 @@ mod tests {
.get(metadata_keys::TYPE_NAME),
Some(&"VARIANT".to_string())
);
assert_eq!(
out.schema()
.field(0)
.metadata()
.get(metadata_keys::SPARK_SQL_NAME),
Some(&"VARIANT".to_string())
);
}

#[tokio::test]
Expand Down
Loading