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

siddteotia 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 0067b64bbf [Feature] Not scalar function (#9338)
0067b64bbf is described below

commit 0067b64bbfee96ec178ea8b5a6eef17732d94f50
Author: Yao Liu <[email protected]>
AuthorDate: Wed Sep 7 02:59:01 2022 -0700

    [Feature] Not scalar function (#9338)
    
    * test
    
    * Add not scalar function to handle post-agregate not
---
 .../common/function/scalar/LogicalFunctions.java   | 37 +++++++++++++
 .../core/data/function/LogicalFunctionsTest.java   | 64 ++++++++++++++++++++++
 .../PostAggregationFunctionTest.java               |  8 +++
 3 files changed, 109 insertions(+)

diff --git 
a/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/LogicalFunctions.java
 
b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/LogicalFunctions.java
new file mode 100644
index 0000000000..863f56f783
--- /dev/null
+++ 
b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/LogicalFunctions.java
@@ -0,0 +1,37 @@
+/**
+ * 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.pinot.common.function.scalar;
+
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+// Logical transformation on boolean values.
+// Currently, only not is supported.
+public class LogicalFunctions {
+  private LogicalFunctions() {
+  }
+
+  /**
+   * Returns logical negate of value
+   */
+  @ScalarFunction
+  public static boolean not(boolean value) {
+    return !value;
+  }
+}
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/data/function/LogicalFunctionsTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/data/function/LogicalFunctionsTest.java
new file mode 100644
index 0000000000..7266ec91b4
--- /dev/null
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/data/function/LogicalFunctionsTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.pinot.core.data.function;
+
+import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.segment.local.function.InbuiltFunctionEvaluator;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests the scalar transform functions for logical operators
+ * Currently, only not operator is supported.
+ */
+public class LogicalFunctionsTest {
+
+  private void testFunction(String functionExpression, List<String> 
expectedArguments, GenericRow row,
+      Object expectedResult) {
+    InbuiltFunctionEvaluator evaluator = new 
InbuiltFunctionEvaluator(functionExpression);
+    Assert.assertEquals(evaluator.getArguments(), expectedArguments);
+    Assert.assertEquals(evaluator.evaluate(row), expectedResult);
+  }
+
+  @Test(dataProvider = "logicalFunctionDataProvider")
+  public void testArithmeticFunctions(String functionExpression, List<String> 
expectedArguments, GenericRow row,
+      Object expectedResult) {
+    testFunction(functionExpression, expectedArguments, row, expectedResult);
+  }
+
+  @DataProvider(name = "logicalFunctionDataProvider")
+  public Object[][] arithmeticFunctionsDataProvider() {
+    List<Object[]> inputs = new ArrayList<>();
+
+    GenericRow row0 = new GenericRow();
+    row0.putValue("a", true);
+    inputs.add(new Object[]{"not a", Lists.newArrayList("a"), row0, false});
+
+    GenericRow row1 = new GenericRow();
+    row1.putValue("b", false);
+    inputs.add(new Object[]{"not b", Lists.newArrayList("b"), row1, true});
+
+    return inputs.toArray(new Object[0][]);
+  }
+}
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/query/postaggregation/PostAggregationFunctionTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/query/postaggregation/PostAggregationFunctionTest.java
index 2cea4564f8..e397ce7343 100644
--- 
a/pinot-core/src/test/java/org/apache/pinot/core/query/postaggregation/PostAggregationFunctionTest.java
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/query/postaggregation/PostAggregationFunctionTest.java
@@ -25,6 +25,8 @@ import org.locationtech.jts.geom.Coordinate;
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
 
 
 public class PostAggregationFunctionTest {
@@ -63,5 +65,11 @@ public class PostAggregationFunctionTest {
     function = new PostAggregationFunction("cast", new 
ColumnDataType[]{ColumnDataType.INT, ColumnDataType.STRING});
     assertEquals(function.getResultType(), ColumnDataType.OBJECT);
     assertEquals(function.invoke(new Object[]{1, "LONG"}), 1L);
+
+    // NOT
+    function = new PostAggregationFunction("not", new 
ColumnDataType[]{ColumnDataType.BOOLEAN});
+    assertEquals(function.getResultType(), ColumnDataType.BOOLEAN);
+    assertFalse((Boolean) function.invoke(new Object[]{true}));
+    assertTrue((Boolean) function.invoke(new Object[]{false}));
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to