drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amansi...@apache.org
Subject drill git commit: DRILL-1729: derive & infer result type for boolean returning custom functions so that optiq can validate and execute user queries seamlessly
Date Fri, 28 Nov 2014 20:25:02 GMT
Repository: drill
Updated Branches:
  refs/heads/master 3119011df -> daaa0c35e


DRILL-1729: derive & infer result type for boolean returning custom functions so that
optiq can validate and execute user queries seamlessly


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/daaa0c35
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/daaa0c35
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/daaa0c35

Branch: refs/heads/master
Commit: daaa0c35ee320c977bee7cc315c6428815388d00
Parents: 3119011
Author: Hanifi Gunes <hgunes@maprtech.com>
Authored: Wed Nov 26 16:57:28 2014 -0800
Committer: Aman Sinha <asinha@maprtech.com>
Committed: Fri Nov 28 11:58:00 2014 -0800

----------------------------------------------------------------------
 .../exec/expr/fn/DrillFunctionRegistry.java     | 11 +++---
 .../exec/planner/sql/DrillSqlOperator.java      | 33 +++++++++++++++-
 .../fn/impl/TestSimpleRepeatedFunctions.java    | 40 ++++++++++++++++++++
 3 files changed, 77 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/daaa0c35/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
index 399f302..27cd6dc 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
@@ -23,6 +23,7 @@ import java.util.Map.Entry;
 import java.util.Set;
 
 import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.types.TypeProtos;
 import org.apache.drill.common.util.PathScanner;
 import org.apache.drill.exec.ExecConstants;
 import org.apache.drill.exec.expr.DrillFunc;
@@ -73,12 +74,12 @@ public class DrillFunctionRegistry {
     for (Entry<String, Collection<DrillFuncHolder>> function : methods.asMap().entrySet())
{
       Set<Integer> argCounts = Sets.newHashSet();
       String name = function.getKey().toUpperCase();
-      for (DrillFuncHolder f : function.getValue()) {
-        if (argCounts.add(f.getParamCount())) {
-          if (f.isAggregating()) {
-            op = new DrillSqlAggOperator(name, f.getParamCount());
+      for (DrillFuncHolder func : function.getValue()) {
+        if (argCounts.add(func.getParamCount())) {
+          if (func.isAggregating()) {
+            op = new DrillSqlAggOperator(name, func.getParamCount());
           } else {
-            op = new DrillSqlOperator(name, f.getParamCount());
+            op = new DrillSqlOperator(name, func.getParamCount(), func.getReturnType());
           }
           operatorTable.add(function.getKey(), op);
         }

http://git-wip-us.apache.org/repos/asf/drill/blob/daaa0c35/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java
index 55a8595..d9fc997 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java
@@ -18,11 +18,16 @@
 
 package org.apache.drill.exec.planner.sql;
 
+import com.google.common.base.Preconditions;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.eigenbase.reltype.RelDataType;
+import org.eigenbase.reltype.RelDataTypeFactory;
 import org.eigenbase.sql.SqlCall;
 import org.eigenbase.sql.SqlFunction;
 import org.eigenbase.sql.SqlFunctionCategory;
 import org.eigenbase.sql.SqlIdentifier;
+import org.eigenbase.sql.SqlOperatorBinding;
 import org.eigenbase.sql.parser.SqlParserPos;
 import org.eigenbase.sql.type.SqlTypeName;
 import org.eigenbase.sql.validate.SqlValidator;
@@ -31,14 +36,38 @@ import org.eigenbase.sql.validate.SqlValidatorScope;
 public class DrillSqlOperator extends SqlFunction {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillSqlOperator.class);
 
+  private static final MajorType NONE = MajorType.getDefaultInstance();
+  private final MajorType returnType;
+
   public DrillSqlOperator(String name, int argCount) {
+    this(name, argCount, MajorType.getDefaultInstance());
+  }
+
+  public DrillSqlOperator(String name, int argCount, MajorType returnType) {
     super(new SqlIdentifier(name, SqlParserPos.ZERO), DynamicReturnType.INSTANCE, null, new
Checker(argCount), null, SqlFunctionCategory.USER_DEFINED_FUNCTION);
+    this.returnType = Preconditions.checkNotNull(returnType);
+  }
+
+  protected RelDataType getReturnDataType(final RelDataTypeFactory factory) {
+    if (MinorType.BIT.equals(returnType.getMinorType())) {
+      return factory.createSqlType(SqlTypeName.BOOLEAN);
+    }
+    return factory.createSqlType(SqlTypeName.ANY);
   }
 
   @Override
   public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall
call) {
-    return validator.getTypeFactory().createSqlType(SqlTypeName.ANY);
-//    return new RelDataTypeDrillImpl(new RelDataTypeHolder(), validator.getTypeFactory());
+    if (NONE.equals(returnType)) {
+      return validator.getTypeFactory().createSqlType(SqlTypeName.ANY);
+    }
+    return getReturnDataType(validator.getTypeFactory());
   }
 
+  @Override
+  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
+    if (NONE.equals(returnType)) {
+      return super.inferReturnType(opBinding);
+    }
+    return getReturnDataType(opBinding.getTypeFactory());
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/daaa0c35/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestSimpleRepeatedFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestSimpleRepeatedFunctions.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestSimpleRepeatedFunctions.java
new file mode 100644
index 0000000..8c75feb
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestSimpleRepeatedFunctions.java
@@ -0,0 +1,40 @@
+/**
+ * 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.expr.fn.impl;
+
+import org.apache.drill.PlanTestBase;
+import org.junit.Test;
+
+public class TestSimpleRepeatedFunctions extends PlanTestBase {
+
+  @Test
+  public void testIfDrillCanInferReturnTypeOfRepeatedContains() throws Exception {
+    final String sql = "select t.arrayval from cp.`nested/nested_1.json` t where repeated_CoNTaInS(t.arrayval,
'c1')";
+    final int count = testSql(sql);
+    assert count == 1 : "Unexpected number of records";
+  }
+
+  @Test
+  public void testIfDrillCanInferReturnTypeOfRepeatedContainsPreceedingTrue() throws Exception
{
+    final String sql = "select t.arrayval from cp.`nested/nested_1.json` t where true and
repeated_CoNTaInS(t.arrayval, 'a1')";
+    final int count = testSql(sql);
+    assert count == 1 : "Unexpected number of records";
+  }
+
+
+}


Mime
View raw message