korlov42 commented on a change in pull request #2623:
URL: https://github.com/apache/calcite/pull/2623#discussion_r828789364
##########
File path: core/src/main/java/org/apache/calcite/tools/RelBuilder.java
##########
@@ -1794,7 +1794,74 @@ public RelBuilder project(Iterable<? extends RexNode>
nodes,
*/
public RelBuilder project(Iterable<? extends RexNode> nodes,
Iterable<? extends @Nullable String> fieldNames, boolean force) {
- return project_(nodes, fieldNames, ImmutableList.of(), force);
+ return project_(ImmutableSet.of(), nodes, fieldNames, ImmutableList.of(),
force);
+ }
+
+ /** Creates a {@link Project} of a set of correlation variables
+ * and the given expressions. */
+ public RelBuilder projectCorrelated(Iterable<CorrelationId> variablesSet,
+ RexNode... nodes) {
+ return projectCorrelated(variablesSet, ImmutableList.copyOf(nodes));
+ }
+
+ /** Creates a {@link Project} of a set of correlation variables
+ * and the given list of expressions.
+ *
+ * <p>Infers names as would {@link #projectCorrelated(Iterable, Iterable,
Iterable)}
+ * if all suggested names were null.
+ *
+ * @param variablesSet Set of correlation variables
+ * @param nodes Expressions
+ */
+ public RelBuilder projectCorrelated(Iterable<CorrelationId> variablesSet,
+ Iterable<? extends RexNode> nodes) {
+ return projectCorrelated(variablesSet, nodes, ImmutableList.of());
+ }
+
+ /** Creates a {@link Project} of a set of correlation variables
+ * and the given list of expressions and field names.
+ *
+ * @param variablesSet Set of correlation variables
+ * @param nodes Expressions
+ * @param fieldNames field names for expressions
+ */
+ public RelBuilder projectCorrelated(
+ Iterable<CorrelationId> variablesSet,
+ Iterable<? extends RexNode> nodes,
+ Iterable<? extends @Nullable String> fieldNames) {
+ return projectCorrelated(variablesSet, nodes, fieldNames, false);
+ }
+
+ /** Creates a {@link Project} of a set of correlation variables
+ * and the given list of expressions, using the given names.
+ *
+ * <p>Names are deduced as follows:
+ * <ul>
+ * <li>If the length of {@code fieldNames} is greater than the index of
+ * the current entry in {@code nodes}, and the entry in
+ * {@code fieldNames} is not null, uses it; otherwise
+ * <li>If an expression projects an input field,
+ * or is a cast an input field,
+ * uses the input field name; otherwise
+ * <li>If an expression is a call to
+ * {@link SqlStdOperatorTable#AS}
+ * (see {@link #alias}), removes the call but uses the intended alias.
+ * </ul>
+ *
+ * <p>After the field names have been inferred, makes the
+ * field names unique by appending numeric suffixes.
+ *
+ * @param variablesSet Set of correlation variables
+ * @param nodes Expressions
+ * @param fieldNames Suggested field names
+ * @param force create project even if it is identity
+ */
+ public RelBuilder projectCorrelated(
+ Iterable<CorrelationId> variablesSet,
+ Iterable<? extends RexNode> nodes,
+ Iterable<? extends @Nullable String> fieldNames,
+ boolean force) {
+ return project_(variablesSet, nodes, fieldNames, ImmutableList.of(),
force);
Review comment:
RelBuilder is used by downstream projects. Since now we could pass
correlation variables to the project, I believe it's good idea to give an
ability to do it with builder
--
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]