Class PlannerTest


  • public class PlannerTest
    extends java.lang.Object
    Unit tests for Planner.
    • Constructor Detail

      • PlannerTest

        public PlannerTest()
    • 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 to Planner.rel(org.apache.calcite.sql.SqlNode) a SqlNode 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 testing RelMetadataQuery.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
      • 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 with GROUP BY (). This form of Aggregate can convert an empty relation to a single-row relation, so it is not valid to pull up the predicate false.
        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. The false predicate effectively means that the relation is empty, because no row can satisfy false.
        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 calls Planner.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 calls Planner.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 calls Planner.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 to Planner.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
      • 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