Class RelBuilderTest


  • public class RelBuilderTest
    extends java.lang.Object
    Unit test for RelBuilder.

    Tasks:

    1. Add RelBuilder.scan(List<String>)
    2. Add RelBuilder.scan(Table)
    3. Test that RelBuilder.filter(org.apache.calcite.rex.RexNode...) does not create a filter if the predicates optimize to true
    4. Test that RelBuilder.filter(org.apache.calcite.rex.RexNode...) DOES create a filter if the predicates optimize to false. (Creating an empty Values seems too devious.)
    5. Test that RelBuilder.scan(java.lang.Iterable<java.lang.String>) throws good error if table not found
    6. Test that RelBuilder.scan(java.lang.Iterable<java.lang.String>) obeys case-sensitivity
    7. Test that RelBuilder.join(JoinRelType, String...) obeys case-sensitivity
    8. Test RelBuilder with alternative factories
    9. Test that RelBuilder.field(String) obeys case-sensitivity
    10. Test case-insensitive unique field names
    11. Test that an alias created using RelBuilder.alias(RexNode, String) is removed if not a top-level project
    12. RelBuilder.aggregate(org.apache.calcite.tools.RelBuilder.GroupKey, org.apache.calcite.tools.RelBuilder.AggCall...) with grouping sets
    13. Add call to create TableFunctionScan
    14. Add call to create Window
    15. Add call to create TableModify
    16. Add call to create Exchange
    17. Add call to create Correlate
    18. Add call to create AggregateCall with filter
    • Constructor Detail

      • RelBuilderTest

        public RelBuilderTest()
    • Method Detail

      • config

        public static org.apache.calcite.tools.Frameworks.ConfigBuilder config()
        Creates a config based on the "scott" schema.
      • expandingConfig

        static org.apache.calcite.tools.Frameworks.ConfigBuilder expandingConfig​(java.sql.Connection connection)
                                                                          throws java.sql.SQLException
        Creates a config builder that will contain a view, "MYVIEW", and also the SCOTT JDBC schema, whose tables implement TranslatableTable.
        Throws:
        java.sql.SQLException
      • createBuilder

        @Nonnull
        static org.apache.calcite.tools.RelBuilder createBuilder​(java.util.function.Function<org.apache.calcite.tools.RelBuilder.ConfigBuilder,​org.apache.calcite.tools.RelBuilder.ConfigBuilder> transform)
      • testScan

        public void testScan()
      • testScanQualifiedTable

        public void testScanQualifiedTable()
      • testScanInvalidTable

        public void testScanInvalidTable()
      • testScanInvalidSchema

        public void testScanInvalidSchema()
      • testScanInvalidQualifiedTable

        public void testScanInvalidQualifiedTable()
      • testScanValidTableWrongCase

        public void testScanValidTableWrongCase()
      • testScanFilterTrue

        public void testScanFilterTrue()
      • testScanFilterTriviallyFalse

        public void testScanFilterTriviallyFalse()
      • testScanFilterEquals

        public void testScanFilterEquals()
      • testSnapshotTemporalTable

        public void testSnapshotTemporalTable()
      • testTableFunctionScan

        public void testTableFunctionScan()
      • testTableFunctionScanZeroInputs

        public void testTableFunctionScanZeroInputs()
      • testJoinTemporalTable

        public void testJoinTemporalTable()
      • testSimplify

        public void testSimplify()
        Tests that RelBuilder.project(org.apache.calcite.rex.RexNode...) simplifies expressions if and only if RelBuilder.Config.simplify.
      • checkSimplify

        private void checkSimplify​(java.util.function.Function<org.apache.calcite.tools.RelBuilder.ConfigBuilder,​org.apache.calcite.tools.RelBuilder.ConfigBuilder> transform,
                                   org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> matcher)
      • testScanFilterOr

        public void testScanFilterOr()
      • testScanFilterOr2

        public void testScanFilterOr2()
      • testScanFilterAndFalse

        public void testScanFilterAndFalse()
      • testScanFilterAndTrue

        public void testScanFilterAndTrue()
      • testBadFieldName

        public void testBadFieldName()
      • testBadFieldOrdinal

        public void testBadFieldOrdinal()
      • testBadType

        public void testBadType()
      • testProject

        public void testProject()
      • testProject2

        public void testProject2()
        Tests each method that creates a scalar expression.
      • testProjectIdentity

        public void testProjectIdentity()
      • testProjectIdentityWithFieldsRenameFilter

        public void testProjectIdentityWithFieldsRenameFilter()
        Variation on testProjectIdentityWithFieldsRename(): don't use a table alias, and make sure the field names propagate through a filter.
      • testProjectLeadingEdge

        public void testProjectLeadingEdge()
      • testProjectWithAliasFromScan

        public void testProjectWithAliasFromScan()
      • project1

        private void project1​(int value,
                              org.apache.calcite.sql.type.SqlTypeName sqlTypeName,
                              java.lang.String message,
                              java.lang.String expected)
      • testProject1asInt

        public void testProject1asInt()
      • testProject1asBigInt

        public void testProject1asBigInt()
      • testRename

        public void testRename()
      • testRenameValues

        public void testRenameValues()
      • testPermute

        public void testPermute()
      • testConvert

        public void testConvert()
      • testConvertRename

        public void testConvertRename()
      • testAggregate

        public void testAggregate()
      • testAggregate2

        public void testAggregate2()
      • testAggregate4

        public void testAggregate4()
        As testAggregate3() but with Filter.
      • testAggregateEliminatesDuplicateCalls

        public void testAggregateEliminatesDuplicateCalls()
        Tests that RelBuilder.aggregate(org.apache.calcite.tools.RelBuilder.GroupKey, org.apache.calcite.tools.RelBuilder.AggCall...) eliminates duplicate aggregate calls and creates a Project to compensate.
      • buildRelWithDuplicateAggregates

        private org.apache.calcite.rel.RelNode buildRelWithDuplicateAggregates​(org.apache.calcite.tools.RelBuilder builder,
                                                                               int... groupFieldOrdinals)
      • testAggregateEliminatesDuplicateDistinctCalls

        public void testAggregateEliminatesDuplicateDistinctCalls()
        Tests eliminating duplicate aggregate calls, when some of them are only seen to be duplicates when a spurious "DISTINCT" has been eliminated.

        Note that "M2" and "MD2" are based on the same field, because "MIN(DISTINCT $2)" is identical to "MIN($2)". The same is not true for "SUM".

      • testAggregateFilter

        public void testAggregateFilter()
      • testAggregateFilterFails

        public void testAggregateFilterFails()
      • testAggregateFilterNullable

        public void testAggregateFilterNullable()
      • testAggregateProjectWithExpression

        public void testAggregateProjectWithExpression()
      • testAggregateGroupingKeyOutOfRangeFails

        public void testAggregateGroupingKeyOutOfRangeFails()
      • testAggregateGroupingSetNotSubsetFails

        public void testAggregateGroupingSetNotSubsetFails()
      • testAggregateGroupingSetDuplicateIgnored

        public void testAggregateGroupingSetDuplicateIgnored()
      • testAggregateGrouping

        public void testAggregateGrouping()
      • testAggregateGroupingWithDistinctFails

        public void testAggregateGroupingWithDistinctFails()
      • testAggregateGroupingWithFilterFails

        public void testAggregateGroupingWithFilterFails()
      • testDistinct

        public void testDistinct()
      • testDistinctAlready

        public void testDistinctAlready()
      • testDistinctEmpty

        public void testDistinctEmpty()
      • testUnion

        public void testUnion()
      • testUnion3

        public void testUnion3()
      • testUnion1

        public void testUnion1()
      • testRepeatUnion1

        public void testRepeatUnion1()
      • testRepeatUnion2

        public void testRepeatUnion2()
      • testIntersect

        public void testIntersect()
      • testIntersect3

        public void testIntersect3()
      • testExcept

        public void testExcept()
      • testJoin

        public void testJoin()
      • testJoinUsing

        public void testJoinUsing()
        Same as testJoin() using USING.
      • testJoin2

        public void testJoin2()
      • testJoinCartesian

        public void testJoinCartesian()
      • testCorrelationFails

        public void testCorrelationFails()
      • testCorrelationWithCondition

        public void testCorrelationWithCondition()
      • testAntiJoin

        public void testAntiJoin()
      • testAlias

        public void testAlias()
      • testAlias2

        public void testAlias2()
      • testAliasSort

        public void testAliasSort()
      • testAliasLimit

        public void testAliasLimit()
      • testAliasProjectProject

        public void testAliasProjectProject()
        Tests that table aliases are propagated even when there is a project on top of a project. (Aliases tend to get lost when projects are merged).
      • testAliasFilter

        public void testAliasFilter()
        Tests that table aliases are propagated and are available to a filter, even when there is a project on top of a project. (Aliases tend to get lost when projects are merged).
      • testScanAlias

        public void testScanAlias()
        Tests that the RelBuilder.alias(RexNode, String) function is idempotent.
      • testAliasSuggester

        public void testAliasSuggester()
        Tests that project field name aliases are suggested incrementally.
      • testAliasAggregate

        public void testAliasAggregate()
      • testProjectJoin

        public void testProjectJoin()
        Tests that a projection retains field names after a join.
      • testProjectProject

        public void testProjectProject()
        Tests that a projection after a projection.
      • testMultiLevelAlias

        public void testMultiLevelAlias()
      • testUnionAlias

        public void testUnionAlias()
      • testEmpty

        public void testEmpty()
      • testValues

        public void testValues()
      • testValuesNullable

        public void testValuesNullable()
        Tests creating Values with some field names and some values null.
      • testValuesBadNullFieldNames

        public void testValuesBadNullFieldNames()
      • testValuesBadNoFields

        public void testValuesBadNoFields()
      • testValuesBadNoValues

        public void testValuesBadNoValues()
      • testValuesBadOddMultiple

        public void testValuesBadOddMultiple()
      • testValuesBadAllNull

        public void testValuesBadAllNull()
      • testValuesAllNull

        public void testValuesAllNull()
      • testSort

        public void testSort()
      • testSortDuplicate

        public void testSortDuplicate()
      • testSortByExpression

        public void testSortByExpression()
      • testLimit

        public void testLimit()
      • testSortLimit

        public void testSortLimit()
      • testSortLimit0

        public void testSortLimit0()
      • testSortThenLimit

        public void testSortThenLimit()
        Tests that a sort on a field followed by a limit gives the same effect as calling sortLimit.

        In general a relational operator cannot rely on the order of its input, but it is reasonable to merge sort and limit if they were created by consecutive builder operations. And clients such as Piglet rely on it.

      • testSortExpThenLimit

        public void testSortExpThenLimit()
        Tests that a sort on an expression followed by a limit gives the same effect as calling sortLimit.
      • testRunValues

        public void testRunValues()
                           throws java.lang.Exception
        Tests RelRunner for a VALUES query.
        Throws:
        java.lang.Exception
      • testRun

        public void testRun()
                     throws java.lang.Exception
        Tests RelRunner for a table scan + filter query.
        Throws:
        java.lang.Exception
      • testMatchRecognize

        public void testMatchRecognize()
      • testFilterCastAny

        public void testFilterCastAny()
      • testFilterCastNull

        public void testFilterCastNull()
      • testFilterWithCorrelationVariables

        public void testFilterWithCorrelationVariables()
        Tests filter builder with correlation variables
      • testFilterEmpty

        public void testFilterEmpty()
      • testRelBuilderToString

        public void testRelBuilderToString()
      • testExpandViewInRelBuilder

        public void testExpandViewInRelBuilder()
                                        throws java.sql.SQLException
        Ensures that relational algebra (RelBuilder) works with SQL views.

        This test currently fails (thus ignored).

        Throws:
        java.sql.SQLException
      • testExpandViewShouldKeepAlias

        public void testExpandViewShouldKeepAlias()
                                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • testExpandTable

        public void testExpandTable()
                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • checkExpandTable

        private void checkExpandTable​(org.apache.calcite.tools.RelBuilder builder,
                                      org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> matcher)
      • testExchange

        public void testExchange()
      • testSortExchange

        public void testSortExchange()
      • testCorrelate

        public void testCorrelate()
      • testCorrelateWithComplexFields

        public void testCorrelateWithComplexFields()