Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Test that struct fields under a map still match by name
A map whose key and value are both structs, with the shared field in a
different position on each side: the entry children are matched by
position, while the fields inside them are matched by name, so a file
field with no counterpart in the table keeps its type.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PL624RiDwff7RVJ2BKSvS5
  • Loading branch information
claude committed Sep 17, 2026
commit 6b729aa86c052fe25d3e8932d8200f9316d603a5
75 changes: 75 additions & 0 deletions datafusion/datasource-parquet/src/schema_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,81 @@ mod tests {
);
}

#[test]
fn nested_coercion_map_entry_struct_children_match_by_name() {
// A map whose key and value are both structs: the two entry children
// are matched by position (the file's `key`/`value` take the types of
// the table's first/second entry child, whatever they are named),
// while the fields inside those structs go back to matching by name.
//
// Both structs put `shared` in a different position on each side, so a
// positional match inside them would coerce `file_only` instead, and a
// by-name match on the entries themselves would coerce nothing at all.
let struct_field =
|name: &str, first: (&str, DataType), second: (&str, DataType)| {
Field::new_struct(
name,
vec![
Field::new(first.0, first.1, true),
Field::new(second.0, second.1, true),
],
true,
)
};
let file_schema = Schema::new(vec![Field::new_map(
"m",
"key_value",
struct_field(
"key",
("file_only", DataType::Utf8),
("shared", DataType::Utf8),
),
struct_field(
"value",
("file_only", DataType::Utf8),
("shared", DataType::Utf8),
),
false,
true,
)]);
let table_schema = Schema::new(vec![Field::new_map(
"m",
"entries",
struct_field(
"keys",
("shared", DataType::Utf8View),
("table_only", DataType::Utf8View),
),
struct_field(
"values",
("shared", DataType::Utf8View),
("table_only", DataType::Utf8View),
),
false,
true,
)]);
let expected = Schema::new(vec![Field::new_map(
"m",
"key_value",
struct_field(
"key",
("file_only", DataType::Utf8),
("shared", DataType::Utf8View),
),
struct_field(
"value",
("file_only", DataType::Utf8),
("shared", DataType::Utf8View),
),
false,
true,
)]);
assert_eq!(
apply_file_schema_type_coercions(&table_schema, &file_schema),
Some(expected)
);
}

#[test]
fn nested_coercion_leaves_binary_map_children_to_the_validating_cast() {
use arrow::array::{
Expand Down