Skip to content

fix(arrow-select): preserve nullif nulls for REE and Union - #10991

Open
yongster wants to merge 1 commit into
apache:mainfrom
yongster:fix/nullif-ree-union
Open

fix(arrow-select): preserve nullif nulls for REE and Union#10991
yongster wants to merge 1 commit into
apache:mainfrom
yongster:fix/nullif-ree-union

Conversation

@yongster

@yongster yongster commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

nullif creates nulls by adding a top-level validity bitmap. This works for
most arrays, but RunEndEncoded and Union arrays derive logical nullability from
their child arrays instead.

As a result, nullif previously returned non-null values at positions where
the condition was true for these array types.

Closes #10990

  • Delegate nullif for RunEndEncoded and Union arrays to take, using null
    indices for the positions selected by the condition.
  • Return an error when a RunEndEncoded values field is non-nullable and cannot
    represent the requested nulls.
  • Return an error when a Union has no nullable child that can represent null
    indices.
  • Prefer a nullable Union child when take needs to represent a null index.
  • Add coverage for nullable and non-nullable REE, plus dense and sparse Union
    cases.

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-select labels Sep 4, 2026
@Jefffrey Jefffrey added the bug label Sep 5, 2026
return Ok(make_array(left_data));
match left.data_type() {
DataType::RunEndEncoded(_, values) => {
if !values.is_nullable() && right.iter().any(|value| value == Some(true)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !values.is_nullable() && right.iter().any(|value| value == Some(true)) {
if !values.is_nullable() && right.has_true() {

}

/// Applies `nullif` to arrays that represent logical nulls in their children.
fn nullif_take(left: &dyn Array, right: &BooleanArray) -> Result<ArrayRef, ArrowError> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

perhaps we can reuse the computation we do here:

// left=0 (null) right=null output bitmap=null
// left=0 right=1 output bitmap=null
// left=1 (set) right=null output bitmap=set (passthrough)
// left=1 right=1 & comp=true output bitmap=null
// left=1 right=1 & comp=false output bitmap=set
//
// Thus: result = left null bitmap & (!right_values | !right_bitmap)
// OR left null bitmap & !(right_values & right_bitmap)
// Compute right_values & right_bitmap
let right = match right.nulls() {
Some(nulls) => right.values() & nulls.inner(),
None => right.values().clone(),
};

instead of needing to check validity in this iterator

Comment thread arrow-select/src/take.rs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 arrow-select bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nullif does not introduce nulls for RunEndEncoded and Union arrays

2 participants