Skip to content

RowConverter panics when encoding union array with non-default type IDs #9263

@kawadakk

Description

@kawadakk

Describe the bug
RowConverter::append panics when union fields have non-default type IDs.

To Reproduce
Update arrow_row::tests::test_row_converter_roundtrip_with_one_union_column as follows:

@@ -4317,3 +4317,3 @@ mod tests {
         let fields = UnionFields::try_new(
-            vec![0, 1],
+            vec![70, 1],
             vec![
@@ -4327,3 +4327,3 @@ mod tests {
         let string_array = StringArray::from(vec![None::<&str>, Some("hello")]);
-        let type_ids = vec![0i8, 1].into();
+        let type_ids = vec![70i8, 1].into();
$ cargo test -p arrow-row test_row_converter_roundtrip_with_one_union_column
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.04s
     Running unittests src/lib.rs (target/debug/deps/arrow_row-cab30e58e5bacbe0)

running 1 test
test tests::test_row_converter_roundtrip_with_one_union_column ... FAILED

failures:

---- tests::test_row_converter_roundtrip_with_one_union_column stdout ----

thread 'tests::test_row_converter_roundtrip_with_one_union_column' (562579) panicked at arrow-array/src/array/union_array.rs:253:24:
invalid type id
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/std/src/panicking.rs:698:5
   1: core::panicking::panic_fmt
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/panicking.rs:75:14
   2: core::panicking::panic_display
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/panicking.rs:259:5
   3: core::option::expect_failed
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/option.rs:2178:5
   4: core::option::Option<T>::expect
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/option.rs:965:21
   5: arrow_array::array::union_array::UnionArray::child
             at .../arrow-rs/arrow-array/src/array/union_array.rs:253:24
   6: arrow_row::Codec::encoder
             at ./src/lib.rs:681:51
   7: arrow_row::RowConverter::append::{{closure}}
             at ./src/lib.rs:879:23
   8: core::iter::adapters::map::map_try_fold::{{closure}}
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/iter/adapters/map.rs:95:28
   9: core::iter::traits::iterator::Iterator::try_fold
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/iter/traits/iterator.rs:2426:21
  10: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/iter/adapters/map.rs:121:19
  11: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::try_fold
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/iter/adapters/mod.rs:192:14
  12: core::iter::traits::iterator::Iterator::try_for_each
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/iter/traits/iterator.rs:2487:14
  13: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::next
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/iter/adapters/mod.rs:174:14
  14: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/alloc/src/vec/spec_from_iter_nested.rs:25:41
  15: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/alloc/src/vec/spec_from_iter.rs:34:9
  16: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/alloc/src/vec/mod.rs:3683:9
  17: core::iter::traits::iterator::Iterator::collect
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/iter/traits/iterator.rs:2027:9
  18: <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter::{{closure}}
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/result.rs:2144:51
  19: core::iter::adapters::try_process
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/iter/adapters/mod.rs:160:17
  20: <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/result.rs:2144:9
  21: core::iter::traits::iterator::Iterator::collect
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/iter/traits/iterator.rs:2027:9
  22: arrow_row::RowConverter::append
             at ./src/lib.rs:881:14
  23: arrow_row::RowConverter::convert_columns
             at ./src/lib.rs:810:14
  24: arrow_row::tests::test_row_converter_roundtrip_with_one_union_column
             at ./src/lib.rs:4346:14
  25: arrow_row::tests::test_row_converter_roundtrip_with_one_union_column::{{closure}}
             at ./src/lib.rs:4316:60
  26: core::ops::function::FnOnce::call_once
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/ops/function.rs:250:5
  27: core::ops::function::FnOnce::call_once
             at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    tests::test_row_converter_roundtrip_with_one_union_column

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 60 filtered out; finished in 0.02s

error: test failed, to rerun pass `-p arrow-row --lib`

Expected behavior
Successful test run

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions