You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "lowka (via GitHub)" <gi...@apache.org> on 2024/09/19 11:26:43 UTC

[PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

lowka opened a new pull request, #4424:
URL: https://github.com/apache/ignite-3/pull/4424

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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1772697026


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,571 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            NativeType type1, NativeType type2,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<Arguments> intTypes =
+                Arrays.stream(NumericPair.values())
+                        .filter(p -> INT_TYPES.contains(p.first()))
+                        .filter(p -> INT_TYPES.contains(p.second()))
+                        .map(p -> Arguments.of(
+                                p.first(), p.second(),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                p.second())
+                        );
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(
+                        NativeTypes.FLOAT, NativeTypes.INT8,
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT8),
+                        Types.DECIMAL_10_7),
+
+                Arguments.of(
+                        NativeTypes.FLOAT, NativeTypes.INT32,
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT32),

Review Comment:
   why is INT16 skipped?



##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,571 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.

Review Comment:
   ```suggestion
    * A set of tests to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
   ```



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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1772708702


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,571 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            NativeType type1, NativeType type2,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<Arguments> intTypes =
+                Arrays.stream(NumericPair.values())
+                        .filter(p -> INT_TYPES.contains(p.first()))
+                        .filter(p -> INT_TYPES.contains(p.second()))
+                        .map(p -> Arguments.of(
+                                p.first(), p.second(),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                p.second())
+                        );
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(

Review Comment:
   It would also be nice to have a more readable description of the test case :sunglasses:  it's not easy to parse such description :thinking: 
   ![image](https://github.com/user-attachments/assets/00b87fc7-eaea-4d54-b517-0881762b4414)
   



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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1773276680


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,595 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.api.Named;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of tests to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            TypePair typePair,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        NativeType type1 = typePair.first();
+        NativeType type2 = typePair.second();
+
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<TypePair> intIntTypes = INT_TYPES.stream().flatMap(t1 -> INT_TYPES.stream().map(t2 -> Types.typePair(t1, t2)));
+
+        Stream<Arguments> intInt = intIntTypes.map(p -> Arguments.of(Types.typePair(p.first(), p.second()),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                namedType(p.second())));
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT8),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT8),
+                        namedType(Types.DECIMAL_10_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT16),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT16),
+                        namedType(Types.DECIMAL_12_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT32),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT32),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT64),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT64),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT8),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT8),
+                        namedType(Types.DECIMAL_18_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT16),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT16),
+                        namedType(Types.DECIMAL_20_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT32),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT32),
+                        namedType(Types.DECIMAL_25_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT64),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT64),
+                        namedType(Types.DECIMAL_30_15))
+        );
+
+        Stream<Arguments> intApproxTypes = Stream.of(
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT8, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT8), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_10_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT16, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT16), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_12_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT32, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT32), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT64, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT64), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT8, NativeTypes.DOUBLE),
+                        ofTypeWithoutCast(NativeTypes.INT8), castTo(Types.DECIMAL_30_15),
+                        namedType(Types.DECIMAL_18_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT16, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT16), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_12_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT32, NativeTypes.DOUBLE),
+                        ofTypeWithoutCast(NativeTypes.INT32), castTo(Types.DECIMAL_30_15),
+                        namedType(Types.DECIMAL_25_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT64, NativeTypes.DOUBLE),
+                        ofTypeWithoutCast(NativeTypes.INT64), castTo(Types.DECIMAL_30_15),
+                        namedType(Types.DECIMAL_30_15))
+        );
+
+        return Stream.concat(Stream.concat(intInt, approxNumInt), intApproxTypes);
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void exp(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        Matcher<RelNode> matcher = new FunctionCallMatcher(List.of(ofTypeWithoutCast(type))).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT EXP(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> numeric() {
+        List<NativeType> numeric = new ArrayList<>();
+
+        for (NumericPair pair : NumericPair.values()) {
+            if (!numeric.contains(pair.first())) {
+                numeric.add(pair.first());
+            }
+        }
+
+        return numeric.stream().map(t -> Named.named(t.displayName(), t)).map(Arguments::of);
+    }
+
+    @ParameterizedTest
+    @EnumSource(NumericPair.class)
+    public void power(TypePair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT POWER(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void ln(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT LN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void log10(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT LOG10(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void abs(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(type);
+
+        assertPlan("SELECT ABS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void rand(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args)
+                .returnTypeNullability(false)
+                .resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT RAND(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void randInteger1(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args)
+                .returnTypeNullability(false)
+                .resultWillBe(NativeTypes.INT32);
+
+        assertPlan("SELECT RAND_INTEGER(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @EnumSource(NumericPair.class)
+    public void randInteger2(TypePair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args)
+                .returnTypeNullability(false)
+                .resultWillBe(NativeTypes.INT32);
+
+        assertPlan("SELECT RAND_INTEGER(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void acos(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ACOS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void asin(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ASIN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void atan(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ATAN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @EnumSource(NumericPair.class)
+    public void atan2(TypePair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ATAN2(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sqrt(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        // SQRT is rewritten to POWER($t0, 0.5:DECIMAL(2, 1))
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type), ofTypeWithoutCast(NativeTypes.decimalOf(2, 1)));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT SQRT(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cbrt(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT CBRT(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cos(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT COS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cosh(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT COSH(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cot(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT COT(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void degrees(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT DEGREES(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void radians(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT RADIANS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void round(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        NativeType returnType;
+        if (type instanceof DecimalNativeType) {
+            returnType = decimalWithZeroScale((DecimalNativeType) type);
+        } else {
+            returnType = type;
+        }
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT ROUND(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("round2Args")
+    public void round2(NumericPair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(pair.first());
+
+        assertPlan("SELECT ROUND(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<NumericPair> round2Args() {
+        List<NativeType> ints = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+        return Arrays.stream(NumericPair.values()).filter(p -> ints.contains(p.second()));
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sign(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(type);
+
+        assertPlan("SELECT SIGN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sin(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT SIN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sinh(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT SINH(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void tan(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT TAN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void tanh(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT TANH(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void truncate(NativeType type) throws Exception {

Review Comment:
   Thanks. 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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1772697026


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,571 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            NativeType type1, NativeType type2,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<Arguments> intTypes =
+                Arrays.stream(NumericPair.values())
+                        .filter(p -> INT_TYPES.contains(p.first()))
+                        .filter(p -> INT_TYPES.contains(p.second()))
+                        .map(p -> Arguments.of(
+                                p.first(), p.second(),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                p.second())
+                        );
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(
+                        NativeTypes.FLOAT, NativeTypes.INT8,
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT8),
+                        Types.DECIMAL_10_7),
+
+                Arguments.of(
+                        NativeTypes.FLOAT, NativeTypes.INT32,
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT32),

Review Comment:
   why is INT16 skipped?
   
   more precisely, I mean, we have pairs
   INT8, FLOAT
   INT32 FLOAT
   INT64 FLOAT
   but don't have INT16 FLOAT?



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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich merged PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424


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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1773114785


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,571 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            NativeType type1, NativeType type2,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<Arguments> intTypes =
+                Arrays.stream(NumericPair.values())
+                        .filter(p -> INT_TYPES.contains(p.first()))
+                        .filter(p -> INT_TYPES.contains(p.second()))
+                        .map(p -> Arguments.of(
+                                p.first(), p.second(),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                p.second())
+                        );
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(

Review Comment:
   Replaced with `arg 1 typeName_arg2 typeName, arg matcher1, arg matcher2, ret typeName`.



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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1772708702


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,571 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            NativeType type1, NativeType type2,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<Arguments> intTypes =
+                Arrays.stream(NumericPair.values())
+                        .filter(p -> INT_TYPES.contains(p.first()))
+                        .filter(p -> INT_TYPES.contains(p.second()))
+                        .map(p -> Arguments.of(
+                                p.first(), p.second(),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                p.second())
+                        );
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(

Review Comment:
   It would also be nice to have a more readable description of the test case, if possible :sunglasses:  it's not easy to parse such description :thinking: 
   ![image](https://github.com/user-attachments/assets/00b87fc7-eaea-4d54-b517-0881762b4414)
   



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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1773207637


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,595 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.api.Named;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of tests to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            TypePair typePair,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        NativeType type1 = typePair.first();
+        NativeType type2 = typePair.second();
+
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<TypePair> intIntTypes = INT_TYPES.stream().flatMap(t1 -> INT_TYPES.stream().map(t2 -> Types.typePair(t1, t2)));
+
+        Stream<Arguments> intInt = intIntTypes.map(p -> Arguments.of(Types.typePair(p.first(), p.second()),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                namedType(p.second())));
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT8),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT8),
+                        namedType(Types.DECIMAL_10_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT16),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT16),
+                        namedType(Types.DECIMAL_12_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT32),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT32),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT64),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT64),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT8),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT8),
+                        namedType(Types.DECIMAL_18_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT16),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT16),
+                        namedType(Types.DECIMAL_20_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT32),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT32),
+                        namedType(Types.DECIMAL_25_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT64),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT64),
+                        namedType(Types.DECIMAL_30_15))
+        );
+
+        Stream<Arguments> intApproxTypes = Stream.of(
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT8, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT8), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_10_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT16, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT16), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_12_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT32, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT32), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT64, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT64), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT8, NativeTypes.DOUBLE),
+                        ofTypeWithoutCast(NativeTypes.INT8), castTo(Types.DECIMAL_30_15),
+                        namedType(Types.DECIMAL_18_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT16, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT16), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_12_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT32, NativeTypes.DOUBLE),
+                        ofTypeWithoutCast(NativeTypes.INT32), castTo(Types.DECIMAL_30_15),
+                        namedType(Types.DECIMAL_25_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT64, NativeTypes.DOUBLE),
+                        ofTypeWithoutCast(NativeTypes.INT64), castTo(Types.DECIMAL_30_15),
+                        namedType(Types.DECIMAL_30_15))
+        );
+
+        return Stream.concat(Stream.concat(intInt, approxNumInt), intApproxTypes);
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void exp(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        Matcher<RelNode> matcher = new FunctionCallMatcher(List.of(ofTypeWithoutCast(type))).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT EXP(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> numeric() {
+        List<NativeType> numeric = new ArrayList<>();
+
+        for (NumericPair pair : NumericPair.values()) {
+            if (!numeric.contains(pair.first())) {
+                numeric.add(pair.first());
+            }
+        }
+
+        return numeric.stream().map(t -> Named.named(t.displayName(), t)).map(Arguments::of);
+    }
+
+    @ParameterizedTest
+    @EnumSource(NumericPair.class)
+    public void power(TypePair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT POWER(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void ln(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT LN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void log10(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT LOG10(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void abs(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(type);
+
+        assertPlan("SELECT ABS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void rand(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args)
+                .returnTypeNullability(false)
+                .resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT RAND(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void randInteger1(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args)
+                .returnTypeNullability(false)
+                .resultWillBe(NativeTypes.INT32);
+
+        assertPlan("SELECT RAND_INTEGER(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @EnumSource(NumericPair.class)
+    public void randInteger2(TypePair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args)
+                .returnTypeNullability(false)
+                .resultWillBe(NativeTypes.INT32);
+
+        assertPlan("SELECT RAND_INTEGER(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void acos(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ACOS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void asin(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ASIN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void atan(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ATAN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @EnumSource(NumericPair.class)
+    public void atan2(TypePair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ATAN2(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sqrt(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        // SQRT is rewritten to POWER($t0, 0.5:DECIMAL(2, 1))
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type), ofTypeWithoutCast(NativeTypes.decimalOf(2, 1)));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT SQRT(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cbrt(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT CBRT(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cos(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT COS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cosh(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT COSH(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cot(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT COT(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void degrees(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT DEGREES(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void radians(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT RADIANS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void round(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        NativeType returnType;
+        if (type instanceof DecimalNativeType) {
+            returnType = decimalWithZeroScale((DecimalNativeType) type);
+        } else {
+            returnType = type;
+        }
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT ROUND(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("round2Args")
+    public void round2(NumericPair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(pair.first());
+
+        assertPlan("SELECT ROUND(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<NumericPair> round2Args() {
+        List<NativeType> ints = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+        return Arrays.stream(NumericPair.values()).filter(p -> ints.contains(p.second()));
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sign(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(type);
+
+        assertPlan("SELECT SIGN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sin(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT SIN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sinh(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT SINH(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void tan(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT TAN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void tanh(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT TANH(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void truncate(NativeType type) throws Exception {

Review Comment:
   looks like we need to add tests for CEILING and FLOOR also :sunglasses: 



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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1773107428


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,571 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.

Review Comment:
   Fixed.



##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,571 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            NativeType type1, NativeType type2,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<Arguments> intTypes =
+                Arrays.stream(NumericPair.values())
+                        .filter(p -> INT_TYPES.contains(p.first()))
+                        .filter(p -> INT_TYPES.contains(p.second()))
+                        .map(p -> Arguments.of(
+                                p.first(), p.second(),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                p.second())
+                        );
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(
+                        NativeTypes.FLOAT, NativeTypes.INT8,
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT8),
+                        Types.DECIMAL_10_7),
+
+                Arguments.of(
+                        NativeTypes.FLOAT, NativeTypes.INT32,
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT32),

Review Comment:
   Added these types.



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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1773207637


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,595 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.api.Named;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of tests to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            TypePair typePair,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        NativeType type1 = typePair.first();
+        NativeType type2 = typePair.second();
+
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<TypePair> intIntTypes = INT_TYPES.stream().flatMap(t1 -> INT_TYPES.stream().map(t2 -> Types.typePair(t1, t2)));
+
+        Stream<Arguments> intInt = intIntTypes.map(p -> Arguments.of(Types.typePair(p.first(), p.second()),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                namedType(p.second())));
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT8),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT8),
+                        namedType(Types.DECIMAL_10_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT16),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT16),
+                        namedType(Types.DECIMAL_12_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT32),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT32),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.FLOAT, NativeTypes.INT64),
+                        castTo(Types.DECIMAL_14_7), ofTypeWithoutCast(NativeTypes.INT64),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT8),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT8),
+                        namedType(Types.DECIMAL_18_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT16),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT16),
+                        namedType(Types.DECIMAL_20_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT32),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT32),
+                        namedType(Types.DECIMAL_25_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.DOUBLE, NativeTypes.INT64),
+                        castTo(Types.DECIMAL_30_15), ofTypeWithoutCast(NativeTypes.INT64),
+                        namedType(Types.DECIMAL_30_15))
+        );
+
+        Stream<Arguments> intApproxTypes = Stream.of(
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT8, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT8), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_10_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT16, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT16), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_12_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT32, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT32), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT64, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT64), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_14_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT8, NativeTypes.DOUBLE),
+                        ofTypeWithoutCast(NativeTypes.INT8), castTo(Types.DECIMAL_30_15),
+                        namedType(Types.DECIMAL_18_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT16, NativeTypes.FLOAT),
+                        ofTypeWithoutCast(NativeTypes.INT16), castTo(Types.DECIMAL_14_7),
+                        namedType(Types.DECIMAL_12_7)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT32, NativeTypes.DOUBLE),
+                        ofTypeWithoutCast(NativeTypes.INT32), castTo(Types.DECIMAL_30_15),
+                        namedType(Types.DECIMAL_25_15)),
+
+                Arguments.of(
+                        Types.typePair(NativeTypes.INT64, NativeTypes.DOUBLE),
+                        ofTypeWithoutCast(NativeTypes.INT64), castTo(Types.DECIMAL_30_15),
+                        namedType(Types.DECIMAL_30_15))
+        );
+
+        return Stream.concat(Stream.concat(intInt, approxNumInt), intApproxTypes);
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void exp(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        Matcher<RelNode> matcher = new FunctionCallMatcher(List.of(ofTypeWithoutCast(type))).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT EXP(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> numeric() {
+        List<NativeType> numeric = new ArrayList<>();
+
+        for (NumericPair pair : NumericPair.values()) {
+            if (!numeric.contains(pair.first())) {
+                numeric.add(pair.first());
+            }
+        }
+
+        return numeric.stream().map(t -> Named.named(t.displayName(), t)).map(Arguments::of);
+    }
+
+    @ParameterizedTest
+    @EnumSource(NumericPair.class)
+    public void power(TypePair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT POWER(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void ln(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT LN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void log10(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT LOG10(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void abs(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(type);
+
+        assertPlan("SELECT ABS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void rand(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args)
+                .returnTypeNullability(false)
+                .resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT RAND(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void randInteger1(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args)
+                .returnTypeNullability(false)
+                .resultWillBe(NativeTypes.INT32);
+
+        assertPlan("SELECT RAND_INTEGER(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @EnumSource(NumericPair.class)
+    public void randInteger2(TypePair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args)
+                .returnTypeNullability(false)
+                .resultWillBe(NativeTypes.INT32);
+
+        assertPlan("SELECT RAND_INTEGER(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void acos(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ACOS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void asin(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ASIN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void atan(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ATAN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @EnumSource(NumericPair.class)
+    public void atan2(TypePair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT ATAN2(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sqrt(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        // SQRT is rewritten to POWER($t0, 0.5:DECIMAL(2, 1))
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type), ofTypeWithoutCast(NativeTypes.decimalOf(2, 1)));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT SQRT(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cbrt(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT CBRT(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cos(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT COS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cosh(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT COSH(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void cot(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT COT(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void degrees(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT DEGREES(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void radians(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT RADIANS(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void round(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        NativeType returnType;
+        if (type instanceof DecimalNativeType) {
+            returnType = decimalWithZeroScale((DecimalNativeType) type);
+        } else {
+            returnType = type;
+        }
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT ROUND(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("round2Args")
+    public void round2(NumericPair pair) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(pair.first(), pair.second());
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(pair.first()), ofTypeWithoutCast(pair.second()));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(pair.first());
+
+        assertPlan("SELECT ROUND(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<NumericPair> round2Args() {
+        List<NativeType> ints = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+        return Arrays.stream(NumericPair.values()).filter(p -> ints.contains(p.second()));
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sign(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(type);
+
+        assertPlan("SELECT SIGN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sin(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT SIN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void sinh(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT SINH(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void tan(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT TAN(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void tanh(NativeType type) throws Exception {
+        IgniteSchema schema = createSchemaWithSingleColumnTable(type);
+
+        List<Matcher<RexNode>> args = List.of(ofTypeWithoutCast(type));
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(NativeTypes.DOUBLE);
+
+        assertPlan("SELECT TANH(C1) FROM T", schema, matcher::matches, List.of());
+    }
+
+    @ParameterizedTest
+    @MethodSource("numeric")
+    public void truncate(NativeType type) throws Exception {

Review Comment:
   looks like we need to add tests for CEILING and FLOOR also? :sunglasses: 



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


Re: [PR] IGNITE-23041: Sql. Add planner test to verify numeric type coercion for function arguments [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4424:
URL: https://github.com/apache/ignite-3/pull/4424#discussion_r1772708702


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/NumericFunctionsTypeCoercionTest.java:
##########
@@ -0,0 +1,571 @@
+/*
+ * 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.internal.sql.engine.util.TypeUtils.native2relationalType;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+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.rel.IgniteTableScan;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.type.DecimalNativeType;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * A set of test to verify behavior of type coercion for numeric functions, when operand belongs to the NUMERIC type family.
+ */
+public class NumericFunctionsTypeCoercionTest extends BaseTypeCoercionTest {
+
+    private static final List<NativeType> INT_TYPES = List.of(NativeTypes.INT8, NativeTypes.INT16, NativeTypes.INT32, NativeTypes.INT64);
+
+    @ParameterizedTest
+    @MethodSource("modArgs")
+    public void mod(
+            NativeType type1, NativeType type2,
+            Matcher<RexNode> arg1, Matcher<RexNode> arg2,
+            NativeType returnType
+    ) throws Exception {
+        IgniteSchema schema = createSchemaWithTwoColumnTable(type1, type2);
+
+        List<Matcher<RexNode>> args = List.of(arg1, arg2);
+        Matcher<RelNode> matcher = new FunctionCallMatcher(args).resultWillBe(returnType);
+
+        assertPlan("SELECT MOD(C1, C2) FROM T", schema, matcher::matches, List.of());
+    }
+
+    private static Stream<Arguments> modArgs() {
+        Stream<Arguments> intTypes =
+                Arrays.stream(NumericPair.values())
+                        .filter(p -> INT_TYPES.contains(p.first()))
+                        .filter(p -> INT_TYPES.contains(p.second()))
+                        .map(p -> Arguments.of(
+                                p.first(), p.second(),
+                                ofTypeWithoutCast(p.first()), ofTypeWithoutCast(p.second()),
+                                p.second())
+                        );
+
+        Stream<Arguments> approxNumInt = Stream.of(
+                Arguments.of(

Review Comment:
   It would also be nice to have a more readable description of the test case, :sunglasses:  it's not easy to parse such description :thinking: 
   ![image](https://github.com/user-attachments/assets/00b87fc7-eaea-4d54-b517-0881762b4414)
   



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