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

Fix ScalarValue::to_array_of_size for DenseUnion #13797

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,7 @@ impl ScalarValue {
e,
size
),
ScalarValue::Union(value, fields, _mode) => match value {
ScalarValue::Union(value, fields, mode) => match value {
Some((v_id, value)) => {
let mut new_fields = Vec::with_capacity(fields.len());
let mut child_arrays = Vec::<ArrayRef>::with_capacity(fields.len());
Expand All @@ -2453,15 +2453,23 @@ impl ScalarValue {
value.to_array_of_size(size)?
} else {
let dt = field.data_type();
new_null_array(dt, size)
match mode {
UnionMode::Sparse => new_null_array(dt, size),
// In a dense union, only the child with values needs to be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked the spec and I agree with this check: https://arrow.apache.org/docs/format/Columnar.html#dense-union

// allocated
UnionMode::Dense => new_null_array(dt, 0),
}
};
let field = (**field).clone();
child_arrays.push(ar);
new_fields.push(field.clone());
}
let type_ids = repeat(*v_id).take(size);
let type_ids = ScalarBuffer::<i8>::from_iter(type_ids);
let value_offsets: Option<ScalarBuffer<i32>> = None;
let value_offsets = match mode {
UnionMode::Sparse => None,
UnionMode::Dense => Some(ScalarBuffer::from_iter(0..size as i32)),
};
let ar = UnionArray::try_new(
fields.clone(),
type_ids,
Expand Down Expand Up @@ -5642,14 +5650,12 @@ mod tests {
// null array
Arc::new(NullArray::new(3)),
// dense union
/* Dense union fails due to https://github.com/apache/datafusion/issues/13762
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

let mut builder = UnionBuilder::new_dense();
builder.append::<Int32Type>("a", 1).unwrap();
builder.append::<Float64Type>("b", 3.4).unwrap();
Arc::new(builder.build().unwrap())
}
*/
},
// sparse union
{
let mut builder = UnionBuilder::new_sparse();
Expand Down
Loading