Skip to content

branch-4.2: [fix](function) Skip hidden elements in NULL subarrays when flattening #69321 - #69534

Open
github-actions[bot] wants to merge 1 commit into
branch-4.2from
auto-pick-69321-branch-4.2
Open

github-actions[bot] wants to merge 1 commit into
branch-4.2from
auto-pick-69321-branch-4.2

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #69321

#69321)

### What problem does this PR solve?

Issue Number: N/A

Problem Summary:
`array_flatten(array(if(id = 1, NULL, a), [9]))` could return `[101,
102, 9]` even though the input is visibly `[NULL, [9]]`.

Root cause: flattening composed offsets without checking subarray null
maps. Expressions such as `IF` can retain nonempty payloads beneath NULL
subarrays. Filter those hidden ranges at each nesting level before
composing offsets, preserve NULL scalar elements, and share the final
leaf column through COW instead of cloning it.

### Release note

Fix `array_flatten` returning hidden elements from NULL subarrays.

### Check List (For Author)

- Test:
- [x] Regression test: generated `array_flatten.out` with
`-forceGenOut`, then reran `array_flatten` successfully.
- [x] Manual test: rebuilt BE; verified the original reproducer, deeper
nesting, materialized INSERT SELECT, empty arrays, outer NULLs, and NULL
scalar elements.
- [ ] Unit Test: added `FunctionArrayFlattenTest` coverage; execution is
pending because the initial ASAN UT build was interrupted before
completion.
- Validation above used base `e0050c41211372e813107f13366d03fe45c005d6`.
The patch was subsequently carried to master
`f6359ae80659c43cc847223278ff9ec808b7ee19`; all four changed files were
identical between these bases before applying the patch. No rebuild was
performed after this move.
    - Formatting, build hygiene, and `git diff --check` passed.
- Behavior changed:
- [x] Yes. NULL subarrays contribute no elements to the flattened
result.
- Does this need documentation?
    - [x] No.

### Check List (For Reviewer who merge this PR)

- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
@github-actions
github-actions Bot requested a review from yiguolei as a code owner October 23, 2026 10:51
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

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