asolimando commented on a change in pull request #2613:
URL: https://github.com/apache/calcite/pull/2613#discussion_r764732068
##########
File path: core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
##########
@@ -2482,6 +2482,41 @@ private void checkPredicates(RelOptCluster cluster,
RelOptTable empTable,
assertThat(inputRef1.getIdentifier(), is(inputRef2.getIdentifier()));
}
+ @Test void testExpressionLineageConjuntiveExpression() {
+ // empno is column 0 in catalog.sales.emp
+ // ename is column 1 in catalog.sales.emp
+ // deptno is column 7 in catalog.sales.emp
+ final RelNode rel = convertSql("select (empno = 1 or ename = 'abc') and
deptno > 1 from emp");
+ final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
+
+ final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
+ final Set<RexNode> r = mq.getExpressionLineage(rel, ref);
+ assertThat(r.size(), is(1));
+
+ final String actualExp = r.iterator().next().toString();
+ assertEquals("AND(OR(=([CATALOG, SALES, EMP].#0.$0, 1),"
+ + " =([CATALOG, SALES, EMP].#0.$1, 'abc')),"
+ + " >([CATALOG, SALES, EMP].#0.$7, 1))", actualExp);
+ }
+
+ @Test void testExpressionLineageBetweenExpressionWithJoin() {
+ // empno is column 0 in catalog.sales.emp
+ // deptno is column 0 in catalog.sales.dept
+ final RelNode rel = convertSql("select dept.deptno + empno between 1 and 2"
+ + " from emp join dept on emp.deptno = dept.deptno");
+ final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
+
+ final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
+ final Set<RexNode> r = mq.getExpressionLineage(rel, ref);
+ assertThat(r.size(), is(1));
+
+ // 'dept.deptno + empno between 1 and 2' is translated into
+ // 'dept.deptno + empno >= 1 and dept.deptno + empno <= 2'
+ final String actualExp = r.iterator().next().toString();
+ assertEquals("AND(>=(+([CATALOG, SALES, DEPT].#0.$0, [CATALOG, SALES,
EMP].#0.$0), 1),"
Review comment:
I have added an assertion message, failures now look like this:
```
For query 'select dept.deptno + empno between 1 and 2 from emp join dept on
emp.deptno = dept.deptno':
'empno' is column 0 in 'catalog.sales.emp', 'deptno' is column 0 in
'catalog.sales.dept', and 'dept.deptno + empno between 1 and 2' is translated
into 'dept.deptno + empno >= 1 and dept.deptno + empno <= 2' ==> expected:
<AND(>=(+([CATALOG, SALES, DEPT].#0.$0, [CATALOG, SALES, EMP].#0.$0), 1),
<=(+([CATALOG, SALES, DEPT].#0.$0, [CATALOG, SALES, EMP].#0.$0), 2)> but was:
<AND(>=(+([CATALOG, SALES, DEPT].#0.$0, [CATALOG, SALES, EMP].#0.$0), 1),
<=(+([CATALOG, SALES, DEPT].#0.$0, [CATALOG, SALES, EMP].#0.$0), 2))>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]