morrySnow opened a new pull request, #67742:
URL: https://github.com/apache/doris/pull/67742

   ## Problem
   
   Valid HAVING predicates were rejected when a lambda function consumed an
   aggregate result. Both map and array forms failed because the analyzer 
treated
   the lambda's local parameters as ungrouped table columns.
   
   ## Root cause
   
   Lambda parameters are represented by `ArrayItemSlot`, which extends
   `SlotReference`. `FillUpMissingSlots.Resolver` recursively visits HAVING
   expressions and applied normal GROUP BY validation to every `SlotReference`,
   including these lambda-local slots. They are bound by their
   `ArrayItemReference` and are not inputs from the aggregate child; the general
   expression input-slot collector already excludes them for the same reason.
   
   ## Reproduction
   
   ```sql
   SELECT id, COUNT(*) AS n
   FROM (SELECT 1 id UNION ALL SELECT 1 id) t
   GROUP BY id
   HAVING map_exists((k, v) -> v > 1, map(1, COUNT(*)));
   
   SELECT id, COUNT(*) AS n
   FROM (SELECT 1 id UNION ALL SELECT 1 id) t
   GROUP BY id
   HAVING array_match_any(array_map(x -> x > 1, array(COUNT(*))));
   ```
   
   The map query reported an internal map-entry parameter as ungrouped, and the
   array query reported `x` as ungrouped. Both should return `(1, 2)`.
   
   ## Fix
   
   Skip `ArrayItemSlot` at the missing-slot resolver entry point. The lambda
   binder owns these local slots, so no aggregate output or GROUP BY validation
   is needed for them. Ordinary `SlotReference` handling is unchanged, and a
   real ungrouped input column inside the surrounding expression is still
   rejected.
   
   ## Tests
   
   - Added analyzer coverage for both map and array lambda parameters in HAVING.
   - Added a negative analyzer case proving an ordinary ungrouped input remains
     rejected.
   - Added execution-level regression coverage for both valid queries and the
     invalid-column boundary.
   - Focused FE tests passed: 13 tests, 0 failures.
   - Regression suite passed: 1 suite, 0 failed suites.
   - Sandbox verification returned `(1, 2)` for both valid queries and preserved
     the expected GROUP BY error for `ungrouped_col`.
   
   Issue Number: None
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to