You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xi...@apache.org on 2020/08/07 06:43:12 UTC

[incubator-pinot] branch master updated: Support aggregation function name with underscore inside (#5795)

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

xiangfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 48d1653  Support aggregation function name with underscore inside (#5795)
48d1653 is described below

commit 48d1653c012b42f19999b50dc1b5d3039a09eeaa
Author: Xiang Fu <fx...@gmail.com>
AuthorDate: Thu Aug 6 23:43:03 2020 -0700

    Support aggregation function name with underscore inside (#5795)
    
    * Support aggregation function name with underscore inside
    
    * Change ST_Union AggregationType enum to STUnion
    
    * Simplify the handling
    
    Co-authored-by: Xiaotian (Jackie) Jiang <ja...@gmail.com>
---
 .../common/function/AggregationFunctionType.java    | 13 ++++++++++---
 .../function/AggregationFunctionFactory.java        |  6 ++++--
 .../function/StUnionAggregationFunction.java        |  2 +-
 .../function/AggregationFunctionFactoryTest.java    | 21 +++++++++++++++++++++
 .../tests/OfflineClusterIntegrationTest.java        | 17 +++++++++++++++++
 5 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/pinot-common/src/main/java/org/apache/pinot/common/function/AggregationFunctionType.java b/pinot-common/src/main/java/org/apache/pinot/common/function/AggregationFunctionType.java
index 62704db..fc60ea6 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/function/AggregationFunctionType.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/function/AggregationFunctionType.java
@@ -18,6 +18,12 @@
  */
 package org.apache.pinot.common.function;
 
+import org.apache.commons.lang3.StringUtils;
+
+
+/**
+ * NOTE: No underscore is allowed in the enum name.
+ */
 public enum AggregationFunctionType {
   // Aggregation functions for single-valued columns
   COUNT("count"),
@@ -38,8 +44,8 @@ public enum AggregationFunctionType {
   PERCENTILEEST("percentileEst"),
   PERCENTILETDIGEST("percentileTDigest"),
 
-  // geo aggregation functions
-  ST_UNION("ST_Union"),
+  // Geo aggregation functions
+  STUNION("STUnion"),
 
   // Aggregation functions for multi-valued columns
   COUNTMV("countMV"),
@@ -78,9 +84,10 @@ public enum AggregationFunctionType {
 
   /**
    * Returns the corresponding aggregation function type for the given function name.
+   * <p>NOTE: Underscores in the function name are ignored.
    */
   public static AggregationFunctionType getAggregationFunctionType(String functionName) {
-    String upperCaseFunctionName = functionName.toUpperCase();
+    String upperCaseFunctionName = StringUtils.remove(functionName, '_').toUpperCase();
     if (upperCaseFunctionName.startsWith("PERCENTILE")) {
       String remainingFunctionName = upperCaseFunctionName.substring(10);
       if (remainingFunctionName.isEmpty() || remainingFunctionName.matches("\\d+")) {
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactory.java b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactory.java
index 08eed30..a218ef1 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactory.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactory.java
@@ -20,6 +20,7 @@ package org.apache.pinot.core.query.aggregation.function;
 
 import com.google.common.base.Preconditions;
 import java.util.List;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.pinot.common.function.AggregationFunctionType;
 import org.apache.pinot.core.query.exception.BadQueryRequestException;
 import org.apache.pinot.core.query.request.context.ExpressionContext;
@@ -37,6 +38,7 @@ public class AggregationFunctionFactory {
 
   /**
    * Given the function information, returns a new instance of the corresponding aggregation function.
+   * <p>NOTE: Underscores in the function name are ignored.
    * <p>NOTE: We pass the query context to this method because DISTINCT is currently modeled as an aggregation function
    *          and requires the order-by and limit information from the query.
    * <p>TODO: Consider modeling DISTINCT as unique selection instead of aggregation so that early-termination, limit and
@@ -44,7 +46,7 @@ public class AggregationFunctionFactory {
    */
   public static AggregationFunction getAggregationFunction(FunctionContext function, QueryContext queryContext) {
     try {
-      String upperCaseFunctionName = function.getFunctionName().toUpperCase();
+      String upperCaseFunctionName = StringUtils.remove(function.getFunctionName(), '_').toUpperCase();
       List<ExpressionContext> arguments = function.getArguments();
       ExpressionContext firstArgument = arguments.get(0);
       if (upperCaseFunctionName.startsWith("PERCENTILE")) {
@@ -158,7 +160,7 @@ public class AggregationFunctionFactory {
           case DISTINCT:
             return new DistinctAggregationFunction(arguments, queryContext.getOrderByExpressions(),
                 queryContext.getLimit());
-          case ST_UNION:
+          case STUNION:
             return new StUnionAggregationFunction(firstArgument);
           default:
             throw new IllegalArgumentException();
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/StUnionAggregationFunction.java b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/StUnionAggregationFunction.java
index eff99db..baff2ee 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/StUnionAggregationFunction.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/StUnionAggregationFunction.java
@@ -46,7 +46,7 @@ public class StUnionAggregationFunction extends BaseSingleInputAggregationFuncti
 
   @Override
   public AggregationFunctionType getType() {
-    return AggregationFunctionType.ST_UNION;
+    return AggregationFunctionType.STUNION;
   }
 
   @Override
diff --git a/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactoryTest.java b/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactoryTest.java
index 0b4360e..476c086 100644
--- a/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactoryTest.java
+++ b/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactoryTest.java
@@ -163,6 +163,13 @@ public class AggregationFunctionFactoryTest {
     assertEquals(aggregationFunction.getColumnName(), "avgMV_column");
     assertEquals(aggregationFunction.getResultColumnName(), function.toString());
 
+    function = getFunction("AvG_mV");
+    aggregationFunction = AggregationFunctionFactory.getAggregationFunction(function, DUMMY_QUERY_CONTEXT);
+    assertTrue(aggregationFunction instanceof AvgMVAggregationFunction);
+    assertEquals(aggregationFunction.getType(), AggregationFunctionType.AVGMV);
+    assertEquals(aggregationFunction.getColumnName(), "avgMV_column");
+    assertEquals(aggregationFunction.getResultColumnName(), "avgmv(column)");
+
     function = getFunction("MiNmAxRaNgEmV");
     aggregationFunction = AggregationFunctionFactory.getAggregationFunction(function, DUMMY_QUERY_CONTEXT);
     assertTrue(aggregationFunction instanceof MinMaxRangeMVAggregationFunction);
@@ -184,6 +191,13 @@ public class AggregationFunctionFactoryTest {
     assertEquals(aggregationFunction.getColumnName(), "distinctCountHLLMV_column");
     assertEquals(aggregationFunction.getResultColumnName(), function.toString());
 
+    function = getFunction("DiStInCt_CoUnT_hLl_Mv");
+    aggregationFunction = AggregationFunctionFactory.getAggregationFunction(function, DUMMY_QUERY_CONTEXT);
+    assertTrue(aggregationFunction instanceof DistinctCountHLLMVAggregationFunction);
+    assertEquals(aggregationFunction.getType(), AggregationFunctionType.DISTINCTCOUNTHLLMV);
+    assertEquals(aggregationFunction.getColumnName(), "distinctCountHLLMV_column");
+    assertEquals(aggregationFunction.getResultColumnName(), "distinctcounthllmv(column)");
+
     function = getFunction("DiStInCtCoUnTrAwHlLmV");
     aggregationFunction = AggregationFunctionFactory.getAggregationFunction(function, DUMMY_QUERY_CONTEXT);
     assertTrue(aggregationFunction instanceof DistinctCountRawHLLMVAggregationFunction);
@@ -211,6 +225,13 @@ public class AggregationFunctionFactoryTest {
     assertEquals(aggregationFunction.getType(), AggregationFunctionType.PERCENTILETDIGESTMV);
     assertEquals(aggregationFunction.getColumnName(), "percentileTDigest95MV_column");
     assertEquals(aggregationFunction.getResultColumnName(), function.toString());
+
+    function = getFunction("PeRcEnTiLe_TdIgEsT_95_mV");
+    aggregationFunction = AggregationFunctionFactory.getAggregationFunction(function, DUMMY_QUERY_CONTEXT);
+    assertTrue(aggregationFunction instanceof PercentileTDigestMVAggregationFunction);
+    assertEquals(aggregationFunction.getType(), AggregationFunctionType.PERCENTILETDIGESTMV);
+    assertEquals(aggregationFunction.getColumnName(), "percentileTDigest95MV_column");
+    assertEquals(aggregationFunction.getResultColumnName(), "percentiletdigest95mv(column)");
   }
 
   private FunctionContext getFunction(String functionName) {
diff --git a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
index 9827001..7475715 100644
--- a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
+++ b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
@@ -1264,4 +1264,21 @@ public class OfflineClusterIntegrationTest extends BaseClusterIntegrationTestSet
     assertEquals(postSqlQuery(query, _brokerBaseApiUrl).get("resultTable").get("rows").get(0).get(0).asLong(),
         expectedResults[10]);
   }
+
+  @Test
+  public void testAggregationFunctionsWithUnderscore()
+      throws Exception {
+    String query;
+
+    // The Accurate value is 6538.
+    query = "SELECT distinct_count(FlightNum) FROM mytable ";
+    assertEquals(postQuery(query).get("aggregationResults").get(0).get("value").asLong(), 6538);
+    assertEquals(postSqlQuery(query, _brokerBaseApiUrl).get("resultTable").get("rows").get(0).get(0).asLong(), 6538);
+
+    // The Accurate value is 6538.
+    query = "SELECT c_o_u_n_t(FlightNum) FROM mytable ";
+    assertEquals(postQuery(query).get("aggregationResults").get(0).get("value").asLong(), 115545);
+    assertEquals(postSqlQuery(query, _brokerBaseApiUrl).get("resultTable").get("rows").get(0).get(0).asLong(), 115545);
+
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org