Skip to content

Array product#22703

Open
SubhamSinghal wants to merge 4 commits into
apache:mainfrom
SubhamSinghal:array-product
Open

Array product#22703
SubhamSinghal wants to merge 4 commits into
apache:mainfrom
SubhamSinghal:array-product

Conversation

@SubhamSinghal
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

What changes are included in this PR?

  • datafusion/functions-nested/src/array_product.rs — new ArrayProduct UDF and kernel.
  • datafusion/functions-nested/src/lib.rs — three registration sites (module, expr_fn, all_default_nested_functions).
  • datafusion/sqllogictest/test_files/array_product.slt — SLT coverage.

Are these changes tested?

yes using UT

Are there any user-facing changes?

Yes — adds two new SQL scalar functions, array_product and its alias list_product. No API breakage.

@github-actions github-actions Bot added documentation Improvements or additions to documentation sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Jun 1, 2026
Comment on lines +158 to +165
// Empty list -> multiplicative identity. Distinguished here from
// all-NULL elements (which yield NULL): we have no data either way,
// but `[]` is structurally a known-empty product, while `[NULL,NULL]`
// means every value was unknown.
if len == 0 {
builder.append_value(1.0);
continue;
}
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.

What's this behaviour based on? DuckDB seems to output null:

memory D select a, list_product(a) from values ([1]), ([2, 2]), ([1, null]), ([null]), ([]) t(a);
┌───────────┬─────────────────┐
│     a     │ list_product(a) │
│  int32[]  │     double      │
├───────────┼─────────────────┤
│ [1]       │             1.0 │
│ [2, 2]    │             4.0 │
│ [1, NULL] │             1.0 │
│ [NULL]    │            NULL │
│ []        │            NULL │
└───────────┴─────────────────┘

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed. matched behaviour with duckDB.

continue;
}

let slice = values.slice(start, 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.

I don't think a slice here is strictly necessary

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