You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "Akanksha-kedia (via GitHub)" <gi...@apache.org> on 2025/11/11 11:05:16 UTC

[PR] Adding logical functions for Apache Pinot [pinot]

Akanksha-kedia opened a new pull request, #17189:
URL: https://github.com/apache/pinot/pull/17189

   Instructions:
   1. The PR has to be tagged with at least one of the following labels (*):
      1. `feature`
      2. `bugfix`
      3. `performance`
      4. `ui`
      5. `backward-incompat`
      6. `release-notes` (**)
   2. Remove these instructions before publishing the PR.
    
   (*) Other labels to consider:
   - `testing`
   - `dependencies`
   - `docker`
   - `kubernetes`
   - `observability`
   - `security`
   - `code-style`
   - `extension-point`
   - `refactor`
   - `cleanup`
   
   (**) Use `release-notes` label for scenarios like:
   - New configuration options
   - Deprecation of configurations
   - Signature changes to public methods/interfaces
   - New plugins added or old plugins removed
   


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Akanksha-kedia (via GitHub)" <gi...@apache.org>.
Akanksha-kedia commented on PR #17189:
URL: https://github.com/apache/pinot/pull/17189#issuecomment-3573839813

   @Jackie-Jiang i have reverted back please check.


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Akanksha-kedia (via GitHub)" <gi...@apache.org>.
Akanksha-kedia commented on PR #17189:
URL: https://github.com/apache/pinot/pull/17189#issuecomment-3544663485

   Thanks for the review , lets go with standard
   
   On Tue, 18 Nov 2025 at 6:56 AM, Xiaotian (Jackie) Jiang <
   ***@***.***> wrote:
   
   > ***@***.**** commented on this pull request.
   >
   > Thanks for the contribution! This fills a big gap
   > ------------------------------
   >
   > In
   > pinot-common/src/main/java/org/apache/pinot/common/function/scalar/LogicalFunctions.java
   > <https://github.com/apache/pinot/pull/17189#discussion_r2535998210>:
   >
   > > +   * 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)
   >
   > Do we want to call it logicalAnd or simply and? Is logicalAnd a standard
   > SQL function?
   >
   > —
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/pinot/pull/17189#pullrequestreview-3475125185>,
   > or unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/AVL2AZVHVNED4A2SLGOTHWL35JYTTAVCNFSM6AAAAACLYKVTRSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTINZVGEZDKMJYGU>
   > .
   > You are receiving this because you authored the thread.Message ID:
   > ***@***.***>
   >
   


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on PR #17189:
URL: https://github.com/apache/pinot/pull/17189#issuecomment-3573206532

   @Akanksha-kedia Did you push the wrong commit to this PR?


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Akanksha-kedia (via GitHub)" <gi...@apache.org>.
Akanksha-kedia commented on PR #17189:
URL: https://github.com/apache/pinot/pull/17189#issuecomment-3600206664

   @Jackie-Jiang please rereview thanks in advance!!!


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17189:
URL: https://github.com/apache/pinot/pull/17189#discussion_r2516257924


##########
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)
+  public static Boolean logicalAnd(@Nullable Boolean a, @Nullable Boolean b) {
+    // If either value is FALSE, the result is FALSE
+    if (Boolean.FALSE.equals(a) || Boolean.FALSE.equals(b)) {

Review Comment:
   [nitpick] Using `Boolean.FALSE.equals()` is correct for null-safety, but for performance-critical logical operations, consider restructuring to check nulls first, then use primitive comparison. For example: `if ((a != null && !a) || (b != null && !b))` avoids boxing comparisons when both values are non-null.
   ```suggestion
       if ((a != null && !a) || (b != null && !b)) {
   ```



##########
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)
+  public static Boolean logicalAnd(@Nullable Boolean a, @Nullable Boolean b) {
+    // If either value is FALSE, the result is FALSE
+    if (Boolean.FALSE.equals(a) || Boolean.FALSE.equals(b)) {
+      return false;
+    }
+
+    // If both values are TRUE, the result is TRUE
+    if (Boolean.TRUE.equals(a) && Boolean.TRUE.equals(b)) {
+      return true;
+    }
+
+    // Otherwise, at least one value is NULL and neither is FALSE, so result is NULL
+    return null;
+  }
+
+  /**
+   * Logical OR operator with Trino-compatible NULL handling.
+   *
+   * <p>Truth table:
+   * <pre>
+   * a     | b     | result
+   * ------|-------|-------
+   * TRUE  | TRUE  | TRUE
+   * TRUE  | FALSE | TRUE
+   * TRUE  | NULL  | TRUE
+   * FALSE | TRUE  | TRUE
+   * FALSE | FALSE | FALSE
+   * FALSE | NULL  | NULL
+   * NULL  | TRUE  | TRUE
+   * NULL  | FALSE | NULL
+   * NULL  | NULL  | NULL
+   * </pre>
+   *
+   * @param a First boolean value (nullable)
+   * @param b Second boolean value (nullable)
+   * @return The logical OR result, or NULL if the result cannot be determined
+   */
+  @Nullable
+  @ScalarFunction(names = {"logicalOr", "logical_or", "or"}, nullableParameters = true)
+  public static Boolean logicalOr(@Nullable Boolean a, @Nullable Boolean b) {
+    // If either value is TRUE, the result is TRUE
+    if (Boolean.TRUE.equals(a) || Boolean.TRUE.equals(b)) {

Review Comment:
   [nitpick] Similar to logicalAnd, using `Boolean.TRUE.equals()` is null-safe but potentially less efficient. Consider checking nulls first: `if ((a != null && a) || (b != null && b))` for better performance with non-null values.
   ```suggestion
       if ((a != null && a) || (b != null && 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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Akanksha-kedia (via GitHub)" <gi...@apache.org>.
Akanksha-kedia commented on PR #17189:
URL: https://github.com/apache/pinot/pull/17189#issuecomment-3516336871

   @xiangfu0 please review and help to merge


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #17189:
URL: https://github.com/apache/pinot/pull/17189#issuecomment-3516543525

   ### :x: 3 Tests Failed:
   | Tests completed | Failed | Passed | Skipped |
   |---|---|---|---|
   | 16019 | 3 | 16016 | 27 |
   <details><summary>View the full list of 3 :snowflake: flaky test(s)</summary>
   
   > <pre><code class="language-python">org.apache.pinot.core.function.FunctionRegistryTest::testTransformAndFilterFunctionsRegistered</code></pre>
   > **Flake rate in main:** 91.18% (Passed 6 times, Failed 62 times)
   > <details><summary>Stack Traces | 0.013s run time</summary>
   > 
   > > <pre><code class="language-python">Unable to find transform function signature for: not expected [true] but found [false]</code></pre>
   > 
   > </details>
   
   
   > <pre><code class="language-python">org.apache.pinot.core.query.postaggregation.PostAggregationFunctionTest::testPostAggregationFunction</code></pre>
   > **Flake rate in main:** 91.18% (Passed 6 times, Failed 62 times)
   > <details><summary>Stack Traces | 0.639s run time</summary>
   > 
   > > <pre><code class="language-python">Unsupported function: not</code></pre>
   > 
   > </details>
   
   
   > <pre><code class="language-python">org.apache.pinot.queries.NullHandlingEnabledQueriesTest::testHavingFilterNotOfColumnIsNull</code></pre>
   > **Flake rate in main:** 91.18% (Passed 6 times, Failed 62 times)
   > <details><summary>Stack Traces | 0.049s run time</summary>
   > 
   > > <pre><code class="language-python">No failure message available</code></pre>
   > 
   > </details>
   
   </details>
   
   To view more test analytics, go to the [Test Analytics Dashboard](https://app.codecov.io/gh/apache/pinot/tests/Akanksha-kedia%3Afeature%2Ffunc)
   <sub>📋 Got 3 mins? [Take this short survey](https://forms.gle/22i53Qa1CySZjA6c7) to help us improve Test Analytics.</sub>


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Akanksha-kedia (via GitHub)" <gi...@apache.org>.
Akanksha-kedia commented on PR #17189:
URL: https://github.com/apache/pinot/pull/17189#issuecomment-3573750703

   Yes, sorry.
   
   On Tue, 25 Nov 2025 at 5:29 AM, Xiaotian (Jackie) Jiang <
   ***@***.***> wrote:
   
   > *Jackie-Jiang* left a comment (apache/pinot#17189)
   > <https://github.com/apache/pinot/pull/17189#issuecomment-3573206532>
   >
   > @Akanksha-kedia <https://github.com/Akanksha-kedia> Did you push the
   > wrong commit to this PR?
   >
   > —
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/pinot/pull/17189#issuecomment-3573206532>, or
   > unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/AVL2AZXCRDLI2O5KXAPZRGL36OLV7AVCNFSM6AAAAACLYKVTRSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKNZTGIYDMNJTGI>
   > .
   > You are receiving this because you were mentioned.Message ID:
   > ***@***.***>
   >
   


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on PR #17189:
URL: https://github.com/apache/pinot/pull/17189#issuecomment-3583459015

   Let's go with the standard `AND`, `OR` and `NOT`, and we can remove the aliases


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Adding logical functions for Apache Pinot [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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