julianhyde commented on code in PR #2916:
URL: https://github.com/apache/calcite/pull/2916#discussion_r977348821
##########
core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java:
##########
@@ -551,17 +529,15 @@ public interface JoinRightEmptyRuleConfig extends
PruneEmptyRule.Config {
// "select * from emp left join dept" is not necessarily empty if
// dept is empty
// join can be removed and take the left branch, all columns come
from dept are null
- List<RexNode> projects = new ArrayList<>(
- left.getRowType().getFieldCount() +
empty.getRowType().getFieldCount());
- List<String> columnNames = new ArrayList<>(
- left.getRowType().getFieldCount() +
empty.getRowType().getFieldCount());
- // left
- copyProjects(
- rexBuilder, left.getRowType(), join.getRowType(), 0, projects,
columnNames);
- // right
- addNullLiterals(rexBuilder, empty, projects, columnNames);
-
- RelNode project = call.builder().push(left).project(projects,
columnNames).build();
+ List<Pair<? extends RexNode, String>> projects =
+ Stream.concat(
+ getProjectStream(left.getRowType(), join.getRowType(), 0,
rexBuilder),
+ getNullLiteralStream(empty,
rexBuilder)).collect(Collectors.toList());
+
+ RelNode project = call.builder()
+ .push(left)
+ .project(Pair.left(projects), Pair.right(projects))
+ .build();
Review Comment:
I have a feeling that it could be even shorter if you use Guava's
`List.concat()` rather than `Stream.concat()`, and use `RelBuilder.fields()`.
You'll have to assign the `RelBuilder` to a variable.
--
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]