github-actions[bot] commented on code in PR #69340:
URL: https://github.com/apache/doris/pull/69340#discussion_r4326700781


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathExpressionCollector.java:
##########
@@ -576,11 +576,32 @@ public Void visitArrayMap(ArrayMap arrayMap, 
CollectorContext context) {
 
         Expression argument = arrayMap.getArgument(0);
         if ((argument instanceof Lambda)) {
-            return collectArrayPathInLambda((Lambda) argument, context);
+            Lambda lambda = (Lambda) argument;
+            return collectArrayMapPathInLambda(lambda, context);
         }
         return visit(arrayMap, context);
     }
 
+    private Void collectArrayMapPathInLambda(Lambda lambda, CollectorContext 
context) {
+        if (context.getType() == ColumnAccessPathType.META) {
+            // A metadata requirement on the ARRAY_MAP result (OFFSET for 
cardinality(), NULL for
+            // IS NULL) describes the output ARRAY container, not the lambda 
elements. The output
+            // container is shaped by the input arrays: array_map copies the 
first input's offsets
+            // and its null map is the union of all inputs' null maps. Pushing 
that context into
+            // the lambda body would attach the metadata to the element layer 
instead, producing
+            // e.g. `arr.*.OFFSET`, which the BE rejects for a struct element 
(OFFSET metadata is
+            // only supported at array/map/string level). Route the container 
metadata to the
+            // input arrays, and collect the element paths the lambda actually 
reads with a fresh
+            // data context so that the elements stay available to the lambda 
body.
+            for (ArrayItemReference lambdaArgument : 
lambda.getLambdaArguments()) {
+                continueCollectAccessPath(lambdaArgument.getArrayExpression(), 
copyContext(context));

Review Comment:
   [P1] Limit container metadata routing to root-level requests
   
   A META context can describe an output element rather than the ARRAY_MAP 
container. For example, with `a ARRAY<STRUCT<v:INT>>`, this valid query reaches 
this method:
   
   ```text
   Project(cardinality(element_at(array_map(x -> array(x.v), a), 1)))
     Scan(a: ARRAY<STRUCT<v:INT>>)
   ```
   
   `visitCardinality` creates `[OFFSET]` and `visitElementAt` prepends `*`, so 
the incoming context is META `[*, OFFSET]`. This loop forwards it directly to 
`a`, emitting `a.*.OFFSET` alongside the lambda's DATA `a.*.v`. 
`NestedColumnPruning.buildColumnAccessPaths` retains both, and the BE struct 
reader rejects the typed OFFSET path with E-3110 before DATA access can 
override it. Previously `collectArrayPathInLambda` stripped the leading `*` and 
the `array(x.v)` body reset to DATA, collecting only the valid `a.*.v` path.
   
   Only unprefixed `[OFFSET]` / `[NULL]` requests describe the root container. 
Restrict this branch accordingly and preserve lambda traversal for descendant 
metadata; add a regression with a selected ARRAY_MAP result whose element type 
differs from the input.



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