Jackie-Jiang commented on code in PR #17189:
URL: https://github.com/apache/pinot/pull/17189#discussion_r2578573513


##########
pinot-common/src/test/java/org/apache/pinot/common/function/scalar/LogicalFunctionsTest.java:
##########
@@ -0,0 +1,445 @@
+/**
+ * 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.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+
+/**
+ * Tests for Logical functions with Trino-compatible NULL handling
+ */
+public class LogicalFunctionsTest {
+
+  // ==================== Tests for logicalAnd ====================
+
+  @Test
+  public void testLogicalAndTrueTrue() {

Review Comment:
   (minor) Same for other places
   
   ```suggestion
     public void testAndTrueTrue() {
   ```



##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/LogicalFunctions.java:
##########
@@ -18,20 +18,146 @@
  */
 package org.apache.pinot.common.function.scalar;
 
+import javax.annotation.Nullable;
 import org.apache.pinot.spi.annotations.ScalarFunction;
 
+
 /**
- * Logical transformation on boolean values. Currently, only not is supported.
+ * Inbuilt logical transform functions with Trino-compatible NULL handling
+ *
+ * <p>These functions implement logical operators (AND, OR, NOT) with proper 
three-valued logic
+ * support, following the SQL standard and Trino's behavior for NULL handling.
+ *
+ * <p>Truth tables for NULL handling:
+ * <ul>
+ *   <li>AND: Returns NULL if one side is NULL and the other is not FALSE.
+ *       Returns FALSE if at least one side is FALSE.</li>
+ *   <li>OR: Returns NULL if one side is NULL and the other is not TRUE.
+ *       Returns TRUE if at least one side is TRUE.</li>
+ *   <li>NOT: Returns NULL if the input is NULL.</li>
+ * </ul>
+ *
+ * <p>Examples:
+ * <pre>
+ * logicalAnd(true, true) → true
+ * logicalAnd(true, false) → false
+ * logicalAnd(true, null) → null
+ * logicalAnd(false, null) → false
+ *
+ * logicalOr(true, false) → true
+ * logicalOr(false, false) → false
+ * logicalOr(false, null) → null
+ * logicalOr(true, null) → true
+ *
+ * logicalNot(true) → false
+ * logicalNot(false) → true
+ * logicalNot(null) → null
+ * </pre>
  */
 public class LogicalFunctions {
+
   private LogicalFunctions() {
   }
 
   /**
-   * Returns logical negate of value
+   * Logical AND operator with Trino-compatible NULL handling.
+   *
+   * <p>Truth table:
+   * <pre>
+   * a     | b     | result
+   * ------|-------|-------
+   * TRUE  | TRUE  | TRUE
+   * TRUE  | FALSE | FALSE
+   * TRUE  | NULL  | NULL
+   * FALSE | TRUE  | FALSE
+   * FALSE | FALSE | FALSE
+   * FALSE | NULL  | FALSE
+   * NULL  | TRUE  | NULL
+   * NULL  | FALSE | FALSE
+   * NULL  | NULL  | NULL
+   * </pre>
+   *
+   * @param a First boolean value (nullable)
+   * @param b Second boolean value (nullable)
+   * @return The logical AND result, or NULL if result cannot be determined
+   */
+  @Nullable
+  @ScalarFunction(names = {"AND"}, nullableParameters = true)
+  public static Boolean logicalAnd(@Nullable Boolean a, @Nullable Boolean b) {

Review Comment:
   Please also update the javadoc. Same for other places
   
   ```suggestion
     @ScalarFunction(nullableParameters = true)
     public static Boolean and(@Nullable Boolean a, @Nullable Boolean b) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to