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


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/BaseTypeCoercionTest.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.planner.datatypes;
+
+import static org.apache.ignite.lang.IgniteStringFormatter.format;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+
+import java.util.Arrays;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.SqlTypeUtil;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.sql.engine.framework.TestBuilders;
+import org.apache.ignite.internal.sql.engine.planner.AbstractPlannerTest;
+import 
org.apache.ignite.internal.sql.engine.planner.datatypes.utils.NumericPair;
+import org.apache.ignite.internal.sql.engine.planner.datatypes.utils.TypePair;
+import org.apache.ignite.internal.sql.engine.rel.IgniteRel;
+import 
org.apache.ignite.internal.sql.engine.rel.ProjectableFilterableTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.trait.IgniteDistributions;
+import org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.sql.engine.util.TypeUtils;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.junit.jupiter.params.provider.Arguments;
+
+abstract class BaseTypeCoercionTest extends AbstractPlannerTest {
+
+    static Stream<Arguments> allPairs() {

Review Comment:
   let's call it `allNumericPairs` or something



##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericBinaryOperationsTypeCoercionTest.java:
##########
@@ -0,0 +1,813 @@
+/*
+ * 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.planner.datatypes;
+
+import java.util.List;
+import java.util.stream.Stream;
+import org.apache.calcite.rex.RexNode;
+import 
org.apache.ignite.internal.sql.engine.planner.datatypes.utils.NumericPair;
+import org.apache.ignite.internal.sql.engine.planner.datatypes.utils.TypePair;
+import org.apache.ignite.internal.sql.engine.planner.datatypes.utils.Types;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.hamcrest.Matcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for binary arithmetic, 
when operands belongs to the NUMERIC type family.
+ *
+ * <p>This tests aim to help to understand in which cases implicit cast will 
be added to which operand when does arithmetic with a given
+ * numeric type pair.
+ */
+public class NumericBinaryOperationsTypeCoercionTest extends 
BaseTypeCoercionTest {
+
+    // No any type changes for `addition` operation from planner perspective.
+    @ParameterizedTest
+    @MethodSource("allPairs")
+    public void additionOp(NumericPair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), 
pair.second());
+
+        Matcher<RexNode> first = ofTypeWithoutCast(pair.first());
+        Matcher<RexNode> second = ofTypeWithoutCast(pair.second());
+
+        assertPlan("SELECT c1 + c2 FROM t", schema, operandMatcher(first, 
second)::matches, List.of());
+        assertPlan("SELECT c2 + c1 FROM t", schema, operandMatcher(second, 
first)::matches, List.of());
+    }
+
+    // No any type changes for `subtraction` operation from planner 
perspective.
+    @ParameterizedTest
+    @MethodSource("allPairs")
+    public void subtractionOp(NumericPair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), 
pair.second());
+
+        Matcher<RexNode> first = ofTypeWithoutCast(pair.first());
+        Matcher<RexNode> second = ofTypeWithoutCast(pair.second());
+
+        assertPlan("SELECT c1 - c2 FROM t", schema, operandMatcher(first, 
second)::matches, List.of());
+        assertPlan("SELECT c2 - c1 FROM t", schema, operandMatcher(second, 
first)::matches, List.of());
+    }
+
+    // No any type changes for `division` operation from planner perspective.
+    @ParameterizedTest
+    @MethodSource("allPairs")
+    public void divisionOp(NumericPair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), 
pair.second());
+
+        Matcher<RexNode> first = ofTypeWithoutCast(pair.first());
+        Matcher<RexNode> second = ofTypeWithoutCast(pair.second());
+
+        assertPlan("SELECT c1 / c2 FROM t", schema, operandMatcher(first, 
second)::matches, List.of());
+        assertPlan("SELECT c2 / c1 FROM t", schema, operandMatcher(second, 
first)::matches, List.of());
+    }
+
+    // No any type changes for `multiplication` operation from planner 
perspective.
+    @ParameterizedTest
+    @MethodSource("allPairs")
+    public void multiplicationOp(NumericPair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), 
pair.second());
+
+        Matcher<RexNode> first = ofTypeWithoutCast(pair.first());
+        Matcher<RexNode> second = ofTypeWithoutCast(pair.second());
+
+        assertPlan("SELECT c1 * c2 FROM t", schema, operandMatcher(first, 
second)::matches, List.of());
+        assertPlan("SELECT c2 * c1 FROM t", schema, operandMatcher(second, 
first)::matches, List.of());
+    }
+
+    //Have the following casts for modulo operation:
+    // REAL datatype always casts to DECIMAL(14,7)
+    // DOUBLE datatype always casts to DECIMAL(30,15)
+    // Any other types with no any changes
+    @ParameterizedTest
+    @MethodSource("moduloArgs")
+    public void moduloOp(

Review Comment:
   `NumericComparisonTypeCoercionTest` have verification that no one pair is 
missed even if new pair will be added to the enum (see 
`NumericComparisonTypeCoercionTest#argsIncludesAllTypePairs`). Do you have 
similar verification?



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