Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REE Dicts cannot be encoded/decoded with streaming IPC #6398

Closed
brancz opened this issue Sep 15, 2024 · 1 comment · Fixed by #6399
Closed

REE Dicts cannot be encoded/decoded with streaming IPC #6398

brancz opened this issue Sep 15, 2024 · 1 comment · Fixed by #6399
Labels
arrow Changes to the arrow crate bug

Comments

@brancz
Copy link
Contributor

brancz commented Sep 15, 2024

Describe the bug

REE arrays whose values are dictionaries can't be successfully encoded and then decoded when using streaming IPC.

To Reproduce

    #[test]
    fn test_read_ree_dict_record_batches_from_buffer() {
        let schema = Schema::new(vec![
            Field::new(
                "test1",
            DataType::RunEndEncoded(
                Arc::new(Field::new("run_ends".to_string(), DataType::Int32, false)),
                Arc::new(Field::new_dict(
                    "values".to_string(),
                    DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8)),
                    true,
                    0,
                    false,
                )),
            ),
            true,
        ),
        ]);
        let batch = RecordBatch::try_new(
            schema.clone().into(),
            vec![
            Arc::new(
                RunArray::try_new(
                    &Int32Array::from(vec![1, 2, 3]),
                    &vec![Some("a"), None, Some("a")]
                    .into_iter()
                    .collect::<DictionaryArray<Int32Type>>(),
                )
                .expect("Failed to create RunArray"),
            ),
            ],
        )
        .expect("Failed to create RecordBatch");

        let mut buffer = vec![];
        {
            let mut writer = StreamWriter::try_new_with_options(
                &mut buffer,
                &schema,
                IpcWriteOptions::default().with_preserve_dict_id(false),
            )
            .expect("Failed to create StreamWriter");
            writer.write(&batch).expect("Failed to write RecordBatch");
            writer.finish().expect("Failed to finish StreamWriter");
        }

        let mut decoder = StreamDecoder::new();
        let buf = &mut Buffer::from(buffer.as_slice());
        while let Some(_) = decoder
            .decode(buf)
            .map_err(|e| {
                ArrowError::ExternalError(format!("Failed to decode record batch: {}", e).into())
            })
            .expect("Failed to decode record batch")
        {
        }

        decoder.finish().expect("Failed to finish decoder");
    }

Expected behavior

The above test works.

Additional context

n/a

@brancz brancz added the bug label Sep 15, 2024
@alamb alamb added the arrow Changes to the arrow crate label Oct 2, 2024
@alamb
Copy link
Contributor

alamb commented Oct 2, 2024

label_issue.py automatically added labels {'arrow'} from #6399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants