Skip to content

Implement unnest function #6555

Closed
@izveigor

Description

@izveigor

Is your feature request related to a problem or challenge?

Follow on to #6384
It would be nice to implement unnest function (with the properties like the analog in PostgreSQL) in arrow-datafusion.

Describe the solution you'd like

Main benefits for adding this feature:

  1. With unnest function we can use aggregate functions for arrays:
SELECT sum(a) AS total FROM (SELECT unnest(make_array(3, 5, 6) AS a) AS b;
----
14
  1. unnest function serves as an exchange between arrays and columns, we have 2 cases of behavior:
  • unnest with single argument
  • unnest with multiple argument (more than 1) (this form is only allowed in a query's FROM clause)

Examples:

unnest(make_array(1, 2))
----
1
2
select * from unnest(make_array(1, 2, 3), make_array('h', 'e', 'l', 'l', 'o')
----
1 h
2 e
3 l
  l
  o

Describe alternatives you've considered

For aggregate functions, we can create a lot of individual functions for aggregate functions (like array_sum), but I think this implementation would be too redundant.

Additional context

Similar Issues:
#6119

Similar PR:
#6384
#5106

Links to sources:
https://www.postgresql.org/docs/current/functions-array.html

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions