Skip to content

Commit 34fd36f

Browse files
committed
Require that the metadata of values in VALUES clause must be identical
1 parent 116170a commit 34fd36f

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

datafusion/expr/src/logical_plan/builder.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,13 @@ impl LogicalPlanBuilder {
309309
for (i, row) in values.iter().enumerate() {
310310
let value = &row[j];
311311
let metadata = value.metadata(&schema)?;
312-
common_metadata = FieldMetadata::merge_options(
313-
common_metadata.as_ref(),
314-
Some(&metadata),
315-
);
312+
if let Some(ref cm) = common_metadata {
313+
if &metadata != cm {
314+
return plan_err!("Inconsistent metadata across values list at row {i} column {j}. Was {:?} but found {:?}", cm, metadata);
315+
}
316+
} else {
317+
common_metadata = Some(metadata.clone());
318+
}
316319
let data_type = value.get_type(&schema)?;
317320
if data_type == DataType::Null {
318321
continue;
@@ -2827,6 +2830,19 @@ mod tests {
28272830
])?
28282831
.build()?;
28292832
assert_eq!(*values.schema().field(0).metadata(), metadata.to_hashmap());
2833+
2834+
// Do not allow VALUES with different metadata mixed together
2835+
let metadata2: HashMap<String, String> =
2836+
[("ARROW:extension:metadata".to_string(), "test2".to_string())]
2837+
.into_iter()
2838+
.collect();
2839+
let metadata2 = FieldMetadata::from(metadata2);
2840+
assert!(LogicalPlanBuilder::values(vec![
2841+
vec![lit_with_metadata(1, Some(metadata.clone()))],
2842+
vec![lit_with_metadata(2, Some(metadata2.clone()))],
2843+
])
2844+
.is_err());
2845+
28302846
Ok(())
28312847
}
28322848
}

0 commit comments

Comments
 (0)