Search in sources :

Example 31 with RelMetadataQuery

use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.

the class RelMetadataTest method testExpressionLineageOuterJoin.

@Test
void testExpressionLineageOuterJoin() {
    // lineage cannot be determined
    final RelNode rel = sql("select name as dname from emp left outer join dept" + " on emp.deptno = dept.deptno").toRel();
    final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
    final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
    final Set<RexNode> r = mq.getExpressionLineage(rel, ref);
    assertNull(r);
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.jupiter.api.Test)

Example 32 with RelMetadataQuery

use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.

the class RelMetadataFixture method assertThatNodeTypeCount.

/**
 * Checks the number of each sub-class of {@link RelNode},
 * calling {@link RelMetadataQuery#getNodeTypes(RelNode)}.
 */
public RelMetadataFixture assertThatNodeTypeCount(Matcher<Map<Class<? extends RelNode>, Integer>> matcher) {
    final RelNode rel = toRel();
    final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
    final Multimap<Class<? extends RelNode>, RelNode> result = mq.getNodeTypes(rel);
    assertThat(result, notNullValue());
    final Map<Class<? extends RelNode>, Integer> resultCount = new HashMap<>();
    for (Map.Entry<Class<? extends RelNode>, Collection<RelNode>> e : result.asMap().entrySet()) {
        resultCount.put(e.getKey(), e.getValue().size());
    }
    assertThat(resultCount, matcher);
    return this;
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) HashMap(java.util.HashMap) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 33 with RelMetadataQuery

use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.

the class RelMetadataFixture method assertThatAreColumnsUnique.

/**
 * Checks {@link RelMetadataQuery#areColumnsUnique(RelNode, ImmutableBitSet)},
 * deriving parameters via functions.
 */
public RelMetadataFixture assertThatAreColumnsUnique(Function<RelNode, ImmutableBitSet> columnsFn, UnaryOperator<RelNode> relFn, Matcher<Boolean> matcher) {
    RelNode rel = toRel();
    final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
    final ImmutableBitSet columns = columnsFn.apply(rel);
    final RelNode rel2 = relFn.apply(rel);
    final Boolean areColumnsUnique = mq.areColumnsUnique(rel2, columns);
    assertThat(areColumnsUnique, matcher);
    return this;
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet)

Example 34 with RelMetadataQuery

use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.

the class RelMetadataFixture method assertThatAreRowsUnique.

/**
 * Checks {@link RelMetadataQuery#areRowsUnique(RelNode)}.
 */
@SuppressWarnings({ "UnusedReturnValue" })
public RelMetadataFixture assertThatAreRowsUnique(Matcher<Boolean> matcher) {
    RelNode rel = toRel();
    final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
    final Boolean areRowsUnique = mq.areRowsUnique(rel);
    assertThat(areRowsUnique, matcher);
    return this;
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode)

Example 35 with RelMetadataQuery

use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.

the class RelMetadataFixture method checkColumnOrigin.

private RelMetadataFixture checkColumnOrigin(Consumer<Set<RelColumnOrigin>> action) {
    RelNode rel = toRel();
    final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
    final Set<RelColumnOrigin> columnOrigins = mq.getColumnOrigins(rel, 0);
    action.accept(columnOrigins);
    return this;
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) RelColumnOrigin(org.apache.calcite.rel.metadata.RelColumnOrigin)

Aggregations

RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)234 RelNode (org.apache.calcite.rel.RelNode)154 RexNode (org.apache.calcite.rex.RexNode)61 Test (org.junit.jupiter.api.Test)55 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)43 ArrayList (java.util.ArrayList)41 RelOptCluster (org.apache.calcite.plan.RelOptCluster)39 RexBuilder (org.apache.calcite.rex.RexBuilder)36 RelOptPredicateList (org.apache.calcite.plan.RelOptPredicateList)32 RelBuilder (org.apache.calcite.tools.RelBuilder)29 RelTraitSet (org.apache.calcite.plan.RelTraitSet)27 List (java.util.List)22 HashMap (java.util.HashMap)19 Aggregate (org.apache.calcite.rel.core.Aggregate)19 RexInputRef (org.apache.calcite.rex.RexInputRef)19 RexTableInputRef (org.apache.calcite.rex.RexTableInputRef)19 RelDataType (org.apache.calcite.rel.type.RelDataType)18 ImmutableList (com.google.common.collect.ImmutableList)17 AggregateCall (org.apache.calcite.rel.core.AggregateCall)17 Join (org.apache.calcite.rel.core.Join)16