asolimando commented on a change in pull request #2613:
URL: https://github.com/apache/calcite/pull/2613#discussion_r763227407
##########
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:
Finally my diagnosis is that `mq.expressionsLineage` was indeed broken,
it was decomposing top `AND` expressions for no apparent good reason.
Luckily there were unit tests, just not where I expected them to be, I have
managed to reproduce the issue in one of them, and double checked that the fix
did handle it, and at the same time that nothing else broke.
Please have another look @zabetak if you have some spare cycles, thanks a
lot for the tip, I was heading down a slippery road :)
--
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]