Skip to content
Open
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
31 changes: 30 additions & 1 deletion vortex-datafusion/src/convert/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ pub fn calculate_physical_schema(
})
.collect::<DFResult<Vec<_>>>()?;

Ok(Schema::new(fields))
Ok(Schema::new_with_metadata(
fields,
reference_logical_schema.metadata().clone(),
))
}

/// Calculate the physical Arrow type for a field, preferring the logical type when the
Expand Down Expand Up @@ -246,6 +249,32 @@ mod tests {
);
}

#[test]
fn test_schema_metadata_preserved() -> DFResult<()> {
let logical_schema = Schema::new_with_metadata(
vec![Field::new("col", DataType::Int32, false)],
[("table".to_string(), "metadata".to_string())]
.into_iter()
.collect(),
);
let dtype = DType::Struct(
StructFields::from_iter([(
"col",
DType::Primitive(PType::I32, Nullability::NonNullable),
)]),
Nullability::NonNullable,
);

let physical_schema =
calculate_physical_schema(&dtype, &logical_schema, &ArrowSession::default())?;

assert_eq!(
physical_schema.metadata().get("table"),
Some(&"metadata".to_string())
);
Ok(())
}

#[test]
fn test_utf8_variants_preserved() {
// Non-view string types become view types after roundtrip through DType,
Expand Down
Loading
Loading