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_r355708215
##########
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:
My vote would be to throw IllegalArgumentException, not throw
RESOURCE.something. This is an API error, not a user error.
Don't make too much effort to accommodate people who are using the API
incorrectly. Make the specification as simple as possible, and if people use it
wrong, throw.
The simplest thing is probably `Collections.removeAll(Collection)`. Keep the
argument as type `Iterable`, but cast or convert it to a collection.
----------------------------------------------------------------
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