Skip to content

feat: support array_compact builtin function#21522

Open
comphead wants to merge 4 commits intoapache:mainfrom
comphead:array_compact
Open

feat: support array_compact builtin function#21522
comphead wants to merge 4 commits intoapache:mainfrom
comphead:array_compact

Conversation

@comphead
Copy link
Copy Markdown
Contributor

@comphead comphead commented Apr 9, 2026

Which issue does this PR close?

  • Closes #.

Rationale for this change

Create array_compact function which removes NULLs from input array. There is no direct counterparty in DuckDB however the function used in Spark, SnowFlake

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Apr 9, 2026
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Apr 9, 2026
}

/// array_compact SQL function
pub fn array_compact_inner(arg: &[ArrayRef]) -> Result<ArrayRef> {
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
pub fn array_compact_inner(arg: &[ArrayRef]) -> Result<ArrayRef> {
fn array_compact_inner(arg: &[ArrayRef]) -> Result<ArrayRef> {

false,
Capacities::Array(original_data.len()),
);
let mut valid = NullBufferBuilder::new(list_array.len());
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.

Can directly grab null buffer from input array for the output array to avoid needing a builder here

[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
[[5, 6], NULL]

## array_compact (aliases: `list_compact`)
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.

Should we also add a test for fixedsizelist?

@comphead
Copy link
Copy Markdown
Contributor Author

Thanks @Jefffrey addressed the comments.

One thing comes to my mind is: arrays.slt becomes unmanageable, we need to split it up into smaller files, file per function basis

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

Labels

documentation Improvements or additions to documentation functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants