use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class RelMetadataTest method testAllPredicatesAggregate3.
@Test
public void testAllPredicatesAggregate3() {
final String sql = "select * from (select a, max(b) as b from (\n" + " select empno as a, sal as b from emp)subq\n" + "group by a) \n" + "where b = 5";
final RelNode rel = convertSql(sql);
final RelMetadataQuery mq = RelMetadataQuery.instance();
RelOptPredicateList inputSet = mq.getAllPredicates(rel);
// Filter on aggregate, we cannot infer lineage
assertNull(inputSet);
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class RelMetadataTest method testPullUpPredicatesFromAggregation.
/**
* Unit test for
* {@link org.apache.calcite.rel.metadata.RelMdPredicates#getPredicates(Aggregate, RelMetadataQuery)}.
*/
@Test
public void testPullUpPredicatesFromAggregation() {
final String sql = "select a, max(b) from (\n" + " select 1 as a, 2 as b from emp)subq\n" + "group by a";
final Aggregate rel = (Aggregate) convertSql(sql);
final RelMetadataQuery mq = RelMetadataQuery.instance();
RelOptPredicateList inputSet = mq.getPulledUpPredicates(rel);
ImmutableList<RexNode> pulledUpPredicates = inputSet.pulledUpPredicates;
assertThat(pulledUpPredicates, sortsAs("[=($0, 1)]"));
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class RelMetadataTest method checkRowCount.
private void checkRowCount(String sql, double expected, double expectedMin, double expectedMax) {
RelNode rel = convertSql(sql);
final RelMetadataQuery mq = RelMetadataQuery.instance();
final Double result = mq.getRowCount(rel);
assertThat(result, notNullValue());
assertEquals(expected, result, 0d);
final Double max = mq.getMaxRowCount(rel);
assertThat(max, notNullValue());
assertEquals(expectedMax, max, 0d);
final Double min = mq.getMinRowCount(rel);
assertThat(max, notNullValue());
assertEquals(expectedMin, min, 0d);
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class RelMetadataTest method testPullUpPredicatesOnConstant.
@Test
public void testPullUpPredicatesOnConstant() {
final String sql = "select deptno, mgr, x, 'y' as y, z from (\n" + " select deptno, mgr, cast(null as integer) as x, cast('1' as int) as z\n" + " from emp\n" + " where mgr is null and deptno < 10)";
final RelNode rel = convertSql(sql);
final RelMetadataQuery mq = RelMetadataQuery.instance();
RelOptPredicateList list = mq.getPulledUpPredicates(rel);
assertThat(list.pulledUpPredicates, sortsAs("[<($0, 10), =($3, 'y'), =($4, 1), IS NULL($1), IS NULL($2)]"));
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class RelMetadataTest method testPullUpPredicatesForExprsItr.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1960">[CALCITE-1960]
* RelMdPredicates.getPredicates is slow if there are many equivalent
* columns</a>. There are much less duplicates after
* <a href="https://issues.apache.org/jira/browse/CALCITE-2205">[CALCITE-2205]</a>.
* Since this is a performance problem, the test result does not
* change, but takes over 15 minutes before the fix and 6 seconds after.
*/
@Test(timeout = 20_000)
public void testPullUpPredicatesForExprsItr() {
// If we're running Windows, we are probably in a VM and the test may
// exceed timeout by a small margin.
Assume.assumeThat("Too slow to run on Windows", File.separatorChar, Is.is('/'));
final String sql = "select a.EMPNO, a.ENAME\n" + "from (select * from sales.emp ) a\n" + "join (select * from sales.emp ) b\n" + "on a.empno = b.deptno\n" + " and a.comm = b.comm\n" + " and a.mgr=b.mgr\n" + " and (a.empno < 10 or a.comm < 3 or a.deptno < 10\n" + " or a.job ='abc' or a.ename='abc' or a.sal='30' or a.mgr >3\n" + " or a.slacker is not null or a.HIREDATE is not null\n" + " or b.empno < 9 or b.comm < 3 or b.deptno < 10 or b.job ='abc'\n" + " or b.ename='abc' or b.sal='30' or b.mgr >3 or b.slacker )\n" + "join emp c\n" + "on b.mgr =a.mgr and a.empno =b.deptno and a.comm=b.comm\n" + " and a.deptno=b.deptno and a.job=b.job and a.ename=b.ename\n" + " and a.mgr=b.deptno and a.slacker=b.slacker";
// Lock to ensure that only one test is using this method at a time.
try (final JdbcAdapterTest.LockWrapper ignore = JdbcAdapterTest.LockWrapper.lock(LOCK)) {
final RelNode rel = convertSql(sql);
final RelMetadataQuery mq = RelMetadataQuery.instance();
RelOptPredicateList inputSet = mq.getPulledUpPredicates(rel.getInput(0));
assertThat(inputSet.pulledUpPredicates.size(), is(18));
}
}
Aggregations