korlov42 commented on code in PR #6637:
URL: https://github.com/apache/ignite-3/pull/6637#discussion_r2379134322


##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItFloatingPointTest.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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;
+
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/** Test floating point special values test. */
+public class ItFloatingPointTest extends BaseSqlMultiStatementTest {
+    @BeforeAll
+    void createTestTable() {
+        sqlScript("CREATE TABLE test (id INT PRIMARY KEY, f FLOAT, d DOUBLE);"
+                + "CREATE INDEX test_f_idx on test (f);"
+                + "CREATE INDEX test_d_idx on test (d);"
+        );
+    }
+
+    @BeforeEach
+    void resetTableState() {
+        sqlScript("DELETE * FROM test;"
+                + "INSERT INTO test VALUES (1, '-Infinity'::FLOAT, 
'-Infinity'::DOUBLE)"
+                + "INSERT INTO test VALUES (2, 'Infinity'::FLOAT, 
'Infinity'::DOUBLE)"
+                + "INSERT INTO test VALUES (3, 'NaN'::FLOAT, 'NaN'::DOUBLE)"
+                + "INSERT INTO test VALUES (4, -0.0::FLOAT, -0.0::DOUBLE)"
+                + "INSERT INTO test VALUES (5, 0.0::FLOAT, 0.0::DOUBLE)"
+                + "INSERT INTO test VALUES (6, -1.0::FLOAT, -1.0::DOUBLE)"
+                + "INSERT INTO test VALUES (7, 1.0::FLOAT, 1.0::DOUBLE)"
+        );
+    }
+
+    @Override
+    protected int initialNodes() {
+        return 2;
+    }
+
+    @Test
+    void testArithmetic() {
+        assertEquals(-0.0f, sql("SELECT -0.0::FLOAT").get(0).get(0));

Review Comment:
   wondering why didn't you use `assertQuery()` here 



##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItFloatingPointTest.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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;
+
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/** Test floating point special values test. */
+public class ItFloatingPointTest extends BaseSqlMultiStatementTest {
+    @BeforeAll
+    void createTestTable() {
+        sqlScript("CREATE TABLE test (id INT PRIMARY KEY, f FLOAT, d DOUBLE);"
+                + "CREATE INDEX test_f_idx on test (f);"
+                + "CREATE INDEX test_d_idx on test (d);"
+        );
+
+        sql("INSERT INTO test VALUES (?, ?, ?)", 1, Float.POSITIVE_INFINITY, 
Double.POSITIVE_INFINITY);
+        sql("INSERT INTO test VALUES (?, ?, ?)", 2, Float.NEGATIVE_INFINITY, 
Double.NEGATIVE_INFINITY);
+        sql("INSERT INTO test VALUES (?, ?, ?)", 3, Float.NaN, Double.NaN);
+        sql("INSERT INTO test VALUES (?, ?, ?)", 4, -1.0f, -1.0d);
+        sql("INSERT INTO test VALUES (?, ?, ?)", 5, 1.0f, 1.0d);
+        sql("INSERT INTO test VALUES (?, ?, ?)", 6, -0.0f, -0.0d);
+        sql("INSERT INTO test VALUES (?, ?, ?)", 7, +0.0f, +0.0d);
+    }
+
+    @Override
+    protected int initialNodes() {
+        return 2;
+    }
+
+    @Test
+    void testArithmetic() {
+        assertEquals(-0.0f, sql("SELECT -0.0::FLOAT").get(0).get(0));
+        assertEquals(0.0f, sql("SELECT 0.0::FLOAT").get(0).get(0));
+
+        assertEquals(Float.NEGATIVE_INFINITY, sql("SELECT '-Infinity'::FLOAT - 
1").get(0).get(0));
+        assertEquals(Float.NEGATIVE_INFINITY, sql("SELECT '-Infinity'::FLOAT + 
1").get(0).get(0));
+
+        assertEquals(Float.POSITIVE_INFINITY, sql("SELECT '+Infinity'::FLOAT - 
1").get(0).get(0));
+        assertEquals(Float.POSITIVE_INFINITY, sql("SELECT '+Infinity'::FLOAT + 
1").get(0).get(0));
+
+        assertEquals(Float.NaN, sql("SELECT 'NaN'::FLOAT - 1").get(0).get(0));
+        assertEquals(Float.NaN, sql("SELECT '-NaN'::FLOAT + 1").get(0).get(0));
+        assertEquals(Float.NaN, sql("SELECT '-Infinity'::FLOAT + 
'+Infinity'::FLOAT").get(0).get(0));
+        assertEquals(Float.NaN, sql("SELECT '-Infinity'::FLOAT / 
'+Infinity'::FLOAT").get(0).get(0));
+
+        assertEquals(Double.NEGATIVE_INFINITY, sql("SELECT '-Infinity'::DOUBLE 
- 1").get(0).get(0));
+        assertEquals(Double.NEGATIVE_INFINITY, sql("SELECT '-Infinity'::DOUBLE 
+ 1").get(0).get(0));
+
+        assertEquals(Double.POSITIVE_INFINITY, sql("SELECT '+Infinity'::DOUBLE 
- 1").get(0).get(0));
+        assertEquals(Double.POSITIVE_INFINITY, sql("SELECT '+Infinity'::DOUBLE 
+ 1").get(0).get(0));
+
+        assertEquals(Double.NaN, sql("SELECT 'NaN'::DOUBLE - 
1").get(0).get(0));
+        assertEquals(Double.NaN, sql("SELECT '-NaN'::DOUBLE + 
1").get(0).get(0));
+        assertEquals(Double.NaN, sql("SELECT '-Infinity'::DOUBLE + 
'+Infinity'::DOUBLE").get(0).get(0));
+        assertEquals(Double.NaN, sql("SELECT '-Infinity'::DOUBLE / 
'+Infinity'::DOUBLE").get(0).get(0));
+    }
+
+    @Test
+    void testLiterals() {
+        assertEquals(-0.0f, sql("SELECT -0.0::FLOAT").get(0).get(0));
+        assertEquals(0.0f, sql("SELECT 0.0::FLOAT").get(0).get(0));
+        assertEquals(Float.NEGATIVE_INFINITY, sql("SELECT 
'-Infinity'::FLOAT").get(0).get(0));
+        assertEquals(Float.POSITIVE_INFINITY, sql("SELECT 
'+Infinity'::FLOAT").get(0).get(0));
+        assertEquals(Float.NaN, sql("SELECT 'NaN'::FLOAT").get(0).get(0));
+        assertEquals(Float.NaN, sql("SELECT -'NaN'::FLOAT").get(0).get(0));
+
+        assertEquals(-0.0d, sql("SELECT -0.0::DOUBLE").get(0).get(0));
+        assertEquals(0.0d, sql("SELECT 0.0::DOUBLE").get(0).get(0));
+        assertEquals(Double.NEGATIVE_INFINITY, sql("SELECT 
'-Infinity'::DOUBLE").get(0).get(0));
+        assertEquals(Double.POSITIVE_INFINITY, sql("SELECT 
'+Infinity'::DOUBLE").get(0).get(0));
+        assertEquals(Double.NaN, sql("SELECT 'NaN'::DOUBLE").get(0).get(0));
+        assertEquals(Double.NaN, sql("SELECT -'NaN'::DOUBLE").get(0).get(0));
+    }
+
+    @ParameterizedTest
+    @ValueSource(floats = {
+            -0.0f,
+            0.0f,
+            Float.NEGATIVE_INFINITY,
+            Float.POSITIVE_INFINITY,
+            Float.NaN
+    })
+    void testParameters(float f) {
+        assertEquals(f, (float) sql("SELECT ?", f).get(0).get(0));
+    }
+
+    @ParameterizedTest
+    @ValueSource(doubles = {
+            -0.0d,
+            0.0d,
+            Double.NEGATIVE_INFINITY,
+            Double.POSITIVE_INFINITY,
+            Double.NaN
+    })
+    void testParameters(double f) {
+        assertEquals(f, (double) sql("SELECT ?", f).get(0).get(0));
+    }
+
+    @Test
+    void testOrderBy() {
+        List<Float> floats = sql("SELECT f FROM test ORDER BY f")
+                
.stream().flatMap(List::stream).map(Float.class::cast).collect(toList());
+        List<Double> doubles = sql("SELECT d FROM test ORDER BY d")
+                
.stream().flatMap(List::stream).map(Double.class::cast).collect(toList());
+
+        assertThat(floats, contains(Float.NEGATIVE_INFINITY, -1.0f, -0.0f, 
0.0f, 1.0f, Float.POSITIVE_INFINITY, Float.NaN));

Review Comment:
   I would also add plan verification, that no explicit sorting is present. 
Otherwise it may obscure problem in index comparators



##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItFloatingPointTest.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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;
+
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/** Test floating point special values test. */
+public class ItFloatingPointTest extends BaseSqlMultiStatementTest {
+    @BeforeAll
+    void createTestTable() {
+        sqlScript("CREATE TABLE test (id INT PRIMARY KEY, f FLOAT, d DOUBLE);"

Review Comment:
   let's also add non-nullable variant of float and double. They may be treated 
differently in certain scenarios



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