use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.ImmutableBitSet in project calcite by apache.
the class AggregatingSelectScope method resolve.
// ~ Methods ----------------------------------------------------------------
private Resolved resolve() {
final ImmutableList.Builder<ImmutableList<ImmutableBitSet>> builder = ImmutableList.builder();
List<SqlNode> extraExprs = ImmutableList.of();
Map<Integer, Integer> groupExprProjection = ImmutableMap.of();
if (select.getGroup() != null) {
final SqlNodeList groupList = select.getGroup();
final SqlValidatorUtil.GroupAnalyzer groupAnalyzer = new SqlValidatorUtil.GroupAnalyzer(temporaryGroupExprList);
for (SqlNode groupExpr : groupList) {
SqlValidatorUtil.analyzeGroupItem(this, groupAnalyzer, builder, groupExpr);
}
extraExprs = groupAnalyzer.extraExprs;
groupExprProjection = groupAnalyzer.groupExprProjection;
}
final Set<ImmutableBitSet> flatGroupSets = Sets.newTreeSet(ImmutableBitSet.COMPARATOR);
for (List<ImmutableBitSet> groupSet : Linq4j.product(builder.build())) {
flatGroupSets.add(ImmutableBitSet.union(groupSet));
}
// For GROUP BY (), we need a singleton grouping set.
if (flatGroupSets.isEmpty()) {
flatGroupSets.add(ImmutableBitSet.of());
}
return new Resolved(extraExprs, temporaryGroupExprList, flatGroupSets, groupExprProjection);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.ImmutableBitSet in project calcite by apache.
the class RelMetadataTest method testDistinctRowCountTable.
@Test
public void testDistinctRowCountTable() {
// no unique key information is available so return null
RelNode rel = convertSql("select * from emp where deptno = 10");
final RelMetadataQuery mq = RelMetadataQuery.instance();
ImmutableBitSet groupKey = ImmutableBitSet.of(rel.getRowType().getFieldNames().indexOf("DEPTNO"));
Double result = mq.getDistinctRowCount(rel, groupKey, null);
assertThat(result, nullValue());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.ImmutableBitSet in project calcite by apache.
the class RelMetadataTest method testCorrelateUniqueKeys.
@Test
public void testCorrelateUniqueKeys() {
final String sql = "select *\n" + "from (select distinct deptno from emp) as e,\n" + " lateral (\n" + " select * from dept where dept.deptno = e.deptno)";
final RelNode rel = convertSql(sql);
final RelMetadataQuery mq = RelMetadataQuery.instance();
assertThat(rel, isA((Class) Project.class));
final Project project = (Project) rel;
final Set<ImmutableBitSet> result = mq.getUniqueKeys(project);
assertThat(result, sortsAs("[{0}]"));
if (false) {
assertUniqueConsistent(project);
}
assertThat(project.getInput(), isA((Class) Correlate.class));
final Correlate correlate = (Correlate) project.getInput();
final Set<ImmutableBitSet> result2 = mq.getUniqueKeys(correlate);
assertThat(result2, sortsAs("[{0}]"));
if (false) {
assertUniqueConsistent(correlate);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.ImmutableBitSet in project calcite by apache.
the class RelMetadataTest method testJoinUniqueKeys.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-509">[CALCITE-509]
* "RelMdColumnUniqueness uses ImmutableBitSet.Builder twice, gets
* NullPointerException"</a>.
*/
@Test
public void testJoinUniqueKeys() {
RelNode rel = convertSql("select * from emp join bonus using (ename)");
final RelMetadataQuery mq = RelMetadataQuery.instance();
Set<ImmutableBitSet> result = mq.getUniqueKeys(rel);
assertThat(result.isEmpty(), is(true));
assertUniqueConsistent(rel);
}
use of org.apache.beam.vendor.calcite.v1_28_0.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));
}
Aggregations