From ea2b758aff14ce7c8ea213d245b455a931272bd0 Mon Sep 17 00:00:00 2001 From: rubenada Date: Fri, 2 Feb 2024 09:34:00 +0000 Subject: [PATCH] Improve test --- .../apache/calcite/test/RelMetadataTest.java | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java index 3715889c701..864a430d99f 100644 --- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java +++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java @@ -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 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)); + } } // ----------------------------------------------------------------------