Skip to content

Commit

Permalink
IGNITE-22462 Add planner test to verify type coercion for set operati…
Browse files Browse the repository at this point in the history
…ons like UNION, INTERSECT and EXCEPT (#3957)
  • Loading branch information
ygerzhedovich authored Jun 21, 2024
1 parent 73d3bb8 commit 9f6d69f
Show file tree
Hide file tree
Showing 4 changed files with 967 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ static IgniteSchema createSchemaWithTwoColumnTable(NativeType c1, NativeType c2)
);
}

static IgniteSchema createSchemaWithTwoSingleColumnTable(NativeType c1, NativeType c2) {
return createSchema(
TestBuilders.table()
.name("T1")
.distribution(IgniteDistributions.single())
.addColumn("C1", c1)
.build(),
TestBuilders.table()
.name("T2")
.distribution(IgniteDistributions.single())
.addColumn("C2", c2)
.build()
);
}

static Matcher<IgniteRel> operandMatcher(Matcher<RexNode> first, Matcher<RexNode> second) {
return new BaseMatcher<>() {
@Override
Expand Down Expand Up @@ -156,13 +171,13 @@ static TestCaseBuilder forTypePair(TypePair typePair) {
*/
static class TestCaseBuilder {
private final TypePair pair;
private Matcher<RexNode> firstOpMatcher;
private Matcher<?> firstOpMatcher;

private TestCaseBuilder(TypePair pair) {
this.pair = pair;
}

TestCaseBuilder firstOpMatches(Matcher<RexNode> operandMatcher) {
TestCaseBuilder firstOpMatches(Matcher<?> operandMatcher) {
firstOpMatcher = operandMatcher;

return this;
Expand All @@ -174,7 +189,7 @@ TestCaseBuilder firstOpBeSame() {
return this;
}

Arguments secondOpMatches(Matcher<RexNode> operandMatcher) {
Arguments secondOpMatches(Matcher<?> operandMatcher) {
return Arguments.of(pair, firstOpMatcher, operandMatcher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,40 @@ private static Stream<Arguments> args() {
.secondOpMatches(ofTypeWithoutCast(NativeTypes.INT64)),

forTypePair(NumericPair.TINYINT_NUMBER_1)
.firstOpMatches(castTo(NativeTypes.numberOf(3)))
.secondOpMatches(castTo(NativeTypes.numberOf(3))),
.firstOpMatches(castTo(Types.NUMBER_3))
.secondOpMatches(castTo(Types.NUMBER_3)),

forTypePair(NumericPair.TINYINT_NUMBER_2)
.firstOpMatches(castTo(NativeTypes.numberOf(3)))
.secondOpMatches(castTo(NativeTypes.numberOf(3))),
.firstOpMatches(castTo(Types.NUMBER_3))
.secondOpMatches(castTo(Types.NUMBER_3)),

forTypePair(NumericPair.TINYINT_NUMBER_5)
.firstOpMatches(castTo(Types.NUMBER_5))
.secondOpMatches(ofTypeWithoutCast(Types.NUMBER_5)),

forTypePair(NumericPair.TINYINT_DECIMAL_1_0)
.firstOpMatches(castTo(NativeTypes.decimalOf(3, 0)))
.secondOpMatches(castTo(NativeTypes.decimalOf(3, 0))),
.firstOpMatches(castTo(Types.DECIMAL_3_0))
.secondOpMatches(castTo(Types.DECIMAL_3_0)),

forTypePair(NumericPair.TINYINT_DECIMAL_2_1)
.firstOpMatches(castTo(NativeTypes.decimalOf(4, 1)))
.secondOpMatches(castTo(NativeTypes.decimalOf(4, 1))),
.firstOpMatches(castTo(Types.DECIMAL_4_1))
.secondOpMatches(castTo(Types.DECIMAL_4_1)),

forTypePair(NumericPair.TINYINT_DECIMAL_4_3)
.firstOpMatches(castTo(NativeTypes.decimalOf(6, 3)))
.secondOpMatches(castTo(NativeTypes.decimalOf(6, 3))),
.firstOpMatches(castTo(Types.DECIMAL_6_3))
.secondOpMatches(castTo(Types.DECIMAL_6_3)),

forTypePair(NumericPair.TINYINT_DECIMAL_2_0)
.firstOpMatches(castTo(NativeTypes.decimalOf(3, 0)))
.secondOpMatches(castTo(NativeTypes.decimalOf(3, 0))),
.firstOpMatches(castTo(Types.DECIMAL_3_0))
.secondOpMatches(castTo(Types.DECIMAL_3_0)),

forTypePair(NumericPair.TINYINT_DECIMAL_3_1)
.firstOpMatches(castTo(NativeTypes.decimalOf(4, 1)))
.secondOpMatches(castTo(NativeTypes.decimalOf(4, 1))),
.firstOpMatches(castTo(Types.DECIMAL_4_1))
.secondOpMatches(castTo(Types.DECIMAL_4_1)),

forTypePair(NumericPair.TINYINT_DECIMAL_5_3)
.firstOpMatches(castTo(NativeTypes.decimalOf(6, 3)))
.secondOpMatches(castTo(NativeTypes.decimalOf(6, 3))),
.firstOpMatches(castTo(Types.DECIMAL_6_3))
.secondOpMatches(castTo(Types.DECIMAL_6_3)),

forTypePair(NumericPair.TINYINT_DECIMAL_5_0)
.firstOpMatches(castTo(Types.DECIMAL_5_0))
Expand Down Expand Up @@ -194,52 +194,52 @@ private static Stream<Arguments> args() {
.secondOpMatches(ofTypeWithoutCast(NativeTypes.INT64)),

forTypePair(NumericPair.INT_NUMBER_1)
.firstOpMatches(castTo(NativeTypes.numberOf(10)))
.secondOpMatches(castTo(NativeTypes.numberOf(10))),
.firstOpMatches(castTo(Types.NUMBER_10))
.secondOpMatches(castTo(Types.NUMBER_10)),

forTypePair(NumericPair.INT_NUMBER_2)
.firstOpMatches(castTo(NativeTypes.numberOf(10)))
.secondOpMatches(castTo(NativeTypes.numberOf(10))),
.firstOpMatches(castTo(Types.NUMBER_10))
.secondOpMatches(castTo(Types.NUMBER_10)),

forTypePair(NumericPair.INT_NUMBER_5)
.firstOpMatches(castTo(NativeTypes.numberOf(10)))
.secondOpMatches(castTo(NativeTypes.numberOf(10))),
.firstOpMatches(castTo(Types.NUMBER_10))
.secondOpMatches(castTo(Types.NUMBER_10)),

forTypePair(NumericPair.INT_DECIMAL_1_0)
.firstOpMatches(castTo(NativeTypes.decimalOf(10, 0)))
.secondOpMatches(castTo(NativeTypes.decimalOf(10, 0))),
.firstOpMatches(castTo(Types.DECIMAL_10_0))
.secondOpMatches(castTo(Types.DECIMAL_10_0)),

forTypePair(NumericPair.INT_DECIMAL_2_1)
.firstOpMatches(castTo(NativeTypes.decimalOf(11, 1)))
.secondOpMatches(castTo(NativeTypes.decimalOf(11, 1))),
.firstOpMatches(castTo(Types.DECIMAL_11_1))
.secondOpMatches(castTo(Types.DECIMAL_11_1)),

forTypePair(NumericPair.INT_DECIMAL_4_3)
.firstOpMatches(castTo(NativeTypes.decimalOf(13, 3)))
.secondOpMatches(castTo(NativeTypes.decimalOf(13, 3))),
.firstOpMatches(castTo(Types.DECIMAL_13_3))
.secondOpMatches(castTo(Types.DECIMAL_13_3)),

forTypePair(NumericPair.INT_DECIMAL_2_0)
.firstOpMatches(castTo(NativeTypes.decimalOf(10, 0)))
.secondOpMatches(castTo(NativeTypes.decimalOf(10, 0))),
.firstOpMatches(castTo(Types.DECIMAL_10_0))
.secondOpMatches(castTo(Types.DECIMAL_10_0)),

forTypePair(NumericPair.INT_DECIMAL_3_1)
.firstOpMatches(castTo(NativeTypes.decimalOf(11, 1)))
.secondOpMatches(castTo(NativeTypes.decimalOf(11, 1))),
.firstOpMatches(castTo(Types.DECIMAL_11_1))
.secondOpMatches(castTo(Types.DECIMAL_11_1)),

forTypePair(NumericPair.INT_DECIMAL_5_3)
.firstOpMatches(castTo(NativeTypes.decimalOf(13, 3)))
.secondOpMatches(castTo(NativeTypes.decimalOf(13, 3))),
.firstOpMatches(castTo(Types.DECIMAL_13_3))
.secondOpMatches(castTo(Types.DECIMAL_13_3)),

forTypePair(NumericPair.INT_DECIMAL_5_0)
.firstOpMatches(castTo(NativeTypes.decimalOf(10, 0)))
.secondOpMatches(castTo(NativeTypes.decimalOf(10, 0))),
.firstOpMatches(castTo(Types.DECIMAL_10_0))
.secondOpMatches(castTo(Types.DECIMAL_10_0)),

forTypePair(NumericPair.INT_DECIMAL_6_1)
.firstOpMatches(castTo(NativeTypes.decimalOf(11, 1)))
.secondOpMatches(castTo(NativeTypes.decimalOf(11, 1))),
.firstOpMatches(castTo(Types.DECIMAL_11_1))
.secondOpMatches(castTo(Types.DECIMAL_11_1)),

forTypePair(NumericPair.INT_DECIMAL_8_3)
.firstOpMatches(castTo(NativeTypes.decimalOf(13, 3)))
.secondOpMatches(castTo(NativeTypes.decimalOf(13, 3))),
.firstOpMatches(castTo(Types.DECIMAL_13_3))
.secondOpMatches(castTo(Types.DECIMAL_13_3)),

forTypePair(NumericPair.INT_REAL)
.firstOpMatches(castTo(NativeTypes.FLOAT))
Expand All @@ -255,52 +255,52 @@ private static Stream<Arguments> args() {
.secondOpMatches(ofTypeWithoutCast(NativeTypes.INT64)),

forTypePair(NumericPair.BIGINT_NUMBER_1)
.firstOpMatches(castTo(NativeTypes.numberOf(19)))
.secondOpMatches(castTo(NativeTypes.numberOf(19))),
.firstOpMatches(castTo(Types.NUMBER_19))
.secondOpMatches(castTo(Types.NUMBER_19)),

forTypePair(NumericPair.BIGINT_NUMBER_2)
.firstOpMatches(castTo(NativeTypes.numberOf(19)))
.secondOpMatches(castTo(NativeTypes.numberOf(19))),
.firstOpMatches(castTo(Types.NUMBER_19))
.secondOpMatches(castTo(Types.NUMBER_19)),

forTypePair(NumericPair.BIGINT_NUMBER_5)
.firstOpMatches(castTo(NativeTypes.numberOf(19)))
.secondOpMatches(castTo(NativeTypes.numberOf(19))),
.firstOpMatches(castTo(Types.NUMBER_19))
.secondOpMatches(castTo(Types.NUMBER_19)),

forTypePair(NumericPair.BIGINT_DECIMAL_1_0)
.firstOpMatches(castTo(NativeTypes.decimalOf(19, 0)))
.secondOpMatches(castTo(NativeTypes.decimalOf(19, 0))),
.firstOpMatches(castTo(Types.DECIMAL_19_0))
.secondOpMatches(castTo(Types.DECIMAL_19_0)),

forTypePair(NumericPair.BIGINT_DECIMAL_2_1)
.firstOpMatches(castTo(NativeTypes.decimalOf(20, 1)))
.secondOpMatches(castTo(NativeTypes.decimalOf(20, 1))),
.firstOpMatches(castTo(Types.DECIMAL_20_1))
.secondOpMatches(castTo(Types.DECIMAL_20_1)),

forTypePair(NumericPair.BIGINT_DECIMAL_4_3)
.firstOpMatches(castTo(NativeTypes.decimalOf(22, 3)))
.secondOpMatches(castTo(NativeTypes.decimalOf(22, 3))),
.firstOpMatches(castTo(Types.DECIMAL_22_3))
.secondOpMatches(castTo(Types.DECIMAL_22_3)),

forTypePair(NumericPair.BIGINT_DECIMAL_2_0)
.firstOpMatches(castTo(NativeTypes.decimalOf(19, 0)))
.secondOpMatches(castTo(NativeTypes.decimalOf(19, 0))),
.firstOpMatches(castTo(Types.DECIMAL_19_0))
.secondOpMatches(castTo(Types.DECIMAL_19_0)),

forTypePair(NumericPair.BIGINT_DECIMAL_3_1)
.firstOpMatches(castTo(NativeTypes.decimalOf(20, 1)))
.secondOpMatches(castTo(NativeTypes.decimalOf(20, 1))),
.firstOpMatches(castTo(Types.DECIMAL_20_1))
.secondOpMatches(castTo(Types.DECIMAL_20_1)),

forTypePair(NumericPair.BIGINT_DECIMAL_5_3)
.firstOpMatches(castTo(NativeTypes.decimalOf(22, 3)))
.secondOpMatches(castTo(NativeTypes.decimalOf(22, 3))),
.firstOpMatches(castTo(Types.DECIMAL_22_3))
.secondOpMatches(castTo(Types.DECIMAL_22_3)),

forTypePair(NumericPair.BIGINT_DECIMAL_5_0)
.firstOpMatches(castTo(NativeTypes.decimalOf(19, 0)))
.secondOpMatches(castTo(NativeTypes.decimalOf(19, 0))),
.firstOpMatches(castTo(Types.DECIMAL_19_0))
.secondOpMatches(castTo(Types.DECIMAL_19_0)),

forTypePair(NumericPair.BIGINT_DECIMAL_6_1)
.firstOpMatches(castTo(NativeTypes.decimalOf(20, 1)))
.secondOpMatches(castTo(NativeTypes.decimalOf(20, 1))),
.firstOpMatches(castTo(Types.DECIMAL_20_1))
.secondOpMatches(castTo(Types.DECIMAL_20_1)),

forTypePair(NumericPair.BIGINT_DECIMAL_8_3)
.firstOpMatches(castTo(NativeTypes.decimalOf(22, 3)))
.secondOpMatches(castTo(NativeTypes.decimalOf(22, 3))),
.firstOpMatches(castTo(Types.DECIMAL_22_3))
.secondOpMatches(castTo(Types.DECIMAL_22_3)),

forTypePair(NumericPair.BIGINT_REAL)
.firstOpMatches(castTo(NativeTypes.FLOAT))
Expand Down
Loading

0 comments on commit 9f6d69f

Please sign in to comment.