use of org.apache.calcite.rel.metadata.RelMetadataQuery 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.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class RelMetadataTest method checkNodeTypeCount.
private void checkNodeTypeCount(String sql, Map<Class<? extends RelNode>, Integer> expected) {
final RelNode rel = convertSql(sql);
final RelMetadataQuery mq = RelMetadataQuery.instance();
final Multimap<Class<? extends RelNode>, RelNode> result = mq.getNodeTypes(rel);
assertThat(result, notNullValue());
final Map<Class<? extends RelNode>, Integer> resultCount = new HashMap<>();
for (Entry<Class<? extends RelNode>, Collection<RelNode>> e : result.asMap().entrySet()) {
resultCount.put(e.getKey(), e.getValue().size());
}
assertEquals(expected, resultCount);
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class RelMetadataTest method checkRelSelectivity.
private void checkRelSelectivity(RelNode rel, double expected) {
final RelMetadataQuery mq = RelMetadataQuery.instance();
Double result = mq.getSelectivity(rel, null);
assertTrue(result != null);
assertEquals(expected, result, EPSILON);
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery 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.calcite.rel.metadata.RelMetadataQuery 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