Skip to content

Commit

Permalink
Improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenada committed Feb 2, 2024
1 parent 184d26b commit ea2b758
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -799,33 +799,38 @@ final RelMetadataFixture sql(String sql) {
}

@Test void testRowCountEnumerableBatchNestedLoopJoin() {
final RelBuilder builder = RelBuilder.create(RelBuilderTest.config().build());
final RelNode relNode1 = builder
.scan("EMP")
.project(builder.field("DEPTNO"))
.scan("DEPT")
.project(builder.field("DEPTNO"))
.join(
JoinRelType.INNER,
builder.equals(
builder.field(2, 0, 0),
builder.field(2, 1, 0)))
.build();
final List<JoinRelType> supportedBatchNestedLoopJoinTypes =
Arrays.asList(JoinRelType.INNER, JoinRelType.LEFT, JoinRelType.SEMI, JoinRelType.ANTI);

for (JoinRelType joinRelType : supportedBatchNestedLoopJoinTypes) {
final RelBuilder builder = RelBuilder.create(RelBuilderTest.config().build());
final RelNode relNode1 = builder
.scan("EMP")
.project(builder.field("DEPTNO"))
.scan("DEPT")
.project(builder.field("DEPTNO"))
.join(
joinRelType,
builder.equals(
builder.field(2, 0, 0),
builder.field(2, 1, 0)))
.build();

final RelMetadataQuery mq = relNode1.getCluster().getMetadataQuery();
assertThat(relNode1, instanceOf(LogicalJoin.class));
final Double rowCount1 = mq.getRowCount(relNode1);
final RelMetadataQuery mq = relNode1.getCluster().getMetadataQuery();
assertThat(relNode1, instanceOf(LogicalJoin.class));
final Double rowCount1 = mq.getRowCount(relNode1);

// Program to convert LogicalJoin into EnumerableBatchNestedLoopJoin
final HepProgram program = new HepProgramBuilder()
.addRuleInstance(EnumerableRules.ENUMERABLE_BATCH_NESTED_LOOP_JOIN_RULE)
.build();
final HepPlanner hepPlanner = new HepPlanner(program);
hepPlanner.setRoot(relNode1);
final RelNode relNode2 = hepPlanner.findBestExp();
assertThat(relNode2, instanceOf(EnumerableBatchNestedLoopJoin.class));
final Double rowCount2 = mq.getRowCount(relNode2);
assertThat(rowCount2, equalTo(rowCount1));
// Program to convert LogicalJoin into EnumerableBatchNestedLoopJoin
final HepProgram program = new HepProgramBuilder()
.addRuleInstance(EnumerableRules.ENUMERABLE_BATCH_NESTED_LOOP_JOIN_RULE)
.build();
final HepPlanner hepPlanner = new HepPlanner(program);
hepPlanner.setRoot(relNode1);
final RelNode relNode2 = hepPlanner.findBestExp();
assertThat(relNode2, instanceOf(EnumerableBatchNestedLoopJoin.class));
final Double rowCount2 = mq.getRowCount(relNode2);
assertThat(rowCount2, equalTo(rowCount1));
}
}

// ----------------------------------------------------------------------
Expand Down

0 comments on commit ea2b758

Please sign in to comment.