Skip to content

Commit

Permalink
test: ArrowWriter and batch schema mismatch is an error
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Jan 29, 2024
1 parent 0504703 commit 03a2f7e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions parquet/src/arrow/arrow_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2963,4 +2963,29 @@ mod tests {
.any(|kv| kv.key.as_str() == ARROW_SCHEMA_META_KEY));
}
}

#[test]
fn mismatched_schemas() {
let batch_schema = Schema::new(vec![Field::new("count", DataType::Int32, false)]);
let file_schema = Arc::new(Schema::new(vec![Field::new(
"temperature",
DataType::Float64,
false,
)]));

let batch = RecordBatch::try_new(
Arc::new(batch_schema),
vec![Arc::new(Int32Array::from(vec![1, 2, 3, 4])) as _],
)
.unwrap();

let mut buf = Vec::with_capacity(1024);
let mut writer = ArrowWriter::try_new(&mut buf, file_schema.clone(), None).unwrap();

let err = writer.write(&batch).unwrap_err().to_string();
assert_eq!(
err,
"Arrow: Incompatible type. Field 'temperature' has type Float64, array has type Int32"
);
}
}

0 comments on commit 03a2f7e

Please sign in to comment.