Skip to content

Implement flatten function #6995

Closed
@izveigor

Description

@izveigor

Is your feature request related to a problem or challenge?

Summary

Characteristic Description
Function name: flatten
Aliases: -
Original function?: No
Function Description: Azure DataBricks: Returns an array of the elements in the union of array1 and array2 without duplicates.
Spark SQL: Creates a single array from an array of arrays column.
ClickHouse: Converts an array of arrays to a flat array. Function: Applies to any depth of nested arrays. Does not change arrays that are already flat. The flattened array contains all the elements from all source arrays.
DuckDB: Concatenate a list of lists into a single list. This only flattens one level of the list (see examples).
Sources: Concept Azure DuckDB ClickHouse Spark

Examples:

D select flatten([[1, 2, 3], [4, 5, 6]]);
┌──────────────────────────────────────────────────────────────────────────────┐
│ flatten(main.list_value(main.list_value(1, 2, 3), main.list_value(4, 5, 6))) │
│                                   int32[]                                    │
├──────────────────────────────────────────────────────────────────────────────┤
│ [1, 2, 3, 4, 5, 6]                                                           │
└──────────────────────────────────────────────────────────────────────────────┘
D select flatten([[[1, 1], [2, 2], [3, 3]], [[4, 4], [5, 5], [6, 6]]]);
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ flatten(main.list_value(main.list_value(main.list_value(1, 1), main.list_value(2, 2), main.list_value(3, 3)), main.list_value(main.list_value(4, 4), main.li…  │
│                                                                           int32[][]                                                                            │
├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]                                                                                                               │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    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