morrySnow commented on code in PR #58776:
URL: https://github.com/apache/doris/pull/58776#discussion_r2597457584


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathPlanCollector.java:
##########
@@ -56,6 +66,118 @@ public Map<Slot, List<CollectAccessPathResult>> 
collect(Plan root, StatementCont
         return scanSlotToAccessPaths;
     }
 
+    @Override
+    public Void visitLogicalGenerate(LogicalGenerate<? extends Plan> generate, 
StatementContext context) {
+        List<Function> generators = generate.getGenerators();
+        List<Slot> output = generate.getGeneratorOutput();
+
+        AccessPathExpressionCollector exprCollector
+                = new AccessPathExpressionCollector(context, 
allSlotToAccessPaths, false);
+        for (int i = 0; i < output.size(); i++) {
+            Slot generatorOutput = output.get(i);
+            Function function = generators.get(i);
+            Collection<CollectAccessPathResult> accessPaths = 
allSlotToAccessPaths.get(
+                    generatorOutput.getExprId().asInt());
+            if (function instanceof Explode || function instanceof 
ExplodeOuter) {
+                if (accessPaths.isEmpty()) {
+                    // use the whole column
+                    for (Expression child : function.children()) {
+                        exprCollector.collect(child);
+                    }
+                } else {
+                    for (CollectAccessPathResult accessPath : accessPaths) {
+                        List<String> path = accessPath.getPath();
+                        if (function.arity() == 1) {
+                            // $c$1.VALUES.b
+                            CollectorContext argumentContext = new 
CollectorContext(context, false);
+                            argumentContext.setType(accessPath.getType());
+                            argumentContext.getAccessPathBuilder()
+                                    .addSuffix(AccessPathInfo.ACCESS_ALL)
+                                    .addSuffix(path.subList(1, path.size()));
+                            function.child(0).accept(exprCollector, 
argumentContext);
+                            continue;
+                        } else if (path.size() >= 2) {
+                            // $c$1.col1.VALUES.b will be extract 'col1'
+                            String colName = path.get(1);
+                            // extract '1' in 'col1'
+                            int colIndex = 
Integer.parseInt(colName.substring("col".length())) - 1;
+                            CollectorContext argumentContext = new 
CollectorContext(context, false);
+                            argumentContext.setType(accessPath.getType());
+                            argumentContext.getAccessPathBuilder()
+                                    .addSuffix(AccessPathInfo.ACCESS_ALL)
+                                    .addSuffix(path.subList(2, path.size()));
+                            function.child(colIndex).accept(exprCollector, 
argumentContext);
+                            continue;
+                        }
+                        // use the whole column
+                        for (Expression child : function.children()) {
+                            exprCollector.collect(child);
+                        }
+                    }
+                }
+            } else if (function instanceof ExplodeMap || function instanceof 
ExplodeMapOuter) {
+                if (accessPaths.isEmpty()) {
+                    // use the whole column
+                    for (Expression child : function.children()) {
+                        exprCollector.collect(child);
+                    }
+                } else {
+                    for (CollectAccessPathResult accessPath : accessPaths) {
+                        List<String> path = accessPath.getPath();
+                        if (path.size() >= 2) {
+                            if (path.get(1).equalsIgnoreCase("col1")) {

Review Comment:
   same as upper comment



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathPlanCollector.java:
##########
@@ -56,6 +66,118 @@ public Map<Slot, List<CollectAccessPathResult>> 
collect(Plan root, StatementCont
         return scanSlotToAccessPaths;
     }
 
+    @Override
+    public Void visitLogicalGenerate(LogicalGenerate<? extends Plan> generate, 
StatementContext context) {
+        List<Function> generators = generate.getGenerators();
+        List<Slot> output = generate.getGeneratorOutput();
+
+        AccessPathExpressionCollector exprCollector
+                = new AccessPathExpressionCollector(context, 
allSlotToAccessPaths, false);
+        for (int i = 0; i < output.size(); i++) {
+            Slot generatorOutput = output.get(i);
+            Function function = generators.get(i);
+            Collection<CollectAccessPathResult> accessPaths = 
allSlotToAccessPaths.get(
+                    generatorOutput.getExprId().asInt());
+            if (function instanceof Explode || function instanceof 
ExplodeOuter) {
+                if (accessPaths.isEmpty()) {
+                    // use the whole column
+                    for (Expression child : function.children()) {
+                        exprCollector.collect(child);
+                    }
+                } else {
+                    for (CollectAccessPathResult accessPath : accessPaths) {
+                        List<String> path = accessPath.getPath();
+                        if (function.arity() == 1) {
+                            // $c$1.VALUES.b
+                            CollectorContext argumentContext = new 
CollectorContext(context, false);
+                            argumentContext.setType(accessPath.getType());
+                            argumentContext.getAccessPathBuilder()
+                                    .addSuffix(AccessPathInfo.ACCESS_ALL)
+                                    .addSuffix(path.subList(1, path.size()));
+                            function.child(0).accept(exprCollector, 
argumentContext);
+                            continue;
+                        } else if (path.size() >= 2) {
+                            // $c$1.col1.VALUES.b will be extract 'col1'
+                            String colName = path.get(1);
+                            // extract '1' in 'col1'
+                            int colIndex = 
Integer.parseInt(colName.substring("col".length())) - 1;

Review Comment:
   so this rely on the struct field name generation code in Explode? i think we 
should:
   1. add a comment here to link to `Explode` and add a comment in Explode in 
order to prevent breaking this potential dependency.
   2. let `col` be a static variable in `Explode`



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