Class RelMetadataTest


  • public class RelMetadataTest
    extends SqlToRelTestBase
    Unit test for DefaultRelMetadataProvider. See SqlToRelTestBase class comments for details on the schema used. Note that no optimizer rules are fired on the translation of the SQL into relational algebra (e.g. join conditions in the WHERE clause will look like filters), so it's necessary to phrase the SQL carefully.
    • Field Detail

      • DEFAULT_EQUAL_SELECTIVITY

        private static final double DEFAULT_EQUAL_SELECTIVITY
        See Also:
        Constant Field Values
      • DEFAULT_EQUAL_SELECTIVITY_SQUARED

        private static final double DEFAULT_EQUAL_SELECTIVITY_SQUARED
        See Also:
        Constant Field Values
      • DEFAULT_COMP_SELECTIVITY

        private static final double DEFAULT_COMP_SELECTIVITY
        See Also:
        Constant Field Values
      • DEFAULT_NOTNULL_SELECTIVITY

        private static final double DEFAULT_NOTNULL_SELECTIVITY
        See Also:
        Constant Field Values
      • EMP_QNAME

        private static final java.util.List<java.lang.String> EMP_QNAME
      • LOCK

        private static final java.util.concurrent.locks.ReentrantLock LOCK
        Ensures that tests that use a lot of memory do not run at the same time.
      • NONDETERMINISTIC_OP

        private static final org.apache.calcite.sql.SqlOperator NONDETERMINISTIC_OP
    • Constructor Detail

      • RelMetadataTest

        public RelMetadataTest()
    • Method Detail

      • convertSql

        private org.apache.calcite.rel.RelNode convertSql​(java.lang.String sql)
      • convertSql

        private org.apache.calcite.rel.RelNode convertSql​(java.lang.String sql,
                                                          boolean typeCoercion)
      • checkPercentageOriginalRows

        private void checkPercentageOriginalRows​(java.lang.String sql,
                                                 double expected)
      • checkPercentageOriginalRows

        private void checkPercentageOriginalRows​(java.lang.String sql,
                                                 double expected,
                                                 double epsilon)
      • testPercentageOriginalRowsTableOnly

        public void testPercentageOriginalRowsTableOnly()
      • testPercentageOriginalRowsAgg

        public void testPercentageOriginalRowsAgg()
      • testPercentageOriginalRowsOneFilter

        public void testPercentageOriginalRowsOneFilter()
      • testPercentageOriginalRowsTwoFilters

        public void testPercentageOriginalRowsTwoFilters()
      • testPercentageOriginalRowsRedundantFilter

        public void testPercentageOriginalRowsRedundantFilter()
      • testPercentageOriginalRowsJoin

        public void testPercentageOriginalRowsJoin()
      • testPercentageOriginalRowsJoinTwoFilters

        public void testPercentageOriginalRowsJoinTwoFilters()
      • testPercentageOriginalRowsUnionNoFilter

        public void testPercentageOriginalRowsUnionNoFilter()
      • testPercentageOriginalRowsUnionLittleFilter

        public void testPercentageOriginalRowsUnionLittleFilter()
      • testPercentageOriginalRowsUnionBigFilter

        public void testPercentageOriginalRowsUnionBigFilter()
      • checkColumnOrigin

        private java.util.Set<org.apache.calcite.rel.metadata.RelColumnOrigin> checkColumnOrigin​(java.lang.String sql)
      • checkNoColumnOrigin

        private void checkNoColumnOrigin​(java.lang.String sql)
      • checkColumnOrigin

        public static void checkColumnOrigin​(org.apache.calcite.rel.metadata.RelColumnOrigin rco,
                                             java.lang.String expectedTableName,
                                             java.lang.String expectedColumnName,
                                             boolean expectedDerived)
      • checkSingleColumnOrigin

        private void checkSingleColumnOrigin​(java.lang.String sql,
                                             java.lang.String expectedTableName,
                                             java.lang.String expectedColumnName,
                                             boolean expectedDerived)
      • checkTwoColumnOrigin

        private void checkTwoColumnOrigin​(java.lang.String sql,
                                          java.lang.String expectedTableName1,
                                          java.lang.String expectedColumnName1,
                                          java.lang.String expectedTableName2,
                                          java.lang.String expectedColumnName2,
                                          boolean expectedDerived)
      • testColumnOriginsTableOnly

        public void testColumnOriginsTableOnly()
      • testColumnOriginsExpression

        public void testColumnOriginsExpression()
      • testColumnOriginsDyadicExpression

        public void testColumnOriginsDyadicExpression()
      • testColumnOriginsConstant

        public void testColumnOriginsConstant()
      • testColumnOriginsFilter

        public void testColumnOriginsFilter()
      • testColumnOriginsJoinLeft

        public void testColumnOriginsJoinLeft()
      • testColumnOriginsJoinRight

        public void testColumnOriginsJoinRight()
      • testColumnOriginsJoinOuter

        public void testColumnOriginsJoinOuter()
      • testColumnOriginsJoinFullOuter

        public void testColumnOriginsJoinFullOuter()
      • testColumnOriginsAggKey

        public void testColumnOriginsAggKey()
      • testColumnOriginsAggReduced

        public void testColumnOriginsAggReduced()
      • testColumnOriginsAggCountNullable

        public void testColumnOriginsAggCountNullable()
      • testColumnOriginsAggCountStar

        public void testColumnOriginsAggCountStar()
      • testColumnOriginsValues

        public void testColumnOriginsValues()
      • testColumnOriginsUnion

        public void testColumnOriginsUnion()
      • testColumnOriginsSelfUnion

        public void testColumnOriginsSelfUnion()
      • checkRowCount

        private void checkRowCount​(java.lang.String sql,
                                   double expected,
                                   double expectedMin,
                                   double expectedMax)
      • testRowCountEmp

        public void testRowCountEmp()
      • testRowCountDept

        public void testRowCountDept()
      • testRowCountValues

        public void testRowCountValues()
      • testRowCountCartesian

        public void testRowCountCartesian()
      • testRowCountJoin

        public void testRowCountJoin()
      • testRowCountJoinFinite

        public void testRowCountJoinFinite()
      • testRowCountJoinEmptyFinite

        public void testRowCountJoinEmptyFinite()
      • testRowCountLeftJoinEmptyFinite

        public void testRowCountLeftJoinEmptyFinite()
      • testRowCountRightJoinEmptyFinite

        public void testRowCountRightJoinEmptyFinite()
      • testRowCountJoinFiniteEmpty

        public void testRowCountJoinFiniteEmpty()
      • testRowCountJoinEmptyEmpty

        public void testRowCountJoinEmptyEmpty()
      • testRowCountUnion

        public void testRowCountUnion()
      • testRowCountUnionOnFinite

        public void testRowCountUnionOnFinite()
      • testRowCountIntersectOnFinite

        public void testRowCountIntersectOnFinite()
      • testRowCountMinusOnFinite

        public void testRowCountMinusOnFinite()
      • testRowCountFilter

        public void testRowCountFilter()
      • testRowCountFilterOnFinite

        public void testRowCountFilterOnFinite()
      • testRowCountFilterFalse

        public void testRowCountFilterFalse()
      • testRowCountSort

        public void testRowCountSort()
      • testRowCountSortHighLimit

        public void testRowCountSortHighLimit()
      • testRowCountSortHighOffset

        public void testRowCountSortHighOffset()
      • testRowCountSortHighOffsetLimit

        public void testRowCountSortHighOffsetLimit()
      • testRowCountSortLimit

        public void testRowCountSortLimit()
      • testRowCountSortLimit0

        public void testRowCountSortLimit0()
      • testRowCountSortLimitOffset

        public void testRowCountSortLimitOffset()
      • testRowCountSortLimitOffsetOnFinite

        public void testRowCountSortLimitOffsetOnFinite()
      • testRowCountAggregate

        public void testRowCountAggregate()
      • testRowCountAggregateGroupingSets

        public void testRowCountAggregateGroupingSets()
      • testRowCountAggregateGroupingSetsOneEmpty

        public void testRowCountAggregateGroupingSetsOneEmpty()
      • testRowCountAggregateEmptyKey

        public void testRowCountAggregateEmptyKey()
      • testRowCountAggregateConstantKey

        public void testRowCountAggregateConstantKey()
      • testRowCountAggregateConstantKeys

        public void testRowCountAggregateConstantKeys()
      • testRowCountFilterAggregateEmptyKey

        public void testRowCountFilterAggregateEmptyKey()
      • testRowCountAggregateEmptyKeyOnEmptyTable

        public void testRowCountAggregateEmptyKeyOnEmptyTable()
      • checkFilterSelectivity

        private void checkFilterSelectivity​(java.lang.String sql,
                                            double expected)
      • testSelectivityIsNotNullFilter

        public void testSelectivityIsNotNullFilter()
      • testSelectivityIsNotNullFilterOnNotNullColumn

        public void testSelectivityIsNotNullFilterOnNotNullColumn()
      • testSelectivityComparisonFilter

        public void testSelectivityComparisonFilter()
      • testSelectivityAndFilter

        public void testSelectivityAndFilter()
      • testSelectivityOrFilter

        public void testSelectivityOrFilter()
      • testSelectivityJoin

        public void testSelectivityJoin()
      • checkRelSelectivity

        private void checkRelSelectivity​(org.apache.calcite.rel.RelNode rel,
                                         double expected)
      • testSelectivityRedundantFilter

        public void testSelectivityRedundantFilter()
      • testSelectivitySort

        public void testSelectivitySort()
      • testSelectivityUnion

        public void testSelectivityUnion()
      • testSelectivityAgg

        public void testSelectivityAgg()
      • testSelectivityAggCached

        public void testSelectivityAggCached()
        Checks that we can cache a metadata request that includes a null argument.
      • testDistinctRowCountTable

        public void testDistinctRowCountTable()
      • testDistinctRowCountTableEmptyKey

        public void testDistinctRowCountTableEmptyKey()
      • assertUniqueConsistent

        private void assertUniqueConsistent​(org.apache.calcite.rel.RelNode rel)
        Asserts that RelMetadataQuery.getUniqueKeys(RelNode) and RelMetadataQuery.areColumnsUnique(RelNode, ImmutableBitSet) return consistent results.
      • isUnique

        private boolean isUnique​(java.util.Set<org.apache.calcite.util.ImmutableBitSet> uniqueKeys,
                                 org.apache.calcite.util.ImmutableBitSet key)
        Returns whether keys is unique, that is, whether it or a superset is in keySets.
      • testCorrelateUniqueKeys

        public void testCorrelateUniqueKeys()
      • testGroupByEmptyUniqueKeys

        public void testGroupByEmptyUniqueKeys()
      • testGroupByEmptyHavingUniqueKeys

        public void testGroupByEmptyHavingUniqueKeys()
      • testFullOuterJoinUniqueness1

        public void testFullOuterJoinUniqueness1()
      • testGroupBy

        public void testGroupBy()
      • testUnion

        public void testUnion()
      • testBrokenCustomProvider

        public void testBrokenCustomProvider()
      • colType

        public java.lang.String colType​(org.apache.calcite.rel.metadata.RelMetadataQuery mq,
                                        org.apache.calcite.rel.RelNode rel,
                                        int column)
      • testCustomProvider

        public void testCustomProvider()
      • testCollation

        public void testCollation()
        Unit test for RelMdCollation.project(org.apache.calcite.rel.metadata.RelMetadataQuery, org.apache.calcite.rel.RelNode, java.util.List<? extends org.apache.calcite.rex.RexNode>) and other helper functions for deducing collations.
      • checkCollation

        private void checkCollation​(org.apache.calcite.plan.RelOptCluster cluster,
                                    org.apache.calcite.plan.RelOptTable empTable,
                                    org.apache.calcite.plan.RelOptTable deptTable)
      • testColumnUniquenessForValues

        public void testColumnUniquenessForValues()
        Unit test for RelMdColumnUniqueness.areColumnsUnique(org.apache.calcite.rel.core.TableScan, org.apache.calcite.rel.metadata.RelMetadataQuery, org.apache.calcite.util.ImmutableBitSet, boolean) applied to Values.
      • addRow

        private void addRow​(com.google.common.collect.ImmutableList.Builder<com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexLiteral>> builder,
                            org.apache.calcite.rex.RexBuilder rexBuilder,
                            java.lang.Object... values)
      • testAverageRowSize

        public void testAverageRowSize()
        Unit test for RelMetadataQuery.getAverageColumnSizes(org.apache.calcite.rel.RelNode), RelMetadataQuery.getAverageRowSize(org.apache.calcite.rel.RelNode).
      • checkAverageRowSize

        private void checkAverageRowSize​(org.apache.calcite.plan.RelOptCluster cluster,
                                         org.apache.calcite.plan.RelOptTable empTable,
                                         org.apache.calcite.plan.RelOptTable deptTable)
      • testPredicates

        public void testPredicates()
        Unit test for RelMdPredicates.getPredicates(Join, RelMetadataQuery).
      • checkPredicates

        private void checkPredicates​(org.apache.calcite.plan.RelOptCluster cluster,
                                     org.apache.calcite.plan.RelOptTable empTable,
                                     org.apache.calcite.plan.RelOptTable deptTable)
      • testPullUpPredicatesFromAggregation

        public void testPullUpPredicatesFromAggregation()
        Unit test for RelMdPredicates.getPredicates(Aggregate, RelMetadataQuery).
      • testPullUpPredicatesOnConstant

        public void testPullUpPredicatesOnConstant()
      • testPullUpPredicatesOnNullableConstant

        public void testPullUpPredicatesOnNullableConstant()
      • testDistributionSimple

        public void testDistributionSimple()
      • testDistributionHash

        public void testDistributionHash()
      • testDistributionHashEmpty

        public void testDistributionHashEmpty()
      • testDistributionSingleton

        public void testDistributionSingleton()
      • testLinear

        public void testLinear()
        Unit test for RelMdUtil.linear(int, int, int, double, double).
      • testExpressionLineageStar

        public void testExpressionLineageStar()
      • testExpressionLineageTwoColumns

        public void testExpressionLineageTwoColumns()
      • testExpressionLineageTwoColumnsSwapped

        public void testExpressionLineageTwoColumnsSwapped()
      • testExpressionLineageCombineTwoColumns

        public void testExpressionLineageCombineTwoColumns()
      • testExpressionLineageInnerJoinLeft

        public void testExpressionLineageInnerJoinLeft()
      • testExpressionLineageInnerJoinRight

        public void testExpressionLineageInnerJoinRight()
      • testExpressionLineageLeftJoinLeft

        public void testExpressionLineageLeftJoinLeft()
      • testExpressionLineageRightJoinRight

        public void testExpressionLineageRightJoinRight()
      • testExpressionLineageSelfJoin

        public void testExpressionLineageSelfJoin()
      • testExpressionLineageOuterJoin

        public void testExpressionLineageOuterJoin()
      • testExpressionLineageFilter

        public void testExpressionLineageFilter()
      • testExpressionLineageAggregateGroupColumn

        public void testExpressionLineageAggregateGroupColumn()
      • testExpressionLineageAggregateAggColumn

        public void testExpressionLineageAggregateAggColumn()
      • testExpressionLineageUnion

        public void testExpressionLineageUnion()
      • testExpressionLineageMultiUnion

        public void testExpressionLineageMultiUnion()
      • testExpressionLineageValues

        public void testExpressionLineageValues()
      • testAllPredicates

        public void testAllPredicates()
      • checkAllPredicates

        private void checkAllPredicates​(org.apache.calcite.plan.RelOptCluster cluster,
                                        org.apache.calcite.plan.RelOptTable empTable,
                                        org.apache.calcite.plan.RelOptTable deptTable)
      • testAllPredicatesAggregate1

        public void testAllPredicatesAggregate1()
      • testAllPredicatesAggregate2

        public void testAllPredicatesAggregate2()
      • testAllPredicatesAggregate3

        public void testAllPredicatesAggregate3()
      • testAllPredicatesAndTablesJoin

        public void testAllPredicatesAndTablesJoin()
      • testAllPredicatesAndTableUnion

        public void testAllPredicatesAndTableUnion()
      • testAllPredicatesCrossJoinMultiTable

        public void testAllPredicatesCrossJoinMultiTable()
      • testTableReferencesJoinUnknownNode

        public void testTableReferencesJoinUnknownNode()
      • testAllPredicatesUnionMultiTable

        public void testAllPredicatesUnionMultiTable()
      • testTableReferencesUnionUnknownNode

        public void testTableReferencesUnionUnknownNode()
      • checkNodeTypeCount

        private void checkNodeTypeCount​(java.lang.String sql,
                                        java.util.Map<java.lang.Class<? extends org.apache.calcite.rel.RelNode>,​java.lang.Integer> expected)
      • testNodeTypeCountEmp

        public void testNodeTypeCountEmp()
      • testNodeTypeCountDept

        public void testNodeTypeCountDept()
      • testNodeTypeCountValues

        public void testNodeTypeCountValues()
      • testNodeTypeCountCartesian

        public void testNodeTypeCountCartesian()
      • testNodeTypeCountJoin

        public void testNodeTypeCountJoin()
      • testNodeTypeCountJoinFinite

        public void testNodeTypeCountJoinFinite()
      • testNodeTypeCountJoinEmptyFinite

        public void testNodeTypeCountJoinEmptyFinite()
      • testNodeTypeCountLeftJoinEmptyFinite

        public void testNodeTypeCountLeftJoinEmptyFinite()
      • testNodeTypeCountRightJoinEmptyFinite

        public void testNodeTypeCountRightJoinEmptyFinite()
      • testNodeTypeCountJoinFiniteEmpty

        public void testNodeTypeCountJoinFiniteEmpty()
      • testNodeTypeCountJoinEmptyEmpty

        public void testNodeTypeCountJoinEmptyEmpty()
      • testNodeTypeCountUnion

        public void testNodeTypeCountUnion()
      • testNodeTypeCountUnionOnFinite

        public void testNodeTypeCountUnionOnFinite()
      • testNodeTypeCountMinusOnFinite

        public void testNodeTypeCountMinusOnFinite()
      • testNodeTypeCountFilter

        public void testNodeTypeCountFilter()
      • testNodeTypeCountSort

        public void testNodeTypeCountSort()
      • testNodeTypeCountSortLimit

        public void testNodeTypeCountSortLimit()
      • testNodeTypeCountSortLimitOffset

        public void testNodeTypeCountSortLimitOffset()
      • testNodeTypeCountSortLimitOffsetOnFinite

        public void testNodeTypeCountSortLimitOffsetOnFinite()
      • testNodeTypeCountAggregate

        public void testNodeTypeCountAggregate()
      • testNodeTypeCountAggregateGroupingSets

        public void testNodeTypeCountAggregateGroupingSets()
      • testNodeTypeCountAggregateEmptyKeyOnEmptyTable

        public void testNodeTypeCountAggregateEmptyKeyOnEmptyTable()
      • testNodeTypeCountFilterAggregateEmptyKey

        public void testNodeTypeCountFilterAggregateEmptyKey()
      • testEmptyAggregateTableOrigin

        public void testEmptyAggregateTableOrigin()
        Tests calling RelMetadataQuery.getTableOrigin(org.apache.calcite.rel.RelNode) for an aggregate with no columns. Previously threw.
      • testGetPredicatesForJoin

        public void testGetPredicatesForJoin()
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testGetPredicatesForFilter

        public void testGetPredicatesForFilter()
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • sortsAs

        static <T> org.hamcrest.Matcher<java.lang.Iterable<? extends T>> sortsAs​(java.lang.String value)
        Matcher that succeeds for any collection that, when converted to strings and sorted on those strings, matches the given reference string.

        Use it as an alternative to CoreMatchers.is(T) if items in your list might occur in any order.

        For example:

        List<Integer> ints = Arrays.asList(2, 500, 12);
         assertThat(ints, sortsAs("[12, 2, 500]");