calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [1/2] git commit: Covariance function - allow 2 arguments
Date Wed, 01 Oct 2014 18:39:41 GMT
Repository: incubator-optiq
Updated Branches:
  refs/heads/master 7fc4f6e08 -> af86cd87a


Covariance function - allow 2 arguments


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

Branch: refs/heads/master
Commit: d4ab395c3ee346a4d40a44fcb949eab2d5d11171
Parents: 7fc4f6e
Author: Yash Sharma <yash.sharma@snapdeal.com>
Authored: Sun Sep 28 18:15:15 2014 +0530
Committer: Julian Hyde <jhyde@apache.org>
Committed: Wed Oct 1 00:39:18 2014 -0700

----------------------------------------------------------------------
 .../eigenbase/sql/fun/SqlAvgAggFunction.java    |  2 -
 .../eigenbase/sql/fun/SqlCovarAggFunction.java  | 93 ++++++++++++++++++++
 .../eigenbase/sql/fun/SqlStdOperatorTable.java  |  4 +-
 .../sql2rel/StandardConvertletTable.java        |  6 --
 .../eigenbase/sql/test/SqlOperatorBaseTest.java | 16 ++--
 5 files changed, 103 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/d4ab395c/core/src/main/java/org/eigenbase/sql/fun/SqlAvgAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eigenbase/sql/fun/SqlAvgAggFunction.java b/core/src/main/java/org/eigenbase/sql/fun/SqlAvgAggFunction.java
index 05f9636..8a6bfe7 100644
--- a/core/src/main/java/org/eigenbase/sql/fun/SqlAvgAggFunction.java
+++ b/core/src/main/java/org/eigenbase/sql/fun/SqlAvgAggFunction.java
@@ -79,8 +79,6 @@ public class SqlAvgAggFunction extends SqlAggFunction {
 
   public enum Subtype {
     AVG,
-    COVAR_POP,
-    COVAR_SAMP,
     STDDEV_POP,
     STDDEV_SAMP,
     VAR_POP,

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/d4ab395c/core/src/main/java/org/eigenbase/sql/fun/SqlCovarAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eigenbase/sql/fun/SqlCovarAggFunction.java b/core/src/main/java/org/eigenbase/sql/fun/SqlCovarAggFunction.java
new file mode 100644
index 0000000..77d7dbf
--- /dev/null
+++ b/core/src/main/java/org/eigenbase/sql/fun/SqlCovarAggFunction.java
@@ -0,0 +1,93 @@
+/*
+ * 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.eigenbase.sql.fun;
+
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.eigenbase.reltype.RelDataType;
+import org.eigenbase.reltype.RelDataTypeFactory;
+import org.eigenbase.sql.SqlAggFunction;
+import org.eigenbase.sql.SqlFunctionCategory;
+import org.eigenbase.sql.SqlKind;
+import org.eigenbase.sql.type.OperandTypes;
+import org.eigenbase.sql.type.ReturnTypes;
+
+
+/**
+ * <code>Covar</code> is an aggregator which returns the Covariance of the
+ * values which go into it. It has precisely two arguments of numeric type
+ * (<code>int</code>, <code>long</code>, <code>float</code>,
<code>
+ * double</code>), and the result is the same type.
+ */
+public class SqlCovarAggFunction extends SqlAggFunction {
+  //~ Instance fields --------------------------------------------------------
+
+  private final RelDataType type;
+  private final Subtype subtype;
+
+  //~ Constructors -----------------------------------------------------------
+
+  /**
+   * Creates a SqlAvgAggFunction
+   *
+   * @param type    Data type
+   * @param subtype Specific function, e.g. AVG or STDDEV_POP
+   */
+  public SqlCovarAggFunction(
+          RelDataType type,
+          Subtype subtype) {
+    super(
+        subtype.name(),
+        SqlKind.OTHER_FUNCTION,
+        ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
+        null,
+        OperandTypes.NUMERIC_NUMERIC,
+        SqlFunctionCategory.NUMERIC);
+    this.type = type;
+    this.subtype = subtype;
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
+    return ImmutableList.of(type);
+  }
+
+  public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
+    return type;
+  }
+
+  /**
+   * Returns the specific function, e.g. COVAR_POP or COVAR_SAMP.
+   *
+   * @return Subtype
+   */
+  public Subtype getSubtype() {
+    return subtype;
+  }
+
+/**
+ * Enum for defining specific types.
+ */
+  public enum Subtype {
+    COVAR_POP,
+    COVAR_SAMP
+  }
+}
+
+// End SqlCovarAggFunction.java

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/d4ab395c/core/src/main/java/org/eigenbase/sql/fun/SqlStdOperatorTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eigenbase/sql/fun/SqlStdOperatorTable.java b/core/src/main/java/org/eigenbase/sql/fun/SqlStdOperatorTable.java
index c4e871c..e46cc3f 100644
--- a/core/src/main/java/org/eigenbase/sql/fun/SqlStdOperatorTable.java
+++ b/core/src/main/java/org/eigenbase/sql/fun/SqlStdOperatorTable.java
@@ -675,13 +675,13 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable
{
    * <code>COVAR_POP</code> aggregate function.
    */
   public static final SqlAggFunction COVAR_POP =
-      new SqlAvgAggFunction(null, SqlAvgAggFunction.Subtype.COVAR_POP);
+      new SqlCovarAggFunction(null, SqlCovarAggFunction.Subtype.COVAR_POP);
 
   /**
    * <code>COVAR_SAMP</code> aggregate function.
    */
   public static final SqlAggFunction COVAR_SAMP =
-      new SqlAvgAggFunction(null, SqlAvgAggFunction.Subtype.COVAR_SAMP);
+      new SqlCovarAggFunction(null, SqlCovarAggFunction.Subtype.COVAR_SAMP);
 
   /**
    * <code>STDDEV_SAMP</code> aggregate function.

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/d4ab395c/core/src/main/java/org/eigenbase/sql2rel/StandardConvertletTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eigenbase/sql2rel/StandardConvertletTable.java b/core/src/main/java/org/eigenbase/sql2rel/StandardConvertletTable.java
index 7e23f93..59b48d7 100644
--- a/core/src/main/java/org/eigenbase/sql2rel/StandardConvertletTable.java
+++ b/core/src/main/java/org/eigenbase/sql2rel/StandardConvertletTable.java
@@ -173,12 +173,6 @@ public class StandardConvertletTable extends ReflectiveConvertletTable
{
         SqlStdOperatorTable.AVG,
         new AvgVarianceConvertlet(SqlAvgAggFunction.Subtype.AVG));
     registerOp(
-        SqlStdOperatorTable.COVAR_POP,
-        new AvgVarianceConvertlet(SqlAvgAggFunction.Subtype.COVAR_POP));
-    registerOp(
-        SqlStdOperatorTable.COVAR_SAMP,
-        new AvgVarianceConvertlet(SqlAvgAggFunction.Subtype.COVAR_SAMP));
-    registerOp(
         SqlStdOperatorTable.STDDEV_POP,
         new AvgVarianceConvertlet(SqlAvgAggFunction.Subtype.STDDEV_POP));
     registerOp(

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/d4ab395c/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java
index b1118b2..c04bec2 100644
--- a/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java
+++ b/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java
@@ -4484,11 +4484,11 @@ public abstract class SqlOperatorBaseTest {
         "Unknown identifier '\\*'",
         false);
     tester.checkFails(
-        "^covar_pop(cast(null as varchar(2)))^",
-        "(?s)Cannot apply 'COVAR_POP' to arguments of type 'COVAR_POP\\(<VARCHAR\\(2\\)>\\)'\\.
Supported form\\(s\\): 'COVAR_POP\\(<NUMERIC>\\)'.*",
+        "^covar_pop(cast(null as varchar(2)),cast(null as varchar(2)))^",
+        "(?s)Cannot apply 'COVAR_POP' to arguments of type 'COVAR_POP\\(<VARCHAR\\(2\\)>,
<VARCHAR\\(2\\)>\\)'\\. Supported form\\(s\\): 'COVAR_POP\\(<NUMERIC>, <NUMERIC>\\)'.*",
         false);
-    tester.checkType("covar_pop(CAST(NULL AS INTEGER))", "INTEGER");
-    checkAggType(tester, "covar_pop(DISTINCT 1.5)", "DECIMAL(2, 1) NOT NULL");
+    tester.checkType("covar_pop(CAST(NULL AS INTEGER),CAST(NULL AS INTEGER))", "INTEGER");
+    checkAggType(tester, "covar_pop(1.5, 2.5)", "DECIMAL(2, 1) NOT NULL");
     if (!enable) {
       return;
     }
@@ -4507,11 +4507,11 @@ public abstract class SqlOperatorBaseTest {
         "Unknown identifier '\\*'",
         false);
     tester.checkFails(
-        "^covar_samp(cast(null as varchar(2)))^",
-        "(?s)Cannot apply 'COVAR_SAMP' to arguments of type 'COVAR_SAMP\\(<VARCHAR\\(2\\)>\\)'\\.
Supported form\\(s\\): 'COVAR_SAMP\\(<NUMERIC>\\)'.*",
+        "^covar_samp(cast(null as varchar(2)),cast(null as varchar(2)))^",
+        "(?s)Cannot apply 'COVAR_SAMP' to arguments of type 'COVAR_SAMP\\(<VARCHAR\\(2\\)>,
<VARCHAR\\(2\\)>\\)'\\. Supported form\\(s\\): 'COVAR_SAMP\\(<NUMERIC>, <NUMERIC>\\)'.*",
         false);
-    tester.checkType("covar_samp(CAST(NULL AS INTEGER))", "INTEGER");
-    checkAggType(tester, "covar_samp(DISTINCT 1.5)", "DECIMAL(2, 1) NOT NULL");
+    tester.checkType("covar_samp(CAST(NULL AS INTEGER),CAST(NULL AS INTEGER))", "INTEGER");
+    checkAggType(tester, "covar_samp(1.5, 2.5)", "DECIMAL(2, 1) NOT NULL");
     if (!enable) {
       return;
     }


Mime
View raw message