julianhyde commented on a change in pull request #1554: [CALCITE-3462] Add
method in RelBuilder for conveniently projecting out expressions
URL: https://github.com/apache/calcite/pull/1554#discussion_r355784386
##########
File path: core/src/main/java/org/apache/calcite/tools/RelBuilder.java
##########
@@ -1259,15 +1255,33 @@ public RelBuilder projectPlus(RexNode... nodes) {
return projectPlus(ImmutableList.copyOf(nodes));
}
- /** Creates a {@link Project} of all original fields, plus the given list of
+ /** Creates a {@link Project} of all original fields, plus the given
* expressions. */
public RelBuilder projectPlus(Iterable<RexNode> nodes) {
final ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
return project(builder.addAll(fields()).addAll(nodes).build());
}
- /** Creates a {@link Project} of the given list
- * of expressions, using the given names.
+ /** Creates a {@link Project} of all original fields, except the given
+ * expressions. */
+ public RelBuilder projectExcept(RexNode... expressions) {
+ return projectExcept(ImmutableList.copyOf(expressions));
+ }
+
+ /** Creates a {@link Project} of all original fields, except the given
+ * expressions. */
+ public RelBuilder projectExcept(Iterable<RexNode> expressions) {
+ List<RexNode> allExpressions = new ArrayList<>(fields());
+ for (RexNode excludeExp : expressions) {
+ if (!allExpressions.remove(excludeExp)) {
+ throw RESOURCE.expressionNotFound(excludeExp.toString()).ex();
Review comment:
The javadoc should say what happens if the expressions do not exist. It's
part of the contract.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services