Skip to content

Conversation

@Weijun-H
Copy link
Member

@Weijun-H Weijun-H commented Nov 1, 2025

Which issue does this PR close?

Rationale for this change

array_slice accepts ListView / LargeListView inputs.

What changes are included in this PR?

  • Extend array_slice_inner to handle ListView/LargeListView arrays directly.
  • Share the stride/bounds logic between list and list‑view implementations via a new SlicePlan.

Are these changes tested?

Yes

Are there any user-facing changes?

Yes. array_slice now accepts ListView and LargeListView arrays without requiring an explicit cast.

@Weijun-H Weijun-H marked this pull request as draft November 1, 2025 19:26
@github-actions github-actions bot added the common Related to common crate label Nov 1, 2025
@Weijun-H
Copy link
Member Author

Weijun-H commented Nov 1, 2025

cc @brancz

@Weijun-H Weijun-H changed the title feat: Enhance array_slice functionality to support ListView and LargeListView types feat: Enhance array_slice functionality to support ListView and LargeListView types Nov 1, 2025
@Weijun-H Weijun-H marked this pull request as ready for review November 1, 2025 20:09
Copy link
Contributor

@vegarsti vegarsti left a comment

Choose a reason for hiding this comment

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

Very nice refactor! The SlicePlan and extraction of functions makes the rest of the code a lot more readable.

Comment on lines 778 to 786
let field = match array.data_type() {
ListView(field) | LargeListView(field) => Arc::clone(field),
other => {
return Err(internal_datafusion_err!(
"array_slice got unexpected data type: {}",
other
));
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest moving this to before the slice to avoid unnecessary work

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch!

);
}

#[test]
Copy link
Contributor

@vegarsti vegarsti Nov 2, 2025

Choose a reason for hiding this comment

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

Nice tests! This PR for reverse of FixedSizeList also added sqllogictest cases https://github.com/apache/datafusion/pull/16423/files#diff-317c67cc9ce87268e4ccec1cb75316eed82f99ae2ffc226874e5897913ffa4c8

It doesn't look like that is currently possible for ListView on arrow-rs 57, as it hits this path, which did not have a branch for ListView at the time of release
https://github.com/apache/arrow-rs/blob/062d766a9c3070d191d1a1fd0baca01b9d13994f/arrow-schema/src/datatype_parse.rs#L70-L96 (but it was added recently: apache/arrow-rs#8649)

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can add to SLTs and expect it to fail on the cast (leaving the expected results as comments) so when we bump to arrow with that fix we will automatically know

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea!

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Nov 2, 2025
@Weijun-H Weijun-H requested a review from Jefffrey November 2, 2025 19:50
Copy link
Contributor

@Jefffrey Jefffrey left a comment

Choose a reason for hiding this comment

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

I like the introduction of SlicePlan

}
}

fn adjusted_from_index<O: OffsetSizeTrait>(index: i64, len: O) -> Result<Option<O>>
Copy link
Contributor

@Jefffrey Jefffrey Nov 3, 2025

Choose a reason for hiding this comment

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

Looks like this + adjusted_to_index are pulled out from their inner function general_array_slice verbatim without changes 👍

(Just a note for myself so I know there isn't an actual diff on the function)

Comment on lines +707 to +713
let field = match array.data_type() {
ListView(field) | LargeListView(field) => Arc::clone(field),
other => {
return internal_err!("array_slice got unexpected data type: {}", other);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let field = match array.data_type() {
ListView(field) | LargeListView(field) => Arc::clone(field),
other => {
return internal_err!("array_slice got unexpected data type: {}", other);
}
};
let field = match array.data_type() {
ListView(field) | LargeListView(field) => Arc::clone(field),
_ => unreachable!()
};

Given array is most definitely a GenericListViewArray

Though I wonder why we handle this differently to how its done in general_array_slice 🤔

len,
from_array.value(row_index),
to_array.value(row_index),
stride.map(|s| s.value(row_index)),
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't check for stride nullability

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

return Ok(SlicePlan::Empty);
};

let stride_value = stride_raw.unwrap_or(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Null strides are assumed 1 by default? Is this intended?

@Weijun-H Weijun-H force-pushed the 18351-array-slice-listview branch from defabd2 to 9dee50f Compare November 4, 2025 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support slicing ListView

3 participants