Skip to content

[Feat](map) Support some map lambda functions - #4085

Open
linrrzqqq wants to merge 1 commit into
apache:masterfrom
linrrzqqq:map-lambda
Open

[Feat](map) Support some map lambda functions#4085
linrrzqqq wants to merge 1 commit into
apache:masterfrom
linrrzqqq:map-lambda

Conversation

@linrrzqqq

Copy link
Copy Markdown
Contributor

Versions

  • dev
  • 4.x
  • 3.x
  • 2.1 or older (not covered by version/language sync gate)

Languages

  • Chinese
  • English

Docs Checklist

  • Checked by AI
  • Test Cases Built
  • Updated required version and language counterparts, or explained why not
  • If only one language changed, confirmed whether source/translation counterparts need sync

@HappenLee HappenLee left a comment

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.

LGTM

HappenLee pushed a commit to apache/doris that referenced this pull request Sep 1, 2026
### What problem does this PR solve?

Related PR: #67045,
#67047

Doc: apache/doris-website#4085

Problem Summary:

This PR adds MAP lambda support under the Nereids planner.

Supported higher-order functions:

- `map_filter((k, v) -> predicate, map)`
- `map_exists((k, v) -> predicate, map)`
- `map_all((k, v) -> predicate, map)`
- `map_apply((k, v) -> struct(new_key, new_value), map)`
- `transform_keys((k, v) -> new_key, map)`
- `transform_values((k, v) -> new_value, map)`

Example:

```sql
SELECT map_filter(
    (k, v) -> v > 10,
    map(1, 10, 2, 20)
);

SELECT transform_values(
    (k, v) -> v + 1,
    map(1, 10, 2, 20)
);

SELECT map_apply(
    (k, v) -> (k + 1, v * 2),
    map(1, 10, 2, 20)
);
```

### Implementation

Use `map_entries(m)` to expand the map parameter and reuse the original
`array lambda` for execution.

```text
map_apply((k, v) -> (k2, v2), m)
    ↓
map_from_entries(
    array_apply(entry: struct{k, v} -> (k2, v2), map_entries(m)
);

map_filter((k, v) -> k + v > 0, m)
    ↓
%map_from_filtered_entries_unique%(
    array_map(
        entry: strct{k, v} -> if(
            e.k + e.v > 0, entry, null
        ),
    map_entries(m)
)


transform_values((k, v) -> k + v + col, m)
    ↓
%map_from_entries_unique%(
    array_map(
        entry -> (e.k, e.k + e.v + col),
        map_entries(m)
    )
)


map_exists((k, v) -> k + v = 1, m)
    ↓
array_match_any(
    array_map(
        entry -> e.k + e.v = 1,
        map_entries(m)
    )
)


map_all((k, v) -> k + v = 1, m)
    ↓
array_match_all(
    array_map(
        entry -> e.k + e.v = 1,
        map_entries(m)
    )
)
```

### Internal helper function

This PR adds two internal Map construction functions used by the
rewritten expressions:
- %map_from_entries_unique%: rebuilds a Map from an entry array without
running key deduplication. Used by `transform_value`
- %map_from_filtered_entries_unique%: **removes** null entries input
instead of throw error like `map_from_entries`. Used by `map_filter`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants