hsyuan commented on a change in pull request #1884:
URL: https://github.com/apache/calcite/pull/1884#discussion_r416350911



##########
File path: core/src/main/java/org/apache/calcite/tools/RelBuilder.java
##########
@@ -2497,6 +2509,17 @@ public RelBuilder sortLimit(int offset, int fetch, 
RexNode... nodes) {
     return sortLimit(offset, fetch, ImmutableList.copyOf(nodes));
   }
 
+  /** Creates a {@link Sort} by specifying collations.
+   */
+  public RelBuilder sort(List<RelFieldCollation> collations) {
+    final ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
+    for (RelFieldCollation collation : collations) {
+      builder.add(collation.direction.isDescending()
+          ? desc(field(collation.getFieldIndex())) : 
field(collation.getFieldIndex()));
+    }
+    return sortLimit(-1, -1, builder.build());

Review comment:
       This will be easier:
   ```
   final RelNode sort =
                 struct.sortFactory.createSort(peek(), collation,
                     null, null);
             replaceTop(sort);
             return this;
   ```




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


Reply via email to