Package org.apache.calcite.tools
Class PlannerTest
- java.lang.Object
-
- org.apache.calcite.tools.PlannerTest
-
public class PlannerTest extends java.lang.Object
Unit tests forPlanner
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
PlannerTest.MockJdbcProjectRule
Rule to convert aEnumerableProject
to anJdbcRules.JdbcProject
.private class
PlannerTest.MockJdbcTableRule
Rule to convert aEnumerableTableScan
to anPlannerTest.MockJdbcTableScan
.private class
PlannerTest.MockJdbcTableScan
Relational expression representing a "mock" scan of a table in a JDBC data source.static class
PlannerTest.MyCountAggFunction
User-defined aggregate function.
-
Constructor Summary
Constructors Constructor Description PlannerTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkBushy(java.lang.String sql, java.lang.String expected)
Checks that a query returns a particular plan, using a planner with MultiJoinOptimizeBushyRule enabled.private void
checkHeuristic(java.lang.String sql, java.lang.String expected)
private void
checkJoinNWay(int n)
private void
checkMetadataPredicates(java.lang.String sql, java.lang.String expectedPredicates)
Helper method for testingRelMetadataQuery.getPulledUpPredicates(org.apache.calcite.rel.RelNode)
metadata.private void
checkParseAndConvert(java.lang.String query, java.lang.String queryFromParseTree, java.lang.String expectedRelExpr)
java.lang.String
checkTpchQuery(java.lang.String tpchTestQuery)
private void
checkView(java.lang.String sql, org.hamcrest.Matcher<java.lang.String> matcher)
private org.apache.calcite.tools.Planner
getPlanner(java.util.List<org.apache.calcite.plan.RelTraitDef> traitDefs, org.apache.calcite.sql.parser.SqlParser.Config parserConfig, org.apache.calcite.tools.Program... programs)
private org.apache.calcite.tools.Planner
getPlanner(java.util.List<org.apache.calcite.plan.RelTraitDef> traitDefs, org.apache.calcite.tools.Program... programs)
private void
runDuplicateSortCheck(java.lang.String sql, java.lang.String plan)
void
testAlmostBushy()
Plans a 3-table join query on the FoodMart schema.void
testBushy()
Plans a 4-table join query on the FoodMart schema.void
testBushy5()
Plans a 5-table join query on the FoodMart schema.void
testBushyCrossJoin()
Tests the bushy join algorithm where one table does not join to anything.void
testBushyCrossJoin2()
Tests the bushy join algorithm against a query where not all tables have a join condition to the others.void
testConvertWithoutValidateFails()
Tests that planner throws an error if you pass toPlanner.rel(org.apache.calcite.sql.SqlNode)
aSqlNode
that has been parsed but not validated.void
testDuplicateSortPlan()
Unit test that parses, validates, converts and plans for query using two duplicate order by.void
testDuplicateSortPlanWithExpr()
Unit test that parses, validates, converts and plans for query using two duplicate order by.void
testDuplicateSortPlanWithOver()
Tests that outer order by is not removed since window function might reorder the rows in-betweenvoid
testDuplicateSortPlanWORemoveSortRule()
Unit test that parses, validates, converts and plans for query using two duplicate order by.void
testHeuristicLeftJoin()
void
testHeuristicPushInnerJoin()
It would probably be OK to transform(emps right join depts) join dependents
to(emps join dependents) right join depts
but we do not currently allow it.void
testHeuristicRightJoin()
Tests that a relation (dependents) that is on the null-generating side of an outer join cannot be pushed into an inner join (emps join depts).void
testHiveDialect()
Tests that Hive dialect does not generate "AS".void
testMergeProjectForceMode()
void
testMetadataAggregatePredicates()
Tests predicates that can be pulled-up from an Aggregate withGROUP BY ()
.void
testMetadataAggregatePredicates2()
Tests predicates that can be pulled-up from an Aggregate with a non-empty group key.void
testMetadataAggregatePredicates3()
void
testMetadataUnionPredicates()
Tests predicates that can be pulled-up from a UNION.void
testMetadataUnionPredicates2()
Test case for [CALCITE-443] getPredicates from a union is not correct.void
testMetadataUnionPredicates3()
void
testMetadataUnionPredicates4()
void
testMetadataUnionPredicates5()
void
testOldJoinStyleDeCorrelation()
Test to determine whether de-correlation correctly removes Correlator.void
testOrderByNonSelectColumn()
void
testParseAndConvert()
void
testParseAndConvertWithOrderByAndOffset()
Unit test that parses, validates and converts the query using order by and offset.void
testParseFails()
void
testParseIdentiferMaxLengthWithDefault()
void
testParseIdentiferMaxLengthWithIncreased()
void
testPlan()
Unit test that parses, validates, converts and plans.void
testPlanNWayJoin()
Unit test that plans a query with a large number of joins.void
testPlanTransformTwice()
Unit test that callsPlanner.transform(int, org.apache.calcite.plan.RelTraitSet, org.apache.calcite.rel.RelNode)
twice.void
testPlanTransformWithDiffRuleSetAndConvention()
Unit test that callsPlanner.transform(int, org.apache.calcite.plan.RelTraitSet, org.apache.calcite.rel.RelNode)
twice, with different rule sets, with different conventions.void
testPlanTransformWithRuleNameConflicts()
Unit test that callsPlanner.transform(int, org.apache.calcite.plan.RelTraitSet, org.apache.calcite.rel.RelNode)
twice with rule name conflictsvoid
testPlanWithExplicitTraitDefs()
Unit test that parses, validates, converts and plans.void
testSortPlan()
Unit test that parses, validates, converts and plans for query using order byvoid
testValidateFails()
void
testValidateUserDefinedAggregate()
void
testView()
void
testViewOnView()
private java.lang.String
toString(org.apache.calcite.rel.RelNode rel)
-
-
-
Method Detail
-
checkParseAndConvert
private void checkParseAndConvert(java.lang.String query, java.lang.String queryFromParseTree, java.lang.String expectedRelExpr) throws java.lang.Exception
- Throws:
java.lang.Exception
-
testParseAndConvert
public void testParseAndConvert() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testParseIdentiferMaxLengthWithDefault
public void testParseIdentiferMaxLengthWithDefault() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testParseIdentiferMaxLengthWithIncreased
public void testParseIdentiferMaxLengthWithIncreased() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testParseAndConvertWithOrderByAndOffset
public void testParseAndConvertWithOrderByAndOffset() throws java.lang.Exception
Unit test that parses, validates and converts the query using order by and offset.- Throws:
java.lang.Exception
-
toString
private java.lang.String toString(org.apache.calcite.rel.RelNode rel)
-
testParseFails
public void testParseFails() throws org.apache.calcite.sql.parser.SqlParseException
- Throws:
org.apache.calcite.sql.parser.SqlParseException
-
testValidateFails
public void testValidateFails() throws org.apache.calcite.sql.parser.SqlParseException
- Throws:
org.apache.calcite.sql.parser.SqlParseException
-
testValidateUserDefinedAggregate
public void testValidateUserDefinedAggregate() throws java.lang.Exception
- Throws:
java.lang.Exception
-
getPlanner
private org.apache.calcite.tools.Planner getPlanner(java.util.List<org.apache.calcite.plan.RelTraitDef> traitDefs, org.apache.calcite.tools.Program... programs)
-
getPlanner
private org.apache.calcite.tools.Planner getPlanner(java.util.List<org.apache.calcite.plan.RelTraitDef> traitDefs, org.apache.calcite.sql.parser.SqlParser.Config parserConfig, org.apache.calcite.tools.Program... programs)
-
testConvertWithoutValidateFails
public void testConvertWithoutValidateFails() throws java.lang.Exception
Tests that planner throws an error if you pass toPlanner.rel(org.apache.calcite.sql.SqlNode)
aSqlNode
that has been parsed but not validated.- Throws:
java.lang.Exception
-
checkMetadataPredicates
private void checkMetadataPredicates(java.lang.String sql, java.lang.String expectedPredicates) throws java.lang.Exception
Helper method for testingRelMetadataQuery.getPulledUpPredicates(org.apache.calcite.rel.RelNode)
metadata.- Throws:
java.lang.Exception
-
testMetadataUnionPredicates
public void testMetadataUnionPredicates() throws java.lang.Exception
Tests predicates that can be pulled-up from a UNION.- Throws:
java.lang.Exception
-
testMetadataUnionPredicates2
public void testMetadataUnionPredicates2() throws java.lang.Exception
Test case for [CALCITE-443] getPredicates from a union is not correct.- Throws:
java.lang.Exception
-
testMetadataUnionPredicates3
public void testMetadataUnionPredicates3() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testMetadataUnionPredicates4
public void testMetadataUnionPredicates4() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testMetadataUnionPredicates5
public void testMetadataUnionPredicates5() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testMetadataAggregatePredicates
public void testMetadataAggregatePredicates() throws java.lang.Exception
Tests predicates that can be pulled-up from an Aggregate withGROUP BY ()
. This form of Aggregate can convert an empty relation to a single-row relation, so it is not valid to pull up the predicatefalse
.- Throws:
java.lang.Exception
-
testMetadataAggregatePredicates2
public void testMetadataAggregatePredicates2() throws java.lang.Exception
Tests predicates that can be pulled-up from an Aggregate with a non-empty group key. Thefalse
predicate effectively means that the relation is empty, because no row can satisfyfalse
.- Throws:
java.lang.Exception
-
testMetadataAggregatePredicates3
public void testMetadataAggregatePredicates3() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testPlan
public void testPlan() throws java.lang.Exception
Unit test that parses, validates, converts and plans.- Throws:
java.lang.Exception
-
testSortPlan
public void testSortPlan() throws java.lang.Exception
Unit test that parses, validates, converts and plans for query using order by- Throws:
java.lang.Exception
-
testDuplicateSortPlan
public void testDuplicateSortPlan() throws java.lang.Exception
Unit test that parses, validates, converts and plans for query using two duplicate order by. The duplicate order by should be removed by SortRemoveRule.- Throws:
java.lang.Exception
-
testDuplicateSortPlanWithExpr
public void testDuplicateSortPlanWithExpr() throws java.lang.Exception
Unit test that parses, validates, converts and plans for query using two duplicate order by. The duplicate order by should be removed by SortRemoveRule- Throws:
java.lang.Exception
-
testDuplicateSortPlanWithOver
public void testDuplicateSortPlanWithOver() throws java.lang.Exception
Tests that outer order by is not removed since window function might reorder the rows in-between- Throws:
java.lang.Exception
-
runDuplicateSortCheck
private void runDuplicateSortCheck(java.lang.String sql, java.lang.String plan) throws java.lang.Exception
- Throws:
java.lang.Exception
-
testDuplicateSortPlanWORemoveSortRule
public void testDuplicateSortPlanWORemoveSortRule() throws java.lang.Exception
Unit test that parses, validates, converts and plans for query using two duplicate order by.- Throws:
java.lang.Exception
-
testPlanWithExplicitTraitDefs
public void testPlanWithExplicitTraitDefs() throws java.lang.Exception
Unit test that parses, validates, converts and plans. Planner is provided with a list of RelTraitDefs to register.- Throws:
java.lang.Exception
-
testPlanTransformTwice
public void testPlanTransformTwice() throws java.lang.Exception
Unit test that callsPlanner.transform(int, org.apache.calcite.plan.RelTraitSet, org.apache.calcite.rel.RelNode)
twice.- Throws:
java.lang.Exception
-
testPlanTransformWithRuleNameConflicts
public void testPlanTransformWithRuleNameConflicts() throws java.lang.Exception
Unit test that callsPlanner.transform(int, org.apache.calcite.plan.RelTraitSet, org.apache.calcite.rel.RelNode)
twice with rule name conflicts- Throws:
java.lang.Exception
-
testHiveDialect
public void testHiveDialect() throws org.apache.calcite.sql.parser.SqlParseException
Tests that Hive dialect does not generate "AS".- Throws:
org.apache.calcite.sql.parser.SqlParseException
-
testPlanTransformWithDiffRuleSetAndConvention
public void testPlanTransformWithDiffRuleSetAndConvention() throws java.lang.Exception
Unit test that callsPlanner.transform(int, org.apache.calcite.plan.RelTraitSet, org.apache.calcite.rel.RelNode)
twice, with different rule sets, with different conventions.JdbcConvention
is different from the typical convention in that it is not a singleton. Switching to a different instance causes problems unless planner state is wiped clean between calls toPlanner.transform(int, org.apache.calcite.plan.RelTraitSet, org.apache.calcite.rel.RelNode)
.- Throws:
java.lang.Exception
-
testPlanNWayJoin
public void testPlanNWayJoin() throws java.lang.Exception
Unit test that plans a query with a large number of joins.- Throws:
java.lang.Exception
-
checkJoinNWay
private void checkJoinNWay(int n) throws java.lang.Exception
- Throws:
java.lang.Exception
-
testHeuristicLeftJoin
public void testHeuristicLeftJoin() throws java.lang.Exception
Test case for [CALCITE-435] LoptOptimizeJoinRule incorrectly re-orders outer joins.Checks the
LoptOptimizeJoinRule
on a query with a left outer join.Specifically, tests that a relation (dependents) in an inner join cannot be pushed into an outer join (emps left join depts).
- Throws:
java.lang.Exception
-
testHeuristicPushInnerJoin
public void testHeuristicPushInnerJoin() throws java.lang.Exception
It would probably be OK to transform(emps right join depts) join dependents
to(emps join dependents) right join depts
but we do not currently allow it.- Throws:
java.lang.Exception
-
testHeuristicRightJoin
public void testHeuristicRightJoin() throws java.lang.Exception
Tests that a relation (dependents) that is on the null-generating side of an outer join cannot be pushed into an inner join (emps join depts).- Throws:
java.lang.Exception
-
checkHeuristic
private void checkHeuristic(java.lang.String sql, java.lang.String expected) throws java.lang.Exception
- Throws:
java.lang.Exception
-
testAlmostBushy
public void testAlmostBushy() throws java.lang.Exception
Plans a 3-table join query on the FoodMart schema. The ideal plan is not bushy, but nevertheless exercises the bushy-join heuristic optimizer.- Throws:
java.lang.Exception
-
testBushy
public void testBushy() throws java.lang.Exception
Plans a 4-table join query on the FoodMart schema.The ideal plan is bushy: customer x (product_class x product x sales) which would be written (customer x ((product_class x product) x sales)) if you don't assume 'x' is left-associative.
- Throws:
java.lang.Exception
-
testBushy5
public void testBushy5() throws java.lang.Exception
Plans a 5-table join query on the FoodMart schema. The ideal plan is bushy: store x (customer x (product_class x product x sales)).- Throws:
java.lang.Exception
-
testBushyCrossJoin
public void testBushyCrossJoin() throws java.lang.Exception
Tests the bushy join algorithm where one table does not join to anything.- Throws:
java.lang.Exception
-
testBushyCrossJoin2
public void testBushyCrossJoin2() throws java.lang.Exception
Tests the bushy join algorithm against a query where not all tables have a join condition to the others.- Throws:
java.lang.Exception
-
checkBushy
private void checkBushy(java.lang.String sql, java.lang.String expected) throws java.lang.Exception
Checks that a query returns a particular plan, using a planner with MultiJoinOptimizeBushyRule enabled.- Throws:
java.lang.Exception
-
testOldJoinStyleDeCorrelation
public void testOldJoinStyleDeCorrelation() throws java.lang.Exception
Test to determine whether de-correlation correctly removes Correlator.- Throws:
java.lang.Exception
-
checkTpchQuery
public java.lang.String checkTpchQuery(java.lang.String tpchTestQuery) throws java.lang.Exception
- Throws:
java.lang.Exception
-
testOrderByNonSelectColumn
public void testOrderByNonSelectColumn() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testMergeProjectForceMode
public void testMergeProjectForceMode() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testView
public void testView() throws java.lang.Exception
- Throws:
java.lang.Exception
-
testViewOnView
public void testViewOnView() throws java.lang.Exception
- Throws:
java.lang.Exception
-
checkView
private void checkView(java.lang.String sql, org.hamcrest.Matcher<java.lang.String> matcher) throws org.apache.calcite.sql.parser.SqlParseException, org.apache.calcite.tools.ValidationException, org.apache.calcite.tools.RelConversionException
- Throws:
org.apache.calcite.sql.parser.SqlParseException
org.apache.calcite.tools.ValidationException
org.apache.calcite.tools.RelConversionException
-
-