Copilot commented on code in PR #18729:
URL: https://github.com/apache/pinot/pull/18729#discussion_r3390516582


##########
pinot-query-planner/src/test/java/org/apache/pinot/query/planner/logical/RexExpressionUtilsTest.java:
##########
@@ -0,0 +1,384 @@
+/**
+ * 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.query.planner.logical;
+
+import com.google.common.collect.ImmutableRangeSet;
+import com.google.common.collect.Range;
+import java.math.BigDecimal;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexUnknownAs;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.util.Sarg;
+import org.apache.pinot.query.type.TypeFactory;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for RexExpressionUtils, focusing on the handleSearch method and null 
handling.
+ */
+public class RexExpressionUtilsTest {
+    private RexBuilder _rexBuilder;
+    private RelDataTypeFactory _typeFactory;
+
+    @BeforeClass
+    public void setup() {
+        _typeFactory = new TypeFactory();
+        _rexBuilder = new RexBuilder(_typeFactory);
+    }
+
+    @Test
+    public void testHandleSearchInWithNullAsUnknown() {
+        // Test: col IN (1, 2, 3) with RexUnknownAs.UNKNOWN
+        RexInputRef inputRef = 
_rexBuilder.makeInputRef(_typeFactory.createSqlType(SqlTypeName.INTEGER), 0);
+
+        ImmutableRangeSet.Builder<BigDecimal> rangeSetBuilder = 
ImmutableRangeSet.builder();
+        rangeSetBuilder.add(Range.singleton(BigDecimal.valueOf(1)));
+        rangeSetBuilder.add(Range.singleton(BigDecimal.valueOf(2)));
+        rangeSetBuilder.add(Range.singleton(BigDecimal.valueOf(3)));
+        Sarg<BigDecimal> sarg = Sarg.of(RexUnknownAs.UNKNOWN, 
rangeSetBuilder.build());
+
+        RexLiteral searchLiteral = _rexBuilder.makeSearchArgumentLiteral(sarg,
+                _typeFactory.createSqlType(SqlTypeName.INTEGER));
+        RexCall searchCall = (RexCall) 
_rexBuilder.makeCall(SqlStdOperatorTable.SEARCH, inputRef, searchLiteral);
+
+        RexExpression result = RexExpressionUtils.fromRexCall(searchCall);
+
+        // Should be a simple IN expression without null check
+        Assert.assertTrue(result instanceof RexExpression.FunctionCall);
+        RexExpression.FunctionCall funcCall = (RexExpression.FunctionCall) 
result;
+        Assert.assertEquals(funcCall.getFunctionName(), SqlKind.IN.name());
+        Assert.assertEquals(funcCall.getFunctionOperands().size(), 4); // col 
+ 3 values
+    }
+
+    @Test
+    public void testHandleSearchInWithNullAsTrue() {
+        // Test: col IN (1, 2, 3) OR col IS NULL (when nullAs = TRUE)
+        RexInputRef inputRef = 
_rexBuilder.makeInputRef(_typeFactory.createSqlType(SqlTypeName.INTEGER), 0);
+
+        ImmutableRangeSet.Builder<BigDecimal> rangeSetBuilder = 
ImmutableRangeSet.builder();
+        rangeSetBuilder.add(Range.singleton(BigDecimal.valueOf(1)));
+        rangeSetBuilder.add(Range.singleton(BigDecimal.valueOf(2)));
+        rangeSetBuilder.add(Range.singleton(BigDecimal.valueOf(3)));
+        Sarg<BigDecimal> sarg = Sarg.of(RexUnknownAs.TRUE, 
rangeSetBuilder.build());
+
+        RexLiteral searchLiteral = _rexBuilder.makeSearchArgumentLiteral(sarg,
+                _typeFactory.createSqlType(SqlTypeName.INTEGER));
+        RexCall searchCall = (RexCall) 
_rexBuilder.makeCall(SqlStdOperatorTable.SEARCH, inputRef, searchLiteral);
+
+        RexExpression result = RexExpressionUtils.fromRexCall(searchCall);
+
+        // Should be: (col IN (1, 2, 3)) OR (col IS NULL)
+        Assert.assertTrue(result instanceof RexExpression.FunctionCall);
+        RexExpression.FunctionCall funcCall = (RexExpression.FunctionCall) 
result;
+        Assert.assertEquals(funcCall.getFunctionName(), SqlKind.OR.name());
+        Assert.assertEquals(funcCall.getFunctionOperands().size(), 2);
+
+        // First operand should be the IN expression
+        RexExpression firstOperand = funcCall.getFunctionOperands().get(0);
+        Assert.assertTrue(firstOperand instanceof RexExpression.FunctionCall);
+        Assert.assertEquals(((RexExpression.FunctionCall) 
firstOperand).getFunctionName(), SqlKind.IN.name());
+
+        // Second operand should be IS NULL
+        RexExpression secondOperand = funcCall.getFunctionOperands().get(1);
+        Assert.assertTrue(secondOperand instanceof RexExpression.FunctionCall);
+        Assert.assertEquals(((RexExpression.FunctionCall) 
secondOperand).getFunctionName(), SqlKind.IS_NULL.name());
+    }
+
+    @Test
+    public void testHandleSearchInWithNullAsFalse() {
+        // Test: col IN (1, 2, 3) AND col IS NOT NULL (when nullAs = FALSE)

Review Comment:
   The comment says the test is for `col IN (1, 2, 3)` but this test only 
builds a Sarg with points {1, 2}. This mismatch is confusing when reading the 
test intent.



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