Skip to content

Conversation

@lyne7-sc
Copy link
Contributor

@lyne7-sc lyne7-sc commented Feb 1, 2026

Which issue does this PR close?

Rationale for this change

The previous implementation of array_repeat relied on Arrow defaults when handling null and negative count values. As a result, null counts were implicitly treated as zero and returned empty arrays, which is a correctness issue.

This PR makes the handling of these edge cases explicit and aligns the function with SQL null semantics.

What changes are included in this PR?

  • Explicit handling of null and negative count values
  • Planner-time coercion of the count argument to Int64

Are these changes tested?

Yes, SLTs added and pass.

Are there any user-facing changes?

Yes. When the count value is null, array_repeat now returns a null array instead of an empty array.

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Feb 1, 2026
OffsetBuffer::new(offsets.into()),
repeated_values,
None,
Some(NullBuffer::new(nulls.finish())),
Copy link
Contributor

Choose a reason for hiding this comment

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

We can copy the nulls buffer from the count array instead of using a builder

Suggested change
Some(NullBuffer::new(nulls.finish())),
count_array.nulls().cloned(),

let total_repeated_values: usize = count_array
.values()
.iter()
.map(|&c| if c > 0 { c as usize } else { 0 })
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: technically the spec allows null slots to have non-0 values, so this could overestimate

for row_idx in 0..count_array.len() {
let (count, count_is_valid) = get_count_with_validity(count_array, row_idx);
outer_nulls.append(count_is_valid);
let list_is_valid = !list_array.is_null(row_idx);
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 list_is_valid = !list_array.is_null(row_idx);
let list_is_valid = list_array.is_valid(row_idx);

),
Arc::new(inner_list),
None,
Some(NullBuffer::new(outer_nulls.finish())),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same note here about reusing input null buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array_repeat function does not handle null values in count array

2 participants