raminqaf commented on code in PR #28367:
URL: https://github.com/apache/flink/pull/28367#discussion_r3385860964


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/SortQueryOperation.java:
##########
@@ -92,23 +92,25 @@ public String asSerializableString(SqlFactory sqlFactory) {
         final StringBuilder s =
                 new StringBuilder(
                         String.format(
-                                "SELECT %s FROM (%s\n) %s ORDER BY %s",
+                                "SELECT %s FROM (%s\n) %s",
                                 OperationUtils.formatSelectColumns(
                                         getResolvedSchema(), INPUT_ALIAS),
                                 
OperationUtils.indent(child.asSerializableString(sqlFactory)),
-                                INPUT_ALIAS,
-                                order.stream()
-                                        .map(
-                                                expr ->
-                                                        
OperationExpressionsUtils
-                                                                
.scopeReferencesWithAlias(
-                                                                        
INPUT_ALIAS, expr))
-                                        .map(
-                                                resolvedExpression ->
-                                                        
resolvedExpression.asSerializableString(
-                                                                sqlFactory))
-                                        .collect(Collectors.joining(", "))));
-
+                                INPUT_ALIAS));
+
+        if (!order.isEmpty()) {
+            s.append(" ORDER BY ");
+            s.append(
+                    order.stream()
+                            .map(
+                                    expr ->
+                                            
OperationExpressionsUtils.scopeReferencesWithAlias(
+                                                    INPUT_ALIAS, expr))
+                            .map(
+                                    resolvedExpression ->
+                                            
resolvedExpression.asSerializableString(sqlFactory))
+                            .collect(Collectors.joining(", ")));

Review Comment:
   Nit: what do you think extracting this logic into a method?



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

Reply via email to