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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java:
##########
@@ -44,11 +44,9 @@ public class LogicalOlapScanToPhysicalOlapScan extends 
OneImplementationRuleFact
     public Rule build() {
         return logicalOlapScan().then(olapScan ->
             new PhysicalOlapScan(
-                olapScan.getTable(),
-                olapScan.getQualifier(),
-                olapScan.getSelectedIndexId(),
-                olapScan.getSelectedTabletId(),
-                olapScan.getSelectedPartitionId(),
+                olapScan.getTable(), olapScan.getQualifier(), 
olapScan.getSelectedIndexId(),
+                    olapScan.getSelectedTabletId(),
+                    olapScan.getSelectedPartitionIds(),

Review Comment:
   ```suggestion
                   olapScan.getTable(),
                   olapScan.getQualifier(),
                   olapScan.getSelectedIndexId(),
                   olapScan.getSelectedTabletId(),
                   olapScan.getSelectedPartitionIds(),
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/SwapFilterAndProject.java:
##########
@@ -0,0 +1,57 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.rewrite.logical;
+
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionReplacer;
+import org.apache.doris.nereids.trees.plans.GroupPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Rewrite filter -> project to project -> filter.
+ */
+public class SwapFilterAndProject extends OneRewriteRuleFactory {
+    @Override
+    public Rule build() {
+        return logicalFilter(logicalProject()).thenApply(ctx -> {
+            LogicalFilter<LogicalProject<GroupPlan>> filter = ctx.root;
+            LogicalProject<GroupPlan> project = filter.child();
+            List<NamedExpression> namedExpressionList = project.getProjects();
+            Map<Expression, Expression> slotToAlias = new HashMap<>();
+            
namedExpressionList.stream().filter(Alias.class::isInstance).forEach(s -> {
+                slotToAlias.put(s.toSlot(), s);

Review Comment:
   ```suggestion
                   slotToAlias.put(s.toSlot(), s.child());
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java:
##########
@@ -42,14 +42,24 @@ public class LogicalOlapScan extends LogicalRelation {
 
     private final long selectedIndexId;
     private final List<Long> selectedTabletId;
-    private final List<Long> selectedPartitionId;
+    private final boolean partitionPruned;
 
     public LogicalOlapScan(OlapTable table) {
         this(table, ImmutableList.of());
     }
 
     public LogicalOlapScan(OlapTable table, List<String> qualifier) {
-        this(table, qualifier, Optional.empty(), Optional.empty());
+        this(table, qualifier,
+                Optional.empty(), Optional.empty(),
+                table.getPartitionIds(), false);
+    }
+
+    public LogicalOlapScan(Table table) {
+        this(table, ImmutableList.of());
+    }

Review Comment:
   remove this constructor pls



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java:
##########
@@ -42,14 +42,24 @@ public class LogicalOlapScan extends LogicalRelation {
 
     private final long selectedIndexId;
     private final List<Long> selectedTabletId;
-    private final List<Long> selectedPartitionId;
+    private final boolean partitionPruned;
 
     public LogicalOlapScan(OlapTable table) {
         this(table, ImmutableList.of());
     }
 
     public LogicalOlapScan(OlapTable table, List<String> qualifier) {
-        this(table, qualifier, Optional.empty(), Optional.empty());
+        this(table, qualifier,
+                Optional.empty(), Optional.empty(),
+                table.getPartitionIds(), false);
+    }
+
+    public LogicalOlapScan(Table table) {
+        this(table, ImmutableList.of());
+    }
+
+    public LogicalOlapScan(Table table, List<String> qualifier) {
+        this(table, qualifier, Optional.empty(), Optional.empty(), 
((OlapTable) table).getPartitionIds(), false);
     }

Review Comment:
   ditto



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/SwapFilterAndProject.java:
##########
@@ -0,0 +1,57 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.rewrite.logical;
+
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionReplacer;
+import org.apache.doris.nereids.trees.plans.GroupPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Rewrite filter -> project to project -> filter.
+ */
+public class SwapFilterAndProject extends OneRewriteRuleFactory {
+    @Override
+    public Rule build() {
+        return logicalFilter(logicalProject()).thenApply(ctx -> {
+            LogicalFilter<LogicalProject<GroupPlan>> filter = ctx.root;
+            LogicalProject<GroupPlan> project = filter.child();
+            List<NamedExpression> namedExpressionList = project.getProjects();
+            Map<Expression, Expression> slotToAlias = new HashMap<>();
+            
namedExpressionList.stream().filter(Alias.class::isInstance).forEach(s -> {
+                slotToAlias.put(s.toSlot(), s);
+            });
+            ExpressionReplacer expressionReplacer = new ExpressionReplacer();
+            Expression rewrittenPredicate = 
expressionReplacer.visit(filter.getPredicates(), slotToAlias);

Review Comment:
   ```suggestion
               Expression rewrittenPredicate = 
ExpressionReplacer.INSTANCE.visit(filter.getPredicates(), slotToAlias);
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java:
##########
@@ -42,14 +42,24 @@ public class LogicalOlapScan extends LogicalRelation {
 
     private final long selectedIndexId;
     private final List<Long> selectedTabletId;
-    private final List<Long> selectedPartitionId;
+    private final boolean partitionPruned;
 
     public LogicalOlapScan(OlapTable table) {
         this(table, ImmutableList.of());
     }
 
     public LogicalOlapScan(OlapTable table, List<String> qualifier) {
-        this(table, qualifier, Optional.empty(), Optional.empty());
+        this(table, qualifier,
+                Optional.empty(), Optional.empty(),
+                table.getPartitionIds(), false);

Review Comment:
   ```suggestion
           this(table, qualifier, Optional.empty(), Optional.empty(), 
table.getPartitionIds(), false);
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java:
##########
@@ -231,7 +231,6 @@ public void setTupleIds(ArrayList<TupleId> tupleIds) {
         this.tupleIds = tupleIds;
     }
 
-    // only used for UT

Review Comment:
   add a comment
   ```
   only used for UT and Nereids
   ```



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to