Skip to content

Commit b826162

Browse files
authored
Improve Schema metadata mismatch error (#2238)
1 parent 577a93b commit b826162

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

arrow/src/datatypes/mod.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,23 +1481,31 @@ mod tests {
14811481
.is_err());
14821482

14831483
// incompatible metadata should throw error
1484-
assert!(Schema::try_merge(vec![
1484+
let res = Schema::try_merge(vec![
14851485
Schema::new_with_metadata(
14861486
vec![Field::new("first_name", DataType::Utf8, false)],
1487-
[("foo".to_string(), "bar".to_string()),]
1487+
[("foo".to_string(), "bar".to_string())]
14881488
.iter()
14891489
.cloned()
1490-
.collect::<HashMap<String, String>>()
1490+
.collect::<HashMap<String, String>>(),
14911491
),
14921492
Schema::new_with_metadata(
14931493
vec![Field::new("last_name", DataType::Utf8, false)],
1494-
[("foo".to_string(), "baz".to_string()),]
1494+
[("foo".to_string(), "baz".to_string())]
14951495
.iter()
14961496
.cloned()
1497-
.collect::<HashMap<String, String>>()
1498-
)
1497+
.collect::<HashMap<String, String>>(),
1498+
),
14991499
])
1500-
.is_err());
1500+
.unwrap_err();
1501+
1502+
let expected = "Fail to merge schema due to conflicting metadata. Key 'foo' has different values 'bar' and 'baz'";
1503+
assert!(
1504+
res.to_string().contains(expected),
1505+
"Could not find expected string '{}' in '{}'",
1506+
expected,
1507+
res
1508+
);
15011509

15021510
Ok(())
15031511
}

arrow/src/datatypes/schema.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ impl Schema {
149149
// merge metadata
150150
if let Some(old_val) = merged.metadata.get(&key) {
151151
if old_val != &value {
152-
return Err(ArrowError::SchemaError(
153-
"Fail to merge schema due to conflicting metadata."
154-
.to_string(),
155-
));
152+
return Err(ArrowError::SchemaError(format!(
153+
"Fail to merge schema due to conflicting metadata. \
154+
Key '{}' has different values '{}' and '{}'",
155+
key, old_val, value
156+
)));
156157
}
157158
}
158159
merged.metadata.insert(key, value);

0 commit comments

Comments
 (0)