vlsi commented on a change in pull request #2613:
URL: https://github.com/apache/calcite/pull/2613#discussion_r764775481



##########
File path: core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
##########
@@ -2482,6 +2483,46 @@ private void checkPredicates(RelOptCluster cluster, 
RelOptTable empTable,
     assertThat(inputRef1.getIdentifier(), is(inputRef2.getIdentifier()));
   }
 
+  @Test void testExpressionLineageConjuntiveExpression() {
+    final String sql = "select (empno = 1 or ename = 'abc') and deptno > 1 
from emp";
+    final RelNode rel = convertSql(sql);
+    final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
+
+    final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
+    final Set<RexNode> r = Objects.requireNonNull(mq.getExpressionLineage(rel, 
ref));
+
+    final String assertionMessage = "For query '" + sql + "':\n"
+        + "'empno' is column 0 in 'catalog.sales.emp', "
+        + "'ename' is column 1 in 'catalog.sales.emp', and "
+        + "'deptno' is column 7 in 'catalog.sales.emp'";
+
+    final String actualExp = Iterables.getOnlyElement(r).toString();
+    assertEquals("AND(OR(=([CATALOG, SALES, EMP].#0.$0, 1),"
+        + " =([CATALOG, SALES, EMP].#0.$1, 'abc')),"
+        + " >([CATALOG, SALES, EMP].#0.$7, 1))", actualExp, assertionMessage);
+  }
+
+  @Test void testExpressionLineageBetweenExpressionWithJoin() {
+    final String sql = "select dept.deptno + empno between 1 and 2"
+        + " from emp join dept on emp.deptno = dept.deptno";
+    final RelNode rel = convertSql(sql);
+    final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
+
+    final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
+    final Set<RexNode> r = Objects.requireNonNull(mq.getExpressionLineage(rel, 
ref));

Review comment:
       This seems to be duplicated across methods, so it would be nice to 
extract it into `assertExpressionLineage(sql, columnIndex, Supplier<String> 
message)`




-- 
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]


Reply via email to