You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
parquet: ArrowWriter::try_new panics on a schema with a Union field instead of returning an error #12510
Creating an ArrowWriter (or calling ArrowSchemaConverter::convert) for an Arrow schema that contains a Union field panics with not implemented: See ARROW-8817. This happens for a top-level union and for a union nested in a struct, list, map or dictionary. The doc comment of ArrowWriter::try_new says the writer "will fail if ... the Arrow schema contains unsupported datatypes such as Unions", so I expected an Err.
The same function also panics (unreachable!) on the invalid types Time32(Microsecond), Time32(Nanosecond), Time64(Second) and Time64(Millisecond).
To Reproduce
Dependencies: arrow-array, arrow-buffer, arrow-schema, parquet (60.2.0 or main).
use std::sync::Arc;use arrow_array::{ArrayRef,Int32Array,RecordBatch,UnionArray};use arrow_buffer::ScalarBuffer;use arrow_schema::{DataType,Field,UnionFields};use parquet::arrow::ArrowWriter;fnmain(){let fields = UnionFields::try_new(vec![0],vec![Field::new("a",DataType::Int32,true)]).unwrap();let union = UnionArray::try_new(
fields,ScalarBuffer::from(vec![0i8,0]),None,vec![Arc::new(Int32Array::from(vec![1,2]))asArrayRef],).unwrap();let batch = RecordBatch::try_from_iter([("c",Arc::new(union)asArrayRef)]).unwrap();let result = ArrowWriter::try_new(Vec::new(), batch.schema(),None);println!("{:?}", result.map(|_| ()));}
Output on main:
thread 'main' panicked at parquet/src/arrow/schema/mod.rs:967:34:
not implemented: See ARROW-8817.
Expected behavior
ArrowWriter::try_new returns an error. The writer already returns one for the same column when it gets a union through an explicit Parquet schema (ArrowWriterOptions::with_parquet_schema):
Err(NYI("Datatype Union(Sparse, 0: (\"a\": Int32)) is not yet supported"))
Additional context
Cause: arrow_to_parquet_type (parquet/src/arrow/schema/mod.rs:967) has DataType::Union(_, _) => unimplemented!("See ARROW-8817."), and the Time32/Time64 unit matches at :801 and :813 use unreachable!. Returning Err from those arms fixes it. Union support itself is #73.
Willingness to contribute
I plan to contribute a fix for this bug independently
@cvp2004 I filed this issue and already have a fix with a test on a branch (a schema with a Union field now returns ParquetError::NYI from ArrowWriter::try_new instead of panicking). I posted take before I saw yours. Are you already working on it? If not, I'll open the PR; if you are, I'll step back and unassign myself.
@dayan02dev , I have a fix ready & have rasied a PR. I saw that the issue was raised 4 days ago & no assignees / PRs linked to te issue. Hence, I went ahead & assigned it to me.
It would be helpful if you could review my PR once. Thanks !!
Activity
cvp2004 commentedon Dec 3, 2026
take
dayan02dev commentedon Dec 3, 2026
take
dayan02dev commentedon Dec 3, 2026
@cvp2004 I filed this issue and already have a fix with a test on a branch (a schema with a Union field now returns
ParquetError::NYIfromArrowWriter::try_newinstead of panicking). I postedtakebefore I saw yours. Are you already working on it? If not, I'll open the PR; if you are, I'll step back and unassign myself.cvp2004 commentedon Dec 4, 2026
@dayan02dev , I have a fix ready & have rasied a PR. I saw that the issue was raised 4 days ago & no assignees / PRs linked to te issue. Hence, I went ahead & assigned it to me.
It would be helpful if you could review my PR once. Thanks !!