You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by cg...@apache.org on 2023/02/28 19:33:19 UTC

[drill] branch master updated: DRILL-8406: Enable Implicit Casting of VARCHAR and BIT args in Aggregate Functions

This is an automated email from the ASF dual-hosted git repository.

cgivre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f3a887de5 DRILL-8406: Enable Implicit Casting of VARCHAR and BIT args in Aggregate Functions
8f3a887de5 is described below

commit 8f3a887de5f1968473289b8f4f68e3d3f05dc259
Author: James Turton <91...@users.noreply.github.com>
AuthorDate: Tue Feb 28 21:33:06 2023 +0200

    DRILL-8406: Enable Implicit Casting of VARCHAR and BIT args in Aggregate Functions
---
 docs/dev/Release.md                                |   4 +-
 .../exec/expr/fn/impl/AggregateErrorFunctions.java | 156 ---------------------
 .../java/org/apache/drill/TestImplicitCasting.java |  17 +++
 3 files changed, 19 insertions(+), 158 deletions(-)

diff --git a/docs/dev/Release.md b/docs/dev/Release.md
index 08d1fa52da..694eef945f 100644
--- a/docs/dev/Release.md
+++ b/docs/dev/Release.md
@@ -255,9 +255,9 @@
 
 
         [1] https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12313820&version=12341087
-        [2] http://home.apache.org/~arina/drill/releases/1.12.0-rc0/
+        [2] https://dist.apache.org/repos/dist/dev/drill/drill-1.17.0-rc0
         [3] https://repository.apache.org/content/repositories/orgapachedrill-1043/
-        [4] https://github.com/arina-ielchiieva/drill/commits/drill-1.12.0
+        [4] https://github.com/arina-ielchiieva/drill/commits/drill-1.17.0
         ```
     3. If the vote fails, cancel RC and prepare new RC:
         1. Send an email with announcing about canceling the vote.
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/AggregateErrorFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/AggregateErrorFunctions.java
deleted file mode 100644
index ec6292d1ed..0000000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/AggregateErrorFunctions.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * 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.exec.expr.DrillAggFunc;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate;
-import org.apache.drill.exec.expr.annotations.Output;
-import org.apache.drill.exec.expr.annotations.Param;
-import org.apache.drill.exec.expr.annotations.Workspace;
-import org.apache.drill.exec.expr.holders.BigIntHolder;
-import org.apache.drill.exec.expr.holders.BitHolder;
-import org.apache.drill.exec.expr.holders.NullableBitHolder;
-import org.apache.drill.exec.expr.holders.NullableVarCharHolder;
-import org.apache.drill.exec.expr.holders.VarCharHolder;
-
-/*
- * TODO: For a handful of functions this approach of using function binding to detect that it is an invalid function is okay.
- * However moving forward we should introduce a validation phase after we learn the data types and before we try
- * to perform function resolution. Otherwise with implicit cast we will try to bind to an existing function.
- */
-public class AggregateErrorFunctions {
-
-  @FunctionTemplate(names = {"sum", "avg", "stddev_pop", "stddev_samp", "stddev", "var_pop",
-      "var_samp", "variance"}, scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
-  public static class BitAggregateErrorFunctions implements DrillAggFunc {
-
-    @Param BitHolder in;
-    @Workspace BigIntHolder value;
-    @Output BigIntHolder out;
-
-    public void setup() {
-      if (true) {
-        throw org.apache.drill.common.exceptions.UserException.unsupportedError()
-          .message("Only COUNT aggregate function supported for Boolean type")
-          .build();
-      }
-    }
-
-    @Override
-    public void add() {
-    }
-
-    @Override
-    public void output() {
-    }
-
-    @Override
-    public void reset() {
-    }
-
-  }
-
-  @FunctionTemplate(names = {"sum", "avg", "stddev_pop", "stddev_samp", "stddev", "var_pop",
-      "var_samp", "variance"}, scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
-  public static class NullableBitAggregateErrorFunctions implements DrillAggFunc {
-
-    @Param NullableBitHolder in;
-    @Workspace BigIntHolder value;
-    @Output BigIntHolder out;
-
-    public void setup() {
-      if (true) {
-        throw org.apache.drill.common.exceptions.UserException.unsupportedError()
-          .message("Only COUNT aggregate function supported for Boolean type")
-          .build();
-      }
-    }
-
-    @Override
-    public void add() {
-    }
-
-    @Override
-    public void output() {
-    }
-
-    @Override
-    public void reset() {
-    }
-  }
-
-
-  @FunctionTemplate(names = {"sum", "avg", "stddev_pop", "stddev_samp", "stddev", "var_pop", "var_samp", "variance"},
-      scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
-  public static class VarCharAggregateErrorFunctions implements DrillAggFunc {
-
-    @Param VarCharHolder in;
-    @Workspace BigIntHolder value;
-    @Output BigIntHolder out;
-
-    public void setup() {
-      if (true) {
-        throw org.apache.drill.common.exceptions.UserException.unsupportedError()
-          .message("Only COUNT, MIN and MAX aggregate functions supported for VarChar type")
-          .build();
-      }
-    }
-
-    @Override
-    public void add() {
-    }
-
-    @Override
-    public void output() {
-    }
-
-    @Override
-    public void reset() {
-    }
-
-  }
-
-  @FunctionTemplate(names = {"sum", "avg", "stddev_pop", "stddev_samp", "stddev", "var_pop", "var_samp", "variance"},
-      scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
-  public static class NullableVarCharAggregateErrorFunctions implements DrillAggFunc {
-
-    @Param NullableVarCharHolder in;
-    @Workspace BigIntHolder value;
-    @Output BigIntHolder out;
-
-    public void setup() {
-      if (true) {
-        throw org.apache.drill.common.exceptions.UserException.unsupportedError()
-          .message("Only COUNT, MIN and MAX aggregate functions supported for VarChar type")
-          .build();
-      }
-    }
-
-    @Override
-    public void add() {
-    }
-
-    @Override
-    public void output() {
-    }
-
-    @Override
-    public void reset() {
-    }
-  }
-}
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestImplicitCasting.java b/exec/java-exec/src/test/java/org/apache/drill/TestImplicitCasting.java
index a167ce614d..54a0fe738b 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestImplicitCasting.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestImplicitCasting.java
@@ -238,4 +238,21 @@ public class TestImplicitCasting extends ClusterTest {
 
     RowSetUtilities.verify(expected, results);
   }
+
+  @Test
+  public void testAvgOfStrings() throws Exception {
+    String sql = "select avg(cast(employee_id as varchar)) from cp.`employee.json`";
+
+    DirectRowSet results = queryBuilder().sql(sql).rowSet();
+
+    TupleMetadata expectedSchema = new SchemaBuilder()
+      .add("EXPR$0", TypeProtos.MinorType.FLOAT8, TypeProtos.DataMode.OPTIONAL)
+      .build();
+
+    RowSet expected = client.rowSetBuilder(expectedSchema)
+      .addRow(578.9982683982684)
+      .build();
+
+    RowSetUtilities.verify(expected, results);
+  }
 }