shanzi opened a new pull request, #29985:
URL: https://github.com/apache/flink/pull/29985

   ## What is the purpose of the change
   
   Fixes [FLINK-41524](https://issues.apache.org/jira/browse/FLINK-41524). When 
a `WHERE` predicate accesses a field two or more levels deep on the result of a 
function call (e.g. `COALESCE(r1, r2).a.b = 'x'`) and the source implements 
`SupportsFilterPushDown`, the planner rewrites the predicate into `r1 = 'x'`. 
The rewritten predicate is pushed to the source, kept as the remaining filter, 
and `r2` is pruned from the scan, so the query silently returns wrong results.
   
   `RexNodeToExpressionConverter.visitFieldAccess` only rejected a field access 
whose *immediate* base is a `RexCall`. For `f(x).a.b` the immediate base is the 
field access `f(x).a`, so the guard passed. `NestedProjectionUtil.build` then 
returned a schema made of the call's operands, and the converter built a 
`NestedFieldReferenceExpression` for the first operand (`r1`) with the type of 
the original access.
   
   ## Brief change log
   
     - `RexNodeToExpressionConverter.visitFieldAccess` now follows the field 
access chain down to its base and only converts the expression when that base 
is a `RexInputRef`. Accesses on function results, map/array items, or any other 
base are left untouched, so the predicate stays in the `Calc` above the scan.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Added plan tests in `PushFilterIntoTableSourceScanRuleTest`:
       - `testNestedFilterOnFunctionResult`: `COALESCE(r1, r2).a.b = 'x'` is no 
longer pushed down or rewritten, and `r2` is not pruned. Fails without the fix.
       - `testNestedFilterOnFunctionResultMixedWithPushableFilter`: combined 
with `r1.a.b = 'y'`, only the latter is pushed down. Fails without the fix.
       - `testNestedFilterOnFunctionResultSingleLevel`: the single-level case 
`COALESCE(r1, r2).a`, which was already handled, still is.
     - `PushFilterIntoTableSourceScanRuleTest`, 
`PushFilterInCalcIntoTableSourceRuleTest`, 
`PushProjectIntoTableSourceScanRuleTest` and `RexNodeExtractorTest` pass.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Claude Opus 5.5)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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

Reply via email to