Search in sources :

Example 56 with ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project calcite by apache.

the class RelMetadataTest method testDistinctRowCountTableEmptyKey.

@Test
public void testDistinctRowCountTableEmptyKey() {
    RelNode rel = convertSql("select * from emp where deptno = 10");
    // empty key
    ImmutableBitSet groupKey = ImmutableBitSet.of();
    final RelMetadataQuery mq = RelMetadataQuery.instance();
    Double result = mq.getDistinctRowCount(rel, groupKey, null);
    assertThat(result, is(1D));
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) Test(org.junit.Test)

Example 57 with ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project calcite by apache.

the class RelMetadataTest method assertUniqueConsistent.

/**
 * Asserts that {@link RelMetadataQuery#getUniqueKeys(RelNode)}
 * and {@link RelMetadataQuery#areColumnsUnique(RelNode, ImmutableBitSet)}
 * return consistent results.
 */
private void assertUniqueConsistent(RelNode rel) {
    final RelMetadataQuery mq = RelMetadataQuery.instance();
    final Set<ImmutableBitSet> uniqueKeys = mq.getUniqueKeys(rel);
    final ImmutableBitSet allCols = ImmutableBitSet.range(0, rel.getRowType().getFieldCount());
    for (ImmutableBitSet key : allCols.powerSet()) {
        Boolean result2 = mq.areColumnsUnique(rel, key);
        assertTrue(result2 == null || result2 == isUnique(uniqueKeys, key));
    }
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet)

Example 58 with ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project calcite by apache.

the class RelMetadataTest method testUnion.

@Test
public void testUnion() {
    RelNode rel = convertSql("select deptno from emp\n" + "union\n" + "select deptno from dept");
    final RelMetadataQuery mq = RelMetadataQuery.instance();
    final Set<ImmutableBitSet> result = mq.getUniqueKeys(rel);
    assertThat(result, CoreMatchers.<Set<ImmutableBitSet>>equalTo(ImmutableSet.of(ImmutableBitSet.of(0))));
    assertUniqueConsistent(rel);
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) Test(org.junit.Test)

Example 59 with ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.

the class LogicalRelImplementor method visit.

/**
 * {@inheritDoc}
 */
@Override
public Node<RowT> visit(IgniteTableScan rel) {
    RexNode condition = rel.condition();
    List<RexNode> projects = rel.projects();
    ImmutableBitSet requiredColumns = rel.requiredColumns();
    InternalIgniteTable tbl = rel.getTable().unwrap(InternalIgniteTable.class);
    assert tbl != null;
    IgniteTypeFactory typeFactory = ctx.getTypeFactory();
    RelDataType rowType = tbl.getRowType(typeFactory, requiredColumns);
    Predicate<RowT> filters = condition == null ? null : expressionFactory.predicate(condition, rowType);
    Function<RowT, RowT> prj = projects == null ? null : expressionFactory.project(projects, rowType);
    ColocationGroup group = ctx.group(rel.sourceId());
    if (!group.nodeIds().contains(ctx.localNodeId())) {
        return new ScanNode<>(ctx, rowType, Collections.emptyList());
    }
    return new TableScanNode<>(ctx, rowType, tbl, group.partitions(ctx.localNodeId()), filters, prj, requiredColumns);
}
Also used : ColocationGroup(org.apache.ignite.internal.sql.engine.metadata.ColocationGroup) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) TableScanNode(org.apache.ignite.internal.sql.engine.exec.rel.TableScanNode) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) ScanNode(org.apache.ignite.internal.sql.engine.exec.rel.ScanNode) TableScanNode(org.apache.ignite.internal.sql.engine.exec.rel.TableScanNode) RexNode(org.apache.calcite.rex.RexNode)

Example 60 with ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.

the class LogicalRelImplementor method visit.

/**
 * {@inheritDoc}
 */
@Override
public Node<RowT> visit(IgniteIndexScan rel) {
    // TODO: fix this
    // RexNode condition = rel.condition();
    // List<RexNode> projects = rel.projects();
    InternalIgniteTable tbl = rel.getTable().unwrap(InternalIgniteTable.class);
    IgniteTypeFactory typeFactory = ctx.getTypeFactory();
    ImmutableBitSet requiredColumns = rel.requiredColumns();
    // List<RexNode> lowerCond = rel.lowerBound();
    // List<RexNode> upperCond = rel.upperBound();
    RelDataType rowType = tbl.getRowType(typeFactory, requiredColumns);
    // Predicate<Row> filters = condition == null ? null : expressionFactory.predicate(condition, rowType);
    // Supplier<Row> lower = lowerCond == null ? null : expressionFactory.rowSource(lowerCond);
    // Supplier<Row> upper = upperCond == null ? null : expressionFactory.rowSource(upperCond);
    // Function<Row, Row> prj = projects == null ? null : expressionFactory.project(projects, rowType);
    // 
    // IgniteIndex idx = tbl.getIndex(rel.indexName());
    // 
    // ColocationGroup group = ctx.group(rel.sourceId());
    Iterable<RowT> rowsIter = (Iterable<RowT>) List.of(new Object[] { 0, 0 }, // idx.scan(ctx, group, filters, lower, upper, prj, requiredColumns);
    new Object[] { 1, 1 });
    return new ScanNode<>(ctx, rowType, rowsIter);
}
Also used : InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) ScanNode(org.apache.ignite.internal.sql.engine.exec.rel.ScanNode) TableScanNode(org.apache.ignite.internal.sql.engine.exec.rel.TableScanNode)

Aggregations

ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)365 RexNode (org.apache.calcite.rex.RexNode)196 RelNode (org.apache.calcite.rel.RelNode)183 ArrayList (java.util.ArrayList)179 AggregateCall (org.apache.calcite.rel.core.AggregateCall)116 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)98 RexBuilder (org.apache.calcite.rex.RexBuilder)92 RelDataType (org.apache.calcite.rel.type.RelDataType)89 RexInputRef (org.apache.calcite.rex.RexInputRef)79 HashMap (java.util.HashMap)68 Aggregate (org.apache.calcite.rel.core.Aggregate)62 RelBuilder (org.apache.calcite.tools.RelBuilder)59 Pair (org.apache.calcite.util.Pair)57 List (java.util.List)49 ImmutableList (com.google.common.collect.ImmutableList)48 HashSet (java.util.HashSet)45 LinkedHashSet (java.util.LinkedHashSet)45 Join (org.apache.calcite.rel.core.Join)45 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)45 Nullable (org.checkerframework.checker.nullness.qual.Nullable)43