dayan02dev opened a new issue, #12510:
URL: https://github.com/apache/arrow-rs/issues/12510
### 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).
```rust
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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]