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



##########
File path: 
core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewRule.java
##########
@@ -1036,21 +1037,36 @@ protected NodeLineage 
generateSwapTableColumnReferencesLineage(
     final Map<RexNode, Integer> exprsLineage = new HashMap<>();
     final Map<RexNode, Integer> exprsLineageLosslessCasts = new HashMap<>();
     for (int i = 0; i < nodeExprs.size(); i++) {
-      final Set<RexNode> s = mq.getExpressionLineage(node, nodeExprs.get(i));
-      if (s == null) {
+      final Set<RexNode> lineages = mq.getExpressionLineage(node, 
nodeExprs.get(i));
+      if (lineages == null) {
         // Next expression
         continue;
       }
-      // We only support project - filter - join, thus it should map to
-      // a single expression
-      assert s.size() == 1;
-      // Rewrite expr. First we swap the table references following the table
-      // mapping, then we take first element from the corresponding 
equivalence class
-      final RexNode e = RexUtil.swapTableColumnReferences(rexBuilder,
-          s.iterator().next(), tableMapping, ec.getEquivalenceClassesMap());
-      exprsLineage.put(e, i);
-      if (RexUtil.isLosslessCast(e)) {
-        exprsLineageLosslessCasts.put(((RexCall) e).getOperands().get(0), i);
+      final RexNode expr = nodeExprs.get(i);
+      if (SqlKind.AND == expr.getKind() || SqlKind.OR == expr.getKind()) {

Review comment:
       Why do we need to restrict ourselves to AND/OR expressions? I suppose 
the same problem can re-appear easily if we have other kind of expressions 
e.g., `s.time_id + s.time_id`. Can't we apply a generic solution here?
   
   Moreover, I am not sure that `mq.expressionsLineage` works as expected. I 
checked the javadoc of `RelMdExpressionLineage#createAllPossibleCombinations` 
and it is supposed to return an equivalent expression with the one given as 
input. If the input is `A > 1 AND A <3 ` why in the output  we have `A > 1`, 
`A<3` decomposed. Is this normal?




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