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));
}
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));
}
}
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);
}
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);
}
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);
}
Aggregations