use of org.apache.calcite.rex.RexTableInputRef in project calcite by apache.
the class RelMetadataTest method testAllPredicatesAggregate2.
@Test
public void testAllPredicatesAggregate2() {
final String sql = "select * from (select a, max(b) from (\n" + " select empno as a, sal as b from emp)subq\n" + "group by a) \n" + "where a = 5";
final RelNode rel = convertSql(sql);
final RelMetadataQuery mq = RelMetadataQuery.instance();
RelOptPredicateList inputSet = mq.getAllPredicates(rel);
ImmutableList<RexNode> pulledUpPredicates = inputSet.pulledUpPredicates;
assertThat(pulledUpPredicates.size(), is(1));
RexCall call = (RexCall) pulledUpPredicates.get(0);
assertThat(call.getOperands().size(), is(2));
final RexTableInputRef inputRef1 = (RexTableInputRef) call.getOperands().get(0);
assertTrue(inputRef1.getQualifiedName().equals(EMP_QNAME));
assertThat(inputRef1.getIndex(), is(0));
final RexLiteral constant = (RexLiteral) call.getOperands().get(1);
assertThat(constant.toString(), is("5"));
}
use of org.apache.calcite.rex.RexTableInputRef in project calcite by apache.
the class RelMetadataTest method testExpressionLineageTwoColumns.
@Test
public void testExpressionLineageTwoColumns() {
// mgr is column 3 in catalog.sales.emp
// deptno is column 7 in catalog.sales.emp
final RelNode rel = convertSql("select mgr, deptno from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref1 = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r1 = mq.getExpressionLineage(rel, ref1);
assertThat(r1.size(), is(1));
final RexTableInputRef result1 = (RexTableInputRef) r1.iterator().next();
assertTrue(result1.getQualifiedName().equals(EMP_QNAME));
assertThat(result1.getIndex(), is(3));
final RexNode ref2 = RexInputRef.of(1, rel.getRowType().getFieldList());
final Set<RexNode> r2 = mq.getExpressionLineage(rel, ref2);
assertThat(r2.size(), is(1));
final RexTableInputRef result2 = (RexTableInputRef) r2.iterator().next();
assertTrue(result2.getQualifiedName().equals(EMP_QNAME));
assertThat(result2.getIndex(), is(7));
assertThat(result1.getIdentifier(), is(result2.getIdentifier()));
}
use of org.apache.calcite.rex.RexTableInputRef in project calcite by apache.
the class RelMetadataTest method testExpressionLineageUnion.
@Test
public void testExpressionLineageUnion() {
// sal is column 5 in catalog.sales.emp
final RelNode rel = convertSql("select sal from (\n" + " select * from emp union all select * from emp) " + "where deptno = 10");
final RelNode tableRel = convertSql("select * from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r = mq.getExpressionLineage(rel, ref);
final String inputRef = RexInputRef.of(5, tableRel.getRowType().getFieldList()).toString();
assertThat(r.size(), is(2));
for (RexNode result : r) {
final String resultString = result.toString();
assertThat(resultString, startsWith(EMP_QNAME.toString()));
assertThat(resultString, endsWith(inputRef));
}
Iterator<RexNode> it = r.iterator();
assertThat(((RexTableInputRef) it.next()).getIdentifier(), not(((RexTableInputRef) it.next()).getIdentifier()));
}
use of org.apache.calcite.rex.RexTableInputRef in project calcite by apache.
the class RelMetadataTest method testExpressionLineageSelfJoin.
@Test
public void testExpressionLineageSelfJoin() {
// deptno is column 7 in catalog.sales.emp
// sal is column 5 in catalog.sales.emp
final RelNode rel = convertSql("select a.deptno, b.sal from (select * from emp limit 7) as a\n" + "inner join (select * from emp limit 2) as b\n" + "on a.deptno = b.deptno");
final RelNode tableRel = convertSql("select * from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref1 = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r1 = mq.getExpressionLineage(rel, ref1);
final String inputRef1 = RexInputRef.of(7, tableRel.getRowType().getFieldList()).toString();
assertThat(r1.size(), is(1));
final String resultString1 = r1.iterator().next().toString();
assertThat(resultString1, startsWith(EMP_QNAME.toString()));
assertThat(resultString1, endsWith(inputRef1));
final RexNode ref2 = RexInputRef.of(1, rel.getRowType().getFieldList());
final Set<RexNode> r2 = mq.getExpressionLineage(rel, ref2);
final String inputRef2 = RexInputRef.of(5, tableRel.getRowType().getFieldList()).toString();
assertThat(r2.size(), is(1));
final String resultString2 = r2.iterator().next().toString();
assertThat(resultString2, startsWith(EMP_QNAME.toString()));
assertThat(resultString2, endsWith(inputRef2));
assertThat(((RexTableInputRef) r1.iterator().next()).getIdentifier(), not(((RexTableInputRef) r2.iterator().next()).getIdentifier()));
}
use of org.apache.calcite.rex.RexTableInputRef in project calcite by apache.
the class RelMetadataTest method testExpressionLineageInnerJoinLeft.
@Test
public void testExpressionLineageInnerJoinLeft() {
// ename is column 1 in catalog.sales.emp
final RelNode rel = convertSql("select ename from emp,dept");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r = mq.getExpressionLineage(rel, ref);
assertThat(r.size(), is(1));
final RexTableInputRef result = (RexTableInputRef) r.iterator().next();
assertTrue(result.getQualifiedName().equals(EMP_QNAME));
assertThat(result.getIndex(), is(1));
}
Aggregations