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


##########
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:
   @silundong Thank you for providing the example. I have added the 
corresponding tests in quidem and RelOptRulesTest.



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