paul-rogers commented on a change in pull request #1892: Drill-7437: Storage 
Plugin for Generic HTTP REST API
URL: https://github.com/apache/drill/pull/1892#discussion_r352254315
 
 

 ##########
 File path: 
contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpFilterBuilder.java
 ##########
 @@ -0,0 +1,127 @@
+/*
+ * 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.http;
+
+import java.util.List;
+
+import org.apache.drill.common.expression.BooleanOperator;
+import org.apache.drill.common.expression.FunctionCall;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.common.expression.visitors.AbstractExprVisitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HttpFilterBuilder extends
+  AbstractExprVisitor<HttpScanSpec, Void, RuntimeException> {
+  static final Logger logger = 
LoggerFactory.getLogger(HttpFilterBuilder.class);
+  private final HttpGroupScan groupScan;
+  private final LogicalExpression le;
+  private boolean allExpressionsConverted = true;
+
+  public boolean isAllExpressionsConverted() {
+    return allExpressionsConverted;
+  }
+
+  public HttpFilterBuilder(HttpGroupScan groupScan, LogicalExpression 
conditionExp) {
+    this.groupScan = groupScan;
+    this.le = conditionExp;
+    logger.debug("HttpFilterBuilder created");
+  }
+
+  public HttpScanSpec parseTree() {
+    HttpScanSpec parsedSpec = le.accept(this, null);
+    if (parsedSpec != null) {
+      parsedSpec = mergeScanSpecs(this.groupScan.getScanSpec(), parsedSpec);
+    }
+    return parsedSpec;
+  }
+
+  private HttpScanSpec mergeScanSpecs(HttpScanSpec leftScanSpec, HttpScanSpec 
rightScanSpec) {
+    leftScanSpec.merge(rightScanSpec);
+    return leftScanSpec;
+  }
+
+  @Override
+  public HttpScanSpec visitUnknown(LogicalExpression e, Void value)
+    throws RuntimeException {
+    allExpressionsConverted = false;
+    return null;
+  }
+
+  // only process `boolean and` expression
+  // `a and b and c` will call this, and argument size = 3
+  @Override
+  public HttpScanSpec visitBooleanOperator(BooleanOperator op, Void value) {
+    List<LogicalExpression> args = op.args;
+    HttpScanSpec nodeScanSpec = null;
+    String functionName = op.getName();
+    if (!functionName.equals("booleanAnd")) {
+      allExpressionsConverted = false;
+      return nodeScanSpec;
+    }
+    logger.debug("boolean 'and' operator {}", args.size());
+    for (int i = 0; i < args.size(); ++i) {
+      if (nodeScanSpec == null) {
+        nodeScanSpec = args.get(i).accept(this, null);
+      } else {
+        HttpScanSpec scanSpec = args.get(i).accept(this, null);
+        if (scanSpec != null) {
+          nodeScanSpec = mergeScanSpecs(nodeScanSpec, scanSpec);
+        } else {
+          allExpressionsConverted = false;
+        }
+      }
+    }
+    return nodeScanSpec;
+  }
+
+  // only process expression like `$key=value`
+  @Override
+  public HttpScanSpec visitFunctionCall(FunctionCall call, Void value) throws 
RuntimeException {
+    HttpScanSpec nodeScanSpec = null;
+    String functionName = call.getName();
+    logger.debug("visit function call {}", functionName);
+    if (!HttpEqualFunctionProcessor.match(functionName)) {
+      allExpressionsConverted = false;
+      return nodeScanSpec;
+    }
+    HttpEqualFunctionProcessor processor = 
HttpEqualFunctionProcessor.process(call);
+    if (!processor.isSuccess()) {
+      allExpressionsConverted = false;
 
 Review comment:
   Actually, it is not enough to know if all nodes are converted. Consider the 
following:
   
   ```
   ... WHERE x='foo' AND myUDF(y) = 'bar' AND isMumble = true
   ```
   
   We can, perhaps, convert the following to:
   
   ```
   HTTP: ...?foo=bar&isMumble=true
   SQL: WHERE myUDF(y) = 'bar'
   ```
   
   That is, some predicates are pushed, others are left for Drill. (The new 
framework mentioned above handles all this.)

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