jinxing64 commented on a change in pull request #1500: [CALCITE-3405] Prune 
columns for ProjectableFilterableTable when Proj…
URL: https://github.com/apache/calcite/pull/1500#discussion_r334742410
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java
 ##########
 @@ -103,30 +106,47 @@ protected static boolean test(TableScan scan) {
   protected void apply(RelOptRuleCall call, Project project, TableScan scan) {
     final RelOptTable table = scan.getTable();
     assert table.unwrap(ProjectableFilterableTable.class) != null;
-    if (!project.isMapping()) {
-      return;
-    }
-    final Mappings.TargetMapping mapping = Project.getPartialMapping(
-            project.getInput().getRowType().getFieldCount(),
-            project.getProjects());
 
-    final ImmutableIntList projects;
-    final ImmutableList<RexNode> filters;
+    final List<Integer> selectedColumns = new ArrayList<>();
+    project.getProjects().forEach(proj -> {
+      proj.accept(new RexVisitorImpl<Void>(true) {
+        public Void visitInputRef(RexInputRef inputRef) {
+          if (!selectedColumns.contains(inputRef.getIndex())) {
+            selectedColumns.add(inputRef.getIndex());
+          }
+          return null;
+        }
+      });
+    });
 
 Review comment:
   Well, I was also thinking about this ~
   The concern here is that the order of selected fields will be lost if using 
`InputFinder` and record by bit set.
   If the order of selected fields for pushing down is lost, we have to add 
another `Project` on top of `BindableTableScan` for adjusting. 
   `ScannableTableTest#testPushSimpleMappingProject` is to test such case.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to