You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ro...@apache.org on 2022/09/01 14:15:11 UTC

[pinot] branch master updated: add cardinality function (#9300)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a5227873d6 add cardinality function (#9300)
a5227873d6 is described below

commit a5227873d60ef02a771ef01bc7fb7ed262ada614
Author: Rong Rong <wa...@gmail.com>
AuthorDate: Thu Sep 1 07:15:01 2022 -0700

    add cardinality function (#9300)
    
    * add array cardinality function as alias of arrayLength
    
    Co-authored-by: Rong Rong <ro...@startree.ai>
    Co-authored-by: Xiaotian (Jackie) Jiang <17...@users.noreply.github.com>
---
 .../common/function/TransformFunctionType.java     |  4 +++-
 .../function/TransformFunctionFactory.java         |  3 +--
 .../pinot/queries/MultiValueRawQueriesTest.java    | 22 +++++++++++++++-------
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java b/pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
index 1cd71f2a7d..29c75a2ae5 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
@@ -85,7 +85,9 @@ public enum TransformFunctionType {
   MINUTE("minute"),
   SECOND("second"),
   MILLISECOND("millisecond"),
-  ARRAYLENGTH("arrayLength"),
+  // The only column accepted by "cardinality" function is multi-value array, thus putting "cardinality" as alias.
+  // TODO: once we support other types of multiset, we should make CARDINALITY its own function
+  ARRAYLENGTH("arrayLength", "cardinality"),
   ARRAYAVERAGE("arrayAverage"),
   ARRAYMIN("arrayMin"),
   ARRAYMAX("arrayMax"),
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
index aed1ee98e0..5c98c304c5 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
@@ -125,8 +125,7 @@ public class TransformFunctionFactory {
     typeToImplementation.put(TransformFunctionType.MINUTE, DateTimeTransformFunction.Minute.class);
     typeToImplementation.put(TransformFunctionType.SECOND, DateTimeTransformFunction.Second.class);
     typeToImplementation.put(TransformFunctionType.MILLISECOND, DateTimeTransformFunction.Millisecond.class);
-    typeToImplementation.put(TransformFunctionType.ARRAYLENGTH,
-        ArrayLengthTransformFunction.class);
+    typeToImplementation.put(TransformFunctionType.ARRAYLENGTH, ArrayLengthTransformFunction.class);
     typeToImplementation.put(TransformFunctionType.VALUEIN, ValueInTransformFunction.class);
     typeToImplementation.put(TransformFunctionType.MAPVALUE, MapValueTransformFunction.class);
     typeToImplementation.put(TransformFunctionType.INIDSET, InIdSetTransformFunction.class);
diff --git a/pinot-core/src/test/java/org/apache/pinot/queries/MultiValueRawQueriesTest.java b/pinot-core/src/test/java/org/apache/pinot/queries/MultiValueRawQueriesTest.java
index 64f4c4c311..45b70cea74 100644
--- a/pinot-core/src/test/java/org/apache/pinot/queries/MultiValueRawQueriesTest.java
+++ b/pinot-core/src/test/java/org/apache/pinot/queries/MultiValueRawQueriesTest.java
@@ -613,21 +613,28 @@ public class MultiValueRawQueriesTest extends BaseQueriesTest {
     }
     {
       // Test a select with a ARRAYLENGTH transform function
-      String query = "SELECT ARRAYLENGTH(mvRawLongCol), ARRAYLENGTH(mvLongCol) from testTable GROUP BY "
-          + "ARRAYLENGTH(mvRawLongCol), ARRAYLENGTH(mvLongCol) LIMIT 10";
+      String query = "SELECT ARRAYLENGTH(mvRawLongCol), ARRAYLENGTH(mvLongCol), CARDINALITY(mvRawLongCol), "
+          + "CARDINALITY(mvLongCol) from testTable GROUP BY ARRAYLENGTH(mvRawLongCol), ARRAYLENGTH(mvLongCol), "
+          + "CARDINALITY(mvRawLongCol), CARDINALITY(mvLongCol) LIMIT 10";
       ResultTable resultTable = getBrokerResponse(query).getResultTable();
       assertNotNull(resultTable);
-      DataSchema dataSchema = new DataSchema(new String[]{"arraylength(mvRawLongCol)", "arraylength(mvLongCol)"},
-          new DataSchema.ColumnDataType[]{DataSchema.ColumnDataType.INT, DataSchema.ColumnDataType.INT});
+      DataSchema dataSchema = new DataSchema(new String[]{"arraylength(mvRawLongCol)", "arraylength(mvLongCol)",
+          "cardinality(mvRawLongCol)", "cardinality(mvLongCol)"},
+          new DataSchema.ColumnDataType[]{DataSchema.ColumnDataType.INT, DataSchema.ColumnDataType.INT,
+              DataSchema.ColumnDataType.INT, DataSchema.ColumnDataType.INT});
       assertEquals(resultTable.getDataSchema(), dataSchema);
       List<Object[]> recordRows = resultTable.getRows();
       assertEquals(recordRows.size(), 1);
       Object[] values = recordRows.get(0);
-      assertEquals(values.length, 2);
+      assertEquals(values.length, 4);
       int intRawVal = (int) values[0];
       int intVal = (int) values[1];
+      int intRawVal2 = (int) values[2];
+      int intVal2 = (int) values[3];
       assertEquals(intRawVal, 2);
       assertEquals(intVal, intRawVal);
+      assertEquals(intRawVal2, intRawVal);
+      assertEquals(intVal2, intRawVal);
     }
   }
 
@@ -937,8 +944,9 @@ public class MultiValueRawQueriesTest extends BaseQueriesTest {
     }
     {
       // Test a select with filter query on an arraylength transform function
-      String query = "SELECT mvRawIntCol, mvRawDoubleCol, mvRawStringCol from testTable where "
-          + "ARRAYLENGTH(mvRawIntCol) < 5 LIMIT 10";
+      String query = "SELECT mvRawIntCol, mvRawDoubleCol, mvRawStringCol FROM testTable WHERE "
+          + "ARRAYLENGTH(mvRawIntCol) < 5 AND CARDINALITY(mvRawIntCol) < 5 AND CARDINALITY(mvRawIntCol) < 5 "
+          + "LIMIT 10";
       ResultTable resultTable = getBrokerResponse(query).getResultTable();
       assertNotNull(resultTable);
       DataSchema dataSchema = new DataSchema(new String[]{


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