AMashenkov commented on code in PR #7303:
URL: https://github.com/apache/ignite-3/pull/7303#discussion_r2646910027


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/expressions/IgnitePredicateTest.java:
##########
@@ -0,0 +1,1172 @@
+/*
+ * 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.ignite.internal.sql.engine.expressions;
+
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrows;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import java.math.BigDecimal;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.UUID;
+import org.apache.ignite.internal.sql.engine.api.expressions.EvaluationContext;
+import 
org.apache.ignite.internal.sql.engine.api.expressions.ExpressionEvaluationException;
+import org.apache.ignite.internal.sql.engine.api.expressions.ExpressionFactory;
+import 
org.apache.ignite.internal.sql.engine.api.expressions.ExpressionParsingException;
+import 
org.apache.ignite.internal.sql.engine.api.expressions.ExpressionValidationException;
+import org.apache.ignite.internal.sql.engine.api.expressions.IgnitePredicate;
+import org.apache.ignite.internal.sql.engine.api.expressions.RowAccessor;
+import org.apache.ignite.internal.sql.engine.exec.exp.SqlExpressionFactoryImpl;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.sql.engine.util.EmptyCacheFactory;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.apache.ignite.internal.type.StructNativeType;
+import org.apache.ignite.sql.ColumnType;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+@SuppressWarnings("ThrowableNotThrown")
+class IgnitePredicateTest extends AbstractExpressionFactoryTest {
+    private final ExpressionFactory factory = new SqlExpressionFactoryAdapter(
+            new SqlExpressionFactoryImpl(
+                    Commons.typeFactory(), 0, EmptyCacheFactory.INSTANCE
+            )
+    );
+
+    @Test
+    @TestFor(ColumnType.BOOLEAN)
+    void booleanTest() throws Exception {
+        EvaluationContext<Object[]> context = context();
+        StructNativeType inputType = singleColumnType(NativeTypes.BOOLEAN);
+
+        {
+            IgnitePredicate predicate = factory.predicate("val", inputType);
+
+            assertThat(predicate.test(context, row(true)), is(true));
+            assertThat(predicate.test(context, row(false)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val = true", 
inputType);
+
+            assertThat(predicate.test(context, row(true)), is(true));
+            assertThat(predicate.test(context, row(false)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val <> true", 
inputType);
+
+            assertThat(predicate.test(context, row(true)), is(false));
+            assertThat(predicate.test(context, row(false)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NULL", 
inputType);
+
+            assertThat(predicate.test(context, row(true)), is(false));
+            assertThat(predicate.test(context, row(false)), is(false));
+            assertThat(predicate.test(context, row(null)), is(true));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NOT NULL", 
inputType);
+
+            assertThat(predicate.test(context, row(true)), is(true));
+            assertThat(predicate.test(context, row(false)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+    }
+
+    @Test
+    @TestFor(ColumnType.INT8)
+    void byteTest() throws Exception {
+        EvaluationContext<Object[]> context = context();
+        StructNativeType inputType = singleColumnType(NativeTypes.INT8);
+
+        {
+            IgnitePredicate predicate = factory.predicate("val > 0", 
inputType);
+
+            assertThat(predicate.test(context, row((byte) -100)), is(false));
+            assertThat(predicate.test(context, row((byte) 0)), is(false));
+            assertThat(predicate.test(context, row((byte) 100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val <> 0", 
inputType);
+
+            assertThat(predicate.test(context, row((byte) -100)), is(true));
+            assertThat(predicate.test(context, row((byte) 0)), is(false));
+            assertThat(predicate.test(context, row((byte) 100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val <= 0", 
inputType);
+
+            assertThat(predicate.test(context, row((byte) -100)), is(true));
+            assertThat(predicate.test(context, row((byte) 0)), is(true));
+            assertThat(predicate.test(context, row((byte) 100)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NULL", 
inputType);
+
+            assertThat(predicate.test(context, row((byte) -100)), is(false));
+            assertThat(predicate.test(context, row((byte) 0)), is(false));
+            assertThat(predicate.test(context, row((byte) 100)), is(false));
+            assertThat(predicate.test(context, row(null)), is(true));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NOT NULL", 
inputType);
+
+            assertThat(predicate.test(context, row((byte) -100)), is(true));
+            assertThat(predicate.test(context, row((byte) 0)), is(true));
+            assertThat(predicate.test(context, row((byte) 100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val < 0.1", 
inputType);
+
+            assertThat(predicate.test(context, row((byte) -100)), is(true));
+            assertThat(predicate.test(context, row((byte) 0)), is(true));
+            assertThat(predicate.test(context, row((byte) 100)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val > 0.1", 
inputType);
+
+            assertThat(predicate.test(context, row((byte) -100)), is(false));
+            assertThat(predicate.test(context, row((byte) 0)), is(false));
+            assertThat(predicate.test(context, row((byte) 100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+    }
+
+    @Test
+    @TestFor(ColumnType.INT16)
+    void shortTest() throws Exception {
+        EvaluationContext<Object[]> context = context();
+        StructNativeType inputType = singleColumnType(NativeTypes.INT16);
+
+        {
+            IgnitePredicate predicate = factory.predicate("val > 0", 
inputType);
+
+            assertThat(predicate.test(context, row((short) -100)), is(false));
+            assertThat(predicate.test(context, row((short) 0)), is(false));
+            assertThat(predicate.test(context, row((short) 100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val <> 0", 
inputType);
+
+            assertThat(predicate.test(context, row((short) -100)), is(true));
+            assertThat(predicate.test(context, row((short) 0)), is(false));
+            assertThat(predicate.test(context, row((short) 100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val <= 0", 
inputType);
+
+            assertThat(predicate.test(context, row((short) -100)), is(true));
+            assertThat(predicate.test(context, row((short) 0)), is(true));
+            assertThat(predicate.test(context, row((short) 100)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NULL", 
inputType);
+
+            assertThat(predicate.test(context, row((short) -100)), is(false));
+            assertThat(predicate.test(context, row((short) 0)), is(false));
+            assertThat(predicate.test(context, row((short) 100)), is(false));
+            assertThat(predicate.test(context, row(null)), is(true));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NOT NULL", 
inputType);
+
+            assertThat(predicate.test(context, row((short) -100)), is(true));
+            assertThat(predicate.test(context, row((short) 0)), is(true));
+            assertThat(predicate.test(context, row((short) 100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val < 0.1", 
inputType);
+
+            assertThat(predicate.test(context, row((short) -100)), is(true));
+            assertThat(predicate.test(context, row((short) 0)), is(true));
+            assertThat(predicate.test(context, row((short) 100)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val > 0.1", 
inputType);
+
+            assertThat(predicate.test(context, row((short) -100)), is(false));
+            assertThat(predicate.test(context, row((short) 0)), is(false));
+            assertThat(predicate.test(context, row((short) 100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+    }
+
+    @Test
+    @TestFor(ColumnType.INT32)
+    void intTest() throws Exception {
+        EvaluationContext<Object[]> context = context();
+        StructNativeType inputType = singleColumnType(NativeTypes.INT32);
+
+        {
+            IgnitePredicate predicate = factory.predicate("val > 0", 
inputType);
+
+            assertThat(predicate.test(context, row(-100)), is(false));
+            assertThat(predicate.test(context, row(0)), is(false));
+            assertThat(predicate.test(context, row(100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val <> 0", 
inputType);
+
+            assertThat(predicate.test(context, row(-100)), is(true));
+            assertThat(predicate.test(context, row(0)), is(false));
+            assertThat(predicate.test(context, row(100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val <= 0", 
inputType);
+
+            assertThat(predicate.test(context, row(-100)), is(true));
+            assertThat(predicate.test(context, row(0)), is(true));
+            assertThat(predicate.test(context, row(100)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NULL", 
inputType);
+
+            assertThat(predicate.test(context, row(-100)), is(false));
+            assertThat(predicate.test(context, row(0)), is(false));
+            assertThat(predicate.test(context, row(100)), is(false));
+            assertThat(predicate.test(context, row(null)), is(true));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NOT NULL", 
inputType);
+
+            assertThat(predicate.test(context, row(-100)), is(true));
+            assertThat(predicate.test(context, row(0)), is(true));
+            assertThat(predicate.test(context, row(100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val < 0.1", 
inputType);
+
+            assertThat(predicate.test(context, row(-100)), is(true));
+            assertThat(predicate.test(context, row(0)), is(true));
+            assertThat(predicate.test(context, row(100)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val > 0.1", 
inputType);
+
+            assertThat(predicate.test(context, row(-100)), is(false));
+            assertThat(predicate.test(context, row(0)), is(false));
+            assertThat(predicate.test(context, row(100)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+    }
+
+    @Test
+    @TestFor(ColumnType.INT64)
+    void longTest() throws Exception {
+        EvaluationContext<Object[]> context = context();
+        StructNativeType inputType = singleColumnType(NativeTypes.INT64);
+
+        {
+            IgnitePredicate predicate = factory.predicate("val > 0", 
inputType);
+
+            assertThat(predicate.test(context, row(-100L)), is(false));
+            assertThat(predicate.test(context, row(0L)), is(false));
+            assertThat(predicate.test(context, row(100L)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val <> 0", 
inputType);
+
+            assertThat(predicate.test(context, row(-100L)), is(true));
+            assertThat(predicate.test(context, row(0L)), is(false));
+            assertThat(predicate.test(context, row(100L)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val <= 0", 
inputType);
+
+            assertThat(predicate.test(context, row(-100L)), is(true));
+            assertThat(predicate.test(context, row(0L)), is(true));
+            assertThat(predicate.test(context, row(100L)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NULL", 
inputType);
+
+            assertThat(predicate.test(context, row(-100L)), is(false));
+            assertThat(predicate.test(context, row(0L)), is(false));
+            assertThat(predicate.test(context, row(100L)), is(false));
+            assertThat(predicate.test(context, row(null)), is(true));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val IS NOT NULL", 
inputType);
+
+            assertThat(predicate.test(context, row(-100L)), is(true));
+            assertThat(predicate.test(context, row(0L)), is(true));
+            assertThat(predicate.test(context, row(100L)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val < 0.1", 
inputType);
+
+            assertThat(predicate.test(context, row(-100L)), is(true));
+            assertThat(predicate.test(context, row(0L)), is(true));
+            assertThat(predicate.test(context, row(100L)), is(false));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+
+        {
+            IgnitePredicate predicate = factory.predicate("val > 0.1", 
inputType);
+
+            assertThat(predicate.test(context, row(-100L)), is(false));
+            assertThat(predicate.test(context, row(0L)), is(false));
+            assertThat(predicate.test(context, row(100L)), is(true));
+            assertThat(predicate.test(context, row(null)), is(false));
+        }
+    }
+
+    @Test
+    @TestFor(ColumnType.FLOAT)

Review Comment:
   Should we check Infinity and NaN special values?



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

Reply via email to