You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "ygerzhedovich (via GitHub)" <gi...@apache.org> on 2023/09/13 14:37:44 UTC
[GitHub] [ignite-3] ygerzhedovich opened a new pull request, #2583: IGNITE-20000: Add planner test to verify numeric type coercion in bin…
ygerzhedovich opened a new pull request, #2583:
URL: https://github.com/apache/ignite-3/pull/2583
…ary arithmetic
Thank you for submitting the pull request.
To streamline the review process of the patch and ensure better code quality
we ask both an author and a reviewer to verify the following:
### The Review Checklist
- [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:
\- There is a single JIRA ticket related to the pull request.
\- The web-link to the pull request is attached to the JIRA ticket.
\- The JIRA ticket has the Patch Available state.
\- The description of the JIRA ticket explains WHAT was made, WHY and HOW.
\- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
- [ ] **Design:** new code conforms with the design principles of the components it is added to.
- [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
- [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
- [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
### Notes
- [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ygerzhedovich commented on a diff in pull request #2583: IGNITE-20000: Add planner test to verify numeric type coercion in bin…
Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich commented on code in PR #2583:
URL: https://github.com/apache/ignite-3/pull/2583#discussion_r1328820955
##########
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:
yep! I forgot did it. Fixed
##########
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:
ok
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] zstan commented on a diff in pull request #2583: IGNITE-20000: Add planner test to verify numeric type coercion in bin…
Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan commented on code in PR #2583:
URL: https://github.com/apache/ignite-3/pull/2583#discussion_r1328567268
##########
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(
+ TypePair typePair,
+ Matcher<RexNode> firstOperandMatcher,
+ Matcher<RexNode> secondOperandMatcher
+ ) throws Exception {
+ IgniteSchema schema = createSchemaWithTwoColumnTable(typePair.first(), typePair.second());
+
+ assertPlan("SELECT c1 % c2 FROM t", schema, operandMatcher(firstOperandMatcher, secondOperandMatcher)::matches, List.of());
+ assertPlan("SELECT c2 % c1 FROM t", schema, operandMatcher(secondOperandMatcher, firstOperandMatcher)::matches, List.of());
+ }
+
+ private static Stream<Arguments> moduloArgs() {
+ return Stream.of(
+ forTypePair(NumericPair.TINYINT_TINYINT)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_SMALLINT)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_INT)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_BIGINT)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_NUMBER_1)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_NUMBER_2)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_NUMBER_5)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_1_0)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_2_1)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_4_3)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_2_0)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_3_1)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_5_3)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_5_0)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_6_1)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_8_3)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_REAL)
+ .firstOpBeSame()
+ .secondOpMatches(castTo(Types.DECIMAL_14_7)),
+
+ forTypePair(NumericPair.TINYINT_DOUBLE)
+ .firstOpBeSame()
+ .secondOpMatches(castTo(Types.DECIMAL_30_15)),
Review Comment:
i just still don`t understand is it correct behavior or we need additional issue, probably @lowka may help here?
Overall looks good.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] korlov42 commented on a diff in pull request #2583: IGNITE-20000: Add planner test to verify numeric type coercion in bin…
Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] zstan commented on a diff in pull request #2583: IGNITE-20000: Add planner test to verify numeric type coercion in bin…
Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan commented on code in PR #2583:
URL: https://github.com/apache/ignite-3/pull/2583#discussion_r1328605916
##########
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(
+ TypePair typePair,
+ Matcher<RexNode> firstOperandMatcher,
+ Matcher<RexNode> secondOperandMatcher
+ ) throws Exception {
+ IgniteSchema schema = createSchemaWithTwoColumnTable(typePair.first(), typePair.second());
+
+ assertPlan("SELECT c1 % c2 FROM t", schema, operandMatcher(firstOperandMatcher, secondOperandMatcher)::matches, List.of());
+ assertPlan("SELECT c2 % c1 FROM t", schema, operandMatcher(secondOperandMatcher, firstOperandMatcher)::matches, List.of());
+ }
+
+ private static Stream<Arguments> moduloArgs() {
+ return Stream.of(
+ forTypePair(NumericPair.TINYINT_TINYINT)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_SMALLINT)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_INT)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_BIGINT)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_NUMBER_1)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_NUMBER_2)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_NUMBER_5)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_1_0)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_2_1)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_4_3)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_2_0)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_3_1)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_5_3)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_5_0)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_6_1)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_DECIMAL_8_3)
+ .firstOpBeSame()
+ .secondOpBeSame(),
+
+ forTypePair(NumericPair.TINYINT_REAL)
+ .firstOpBeSame()
+ .secondOpMatches(castTo(Types.DECIMAL_14_7)),
+
+ forTypePair(NumericPair.TINYINT_DOUBLE)
+ .firstOpBeSame()
+ .secondOpMatches(castTo(Types.DECIMAL_30_15)),
Review Comment:
With @lowka help seems it raised from :
org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion#implicitCast
// FLOAT/DOUBLE -> DECIMAL
if (SqlTypeUtil.isApproximateNumeric(in) && expected == SqlTypeFamily.EXACT_NUMERIC) {
return factory.decimalOf(in);
}
org.apache.calcite.rel.type.RelDataTypeFactoryImpl#decimalOf2 <-- here
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] zstan commented on pull request #2583: IGNITE-20000: Add planner test to verify numeric type coercion in bin…
Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan commented on PR #2583:
URL: https://github.com/apache/ignite-3/pull/2583#issuecomment-1723253331
@ygerzhedovich PR need to be fixed.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] korlov42 merged pull request #2583: IGNITE-20000: Add planner test to verify numeric type coercion in binary arithmetic
Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 merged PR #2583:
URL: https://github.com/apache/ignite-3/pull/2583
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org