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-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org