silundong commented on code in PR #4758:
URL: https://github.com/apache/calcite/pull/4758#discussion_r2708989006


##########
core/src/main/java/org/apache/calcite/rel/rules/SingleValuesOptimizationRules.java:
##########
@@ -121,41 +121,36 @@ protected SingleValuesRelTransformer(
       if (!transformable.test(join)) {
         return null;
       }
-      int end = valuesAsLeftChild
-          ? join.getLeft().getRowType().getFieldCount()
-          : join.getRowType().getFieldCount();
-
-      int start = valuesAsLeftChild
-          ? 0
-          : join.getLeft().getRowType().getFieldCount();
-      ImmutableBitSet bitSet = ImmutableBitSet.range(start, end);
-      RexNode trueNode = relBuilder.getRexBuilder().makeLiteral(true);
-      final RexNode filterCondition =
-          new RexNodeReplacer(bitSet,
-              literals,
-              (valuesAsLeftChild ? 0 : -1) * 
join.getLeft().getRowType().getFieldCount())
+      final int leftCount = join.getLeft().getRowType().getFieldCount();
+      final int rightCount = join.getRight().getRowType().getFieldCount();
+      final int start = valuesAsLeftChild ? 0 : leftCount;
+      final int end = start + (valuesAsLeftChild ? leftCount : rightCount);
+      final int offset = valuesAsLeftChild ? 0 : -leftCount;
+
+      final ImmutableBitSet bitSet = ImmutableBitSet.range(start, end);
+      RexNode condition =
+          new RexNodeReplacer(bitSet, literals, offset)
               .go(join.getCondition());
 
-      RexNode fixedCondition =
-          valuesAsLeftChild
-              ? RexUtil.shift(filterCondition,
-              -1 * join.getLeft().getRowType().getFieldCount())
-              : filterCondition;
-
-      List<RexNode> rexLiterals = litTransformer.apply(fixedCondition, 
literals);
-      relBuilder.push(relNode)
-          .filter(join.getJoinType().isOuterJoin() ? trueNode : 
fixedCondition);
-
-      List<RexNode> rexNodes = relNode
-          .getRowType()
-          .getFieldList()
-          .stream()
-          .map(fld -> relBuilder.field(fld.getIndex()))
-          .collect(Collectors.toList());
-
-      List<RexNode> projects = new ArrayList<>();
-      projects.addAll(valuesAsLeftChild ? rexLiterals : rexNodes);
-      projects.addAll(valuesAsLeftChild ? rexNodes : rexLiterals);
+      if (valuesAsLeftChild) {
+        condition = RexUtil.shift(condition, -leftCount);
+      }
+
+      relBuilder.push(relNode);
+      if (!join.getJoinType().isOuterJoin()) {
+        relBuilder.filter(condition);
+      }
+
+      final List<RexNode> otherNodes = relBuilder.fields();
+      final List<RexNode> valuesNodes = litTransformer.apply(condition, 
literals);

Review Comment:
   There may be another potential error here. The current functionality of 
`litTransformer` seems to be calculating the join partner (NULL or a single 
row) from the `Values` ​​based on the join condition and join type. However, 
for LEFT MARK join, `litTransformer.apply` should return the marker, i.e., the 
result of the join condition.



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