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


##########
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 = {"logicalAnd", "logical_and", "and"}, 
nullableParameters = true)

Review Comment:
   Do we want to call it `logicalAnd` or simply `and`? Is `logicalAnd` a 
standard SQL function?



-- 
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