jaredmdobson opened a new issue, #70448:
URL: https://github.com/apache/doris/issues/70448

   ### Search before asking
   - [x] I searched the issues and found no similar issues.
   
   ### Version
   4.1.5 (apache/doris:fe-4.1.5 / be-4.1.5 images)
   
   ### What's wrong?
   Wrong result. A lambda expression over the nullable side of a `LEFT JOIN` is 
evaluated below the join, so NULL-extended rows get NULL instead of the 
expression's value. The same expression without a lambda is correct.
   
   `EXPLAIN SHAPE PLAN` shows the projection holding `array_filter(...)` placed 
under the join, on the scan of `b`:
   
   ```
   PhysicalResultSink
   --PhysicalProject
   ----hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((a.id = b.id)) 
otherCondition=()
   ------PhysicalProject
   --------PhysicalOlapScan[a]
   ------PhysicalProject
   --------PhysicalOlapScan[b]
   ```
   
   ### What you expected to happen
   Row 2 (no match in `b`): `filtered = ["n"]` and `mapped = ["N"]`, the same 
as `plain` and as the expression over a NULL literal (`SELECT array_filter(x -> 
x != '', IF(NULL IS NULL, ['n'], NULL))` returns `["n"]`).
   
   Actual:
   ```
   id  plain       filtered  mapped
   1   ["p", ""]   ["p"]     ["P", ""]
   2   ["n"]       NULL      NULL
   ```
   
   ### How to reproduce
   ```sql
   DROP DATABASE IF EXISTS lambda_null FORCE;
   CREATE DATABASE lambda_null;
   USE lambda_null;
   CREATE TABLE a (id INT) DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1 
PROPERTIES ("replication_num" = "1");
   CREATE TABLE b (id INT, arr ARRAY<STRING>) DUPLICATE KEY(id) DISTRIBUTED BY 
HASH(id) BUCKETS 1 PROPERTIES ("replication_num" = "1");
   INSERT INTO a VALUES (1), (2);
   INSERT INTO b VALUES (1, ['p', '']);
   SELECT a.id,
          IF(b.arr IS NULL, ['n'], b.arr)                                AS 
plain,
          array_filter(x -> x != '', IF(b.arr IS NULL, ['n'], b.arr))    AS 
filtered,
          array_map(x -> upper(x), IF(b.arr IS NULL, ['n'], b.arr))      AS 
mapped
   FROM a LEFT JOIN b ON b.id = a.id
   ORDER BY a.id;
   ```
   
   ### Anything Else?
   Possibly related to #70447 (the lambda argument slot is a 
`SlotNotFromChildren`, so the expression may look like it only reads `b`). 
Workaround: no lambda, e.g. `array_remove(arr, '')` instead of `array_filter(x 
-> x != '', arr)`.
   
   ### Are you willing to submit PR?
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   - [x] I agree to follow this project's Code of Conduct
   


-- 
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