arina-ielchiieva commented on a change in pull request #1619: DRILL-6910: Allow 
applying DrillPushProjectIntoScanRule at physical phase
URL: https://github.com/apache/drill/pull/1619#discussion_r250143587
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushProjectIntoScanRule.java
 ##########
 @@ -43,51 +49,75 @@
   public static final RelOptRule INSTANCE =
       new DrillPushProjectIntoScanRule(LogicalProject.class,
           EnumerableTableScan.class,
-          "DrillPushProjIntoEnumerableScan");
+          "DrillPushProjIntoEnumerableScan") {
+
+        @Override
+        protected boolean skipScanConversion(RelDataType projectRelDataType, 
TableScan scan) {
+          // do not allow skipping conversion of EnumerableTableScan to 
DrillScanRel if rule is applicable
+          return false;
+        }
+      };
 
   public static final RelOptRule DRILL_LOGICAL_INSTANCE =
       new DrillPushProjectIntoScanRule(LogicalProject.class,
           DrillScanRel.class,
           "DrillPushProjIntoDrillRelScan");
 
+  public static final RelOptRule DRILL_PHYSICAL_INSTANCE =
+      new DrillPushProjectIntoScanRule(ProjectPrel.class,
+          ScanPrel.class,
+          "DrillPushProjIntoScanPrel") {
+
+        @Override
+        protected ScanPrel createScan(TableScan scan, ProjectPushInfo 
projectPushInfo) {
+          ScanPrel drillScan = (ScanPrel) scan;
+
+          return new ScanPrel(drillScan.getCluster(),
+              drillScan.getTraitSet().plus(Prel.DRILL_PHYSICAL),
+              drillScan.getGroupScan().clone(projectPushInfo.getFields()),
+              
projectPushInfo.createNewRowType(drillScan.getCluster().getTypeFactory()),
+              drillScan.getTable());
+        }
+
+        @Override
+        protected ProjectPrel createProject(Project project, TableScan 
newScan, List<RexNode> newProjects) {
+          return new ProjectPrel(project.getCluster(),
+              project.getTraitSet().plus(Prel.DRILL_PHYSICAL),
+              newScan,
+              newProjects,
+              project.getRowType());
+        }
+      };
+
   private DrillPushProjectIntoScanRule(Class<? extends Project> projectClass, 
Class<? extends TableScan> scanClass, String description) {
     super(RelOptHelper.some(projectClass, RelOptHelper.any(scanClass)), 
description);
   }
 
   @Override
   public void onMatch(RelOptRuleCall call) {
-    final Project project = call.rel(0);
-    final TableScan scan = call.rel(1);
+    Project project = call.rel(0);
+    TableScan scan = call.rel(1);
 
     try {
-
       if (scan.getRowType().getFieldList().isEmpty()) {
         return;
       }
 
       ProjectPushInfo projectPushInfo = 
DrillRelOptUtil.getFieldsInformation(scan.getRowType(), project.getProjects());
-      if (!canPushProjectIntoScan(scan.getTable(), projectPushInfo)) {
+      if (!canPushProjectIntoScan(scan.getTable(), projectPushInfo)
+          || 
skipScanConversion(projectPushInfo.createNewRowType(project.getCluster().getTypeFactory()),
 scan)) {
 
 Review comment:
   If we skip project push down into scan because scan and rows types are the 
same, project will be still in plan? or it will be removed by some other rule 
later?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to