Skip to content

parquet: ArrowWriter::try_new panics on a schema with a Union field instead of returning an error #12510

Todo

Description

@dayan02dev

Describe the bug

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;

fn main() {
    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])) as ArrayRef],
    )
    .unwrap();
    let batch = RecordBatch::try_from_iter([("c", Arc::new(union) as ArrayRef)]).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

Activity

  1. cvp2004 commented on Dec 3, 2026

    @cvp2004

    take

  2. dayan02dev commented on Dec 3, 2026

    @dayan02dev
    ContributorAuthor

    take

  3. dayan02dev commented on Dec 3, 2026

    @dayan02dev
    ContributorAuthor

    @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.

  4. cvp2004 commented on Dec 4, 2026

    @cvp2004

    @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 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions