arina-ielchiieva commented on a change in pull request #1914: DRILL-7458: Base 
framework for storage plugins
URL: https://github.com/apache/drill/pull/1914#discussion_r368564310
 
 

 ##########
 File path: 
exec/java-exec/src/test/java/org/apache/drill/exec/store/base/DummyFilterPushDownListener.java
 ##########
 @@ -0,0 +1,106 @@
+/*
+ * 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.drill.exec.store.base;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.ops.OptimizerRulesContext;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.store.StoragePluginOptimizerRule;
+import org.apache.drill.exec.store.base.filter.DisjunctionFilterSpec;
+import org.apache.drill.exec.store.base.filter.FilterPushDownListener;
+import org.apache.drill.exec.store.base.filter.FilterPushDownStrategy;
+import org.apache.drill.exec.store.base.filter.FilterSpec;
+import org.apache.drill.exec.store.base.filter.RelOp;
+
+public class DummyFilterPushDownListener implements FilterPushDownListener {
+
+  private final DummyStoragePluginConfig config;
+
+  public DummyFilterPushDownListener(DummyStoragePluginConfig config) {
+    this.config = config;
+  }
+
+  public static Set<StoragePluginOptimizerRule> rulesFor(
+      OptimizerRulesContext optimizerRulesContext, DummyStoragePluginConfig 
config) {
+    return FilterPushDownStrategy.rulesFor(optimizerRulesContext,
+        new DummyFilterPushDownListener(config));
+  }
+
+  @Override
+  public String prefix() { return "Dummy"; }
+
+  @Override
+  public boolean isTargetScan(GroupScan groupScan) {
+    return groupScan instanceof DummyGroupScan;
+  }
+
+  @Override
+  public boolean needsApplication(GroupScan groupScan) {
+    DummyGroupScan dummyScan = (DummyGroupScan) groupScan;
+    return !dummyScan.hasFilters();
+  }
+
+  @Override
+  public RelOp accept(GroupScan groupScan, RelOp relOp) {
+
+    // Determine if filter applies to this scan
+
+    DummyGroupScan dummyScan = (DummyGroupScan) groupScan;
+    return dummyScan.acceptFilter(relOp);
+  }
+
+  @Override
+  public Pair<GroupScan, List<RexNode>> transform(GroupScan groupScan,
+      List<Pair<RexNode, RelOp>> andTerms, Pair<RexNode, 
DisjunctionFilterSpec> orTerm) {
+    List<RelOp> andExprs;
+    if (andTerms == null || andTerms.isEmpty()) {
+      andExprs = null;
+    } else {
+      andExprs = andTerms.stream().map(t -> 
t.right).collect(Collectors.toList());
+    }
+    DisjunctionFilterSpec orExprs;
+    if (orTerm == null) {
+      orExprs = null;
+    } else {
+      orExprs = orTerm.right;
+    }
+    FilterSpec filters = FilterSpec.build(andExprs, orExprs);
+    DummyGroupScan dummyScan = (DummyGroupScan) groupScan;
+    GroupScan newScan = new DummyGroupScan(dummyScan, filters);
+
+    List<RexNode> exprs;
+    if (config.keepFilters()) {
+      exprs = new ArrayList<>();
+      if (andTerms != null) {
+        exprs.addAll(andTerms.stream().map(t -> 
t.left).collect(Collectors.toList()));
 
 Review comment:
   ```suggestion
           exprs.addAll(andTerms.stream()
            .map(t -> t.left)
            .collect(Collectors.toList()));
   ```
   Chaining is usually written from the new line.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to