xzj7019 commented on code in PR #38393:
URL: https://github.com/apache/doris/pull/38393#discussion_r1703522462


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java:
##########
@@ -171,61 +181,162 @@ public int hashCode() {
     }
 
     /**
-     * pushPartitionLimitThroughWindow is used to push the partitionLimit 
through the window
-     * and generate the partitionTopN. If the window can not meet the 
requirement,
-     * it will return null. So when we use this function, we need check the 
null in the outside.
+     * check and get valid window function and partition limit value
      */
-    public Optional<Plan> pushPartitionLimitThroughWindow(long partitionLimit, 
boolean hasGlobalLimit) {
+    public Pair<WindowExpression, Long> 
checkAndGetValidWindowFunc(LogicalFilter<?> filter, long partitionLimit) {
         if 
(!ConnectContext.get().getSessionVariable().isEnablePartitionTopN()) {
-            return Optional.empty();
+            return null;
         }
         // We have already done such optimization rule, so just ignore it.
-        if (child(0) instanceof LogicalPartitionTopN) {
-            return Optional.empty();
+        if (child(0) instanceof LogicalPartitionTopN
+                || (child(0) instanceof LogicalFilter
+                && child(0).child(0) != null
+                && child(0).child(0) instanceof LogicalPartitionTopN)) {
+            return null;
         }
 
         // Check the window function. There are some restrictions for window 
function:
-        // 1. The number of window function should be 1.
-        // 2. The window function should be one of the 'row_number()', 
'rank()', 'dense_rank()'.
-        // 3. The window frame should be 'UNBOUNDED' to 'CURRENT'.
-        // 4. The 'PARTITION' key and 'ORDER' key can not be empty at the same 
time.
-        if (windowExpressions.size() != 1) {
-            return Optional.empty();
-        }
-        NamedExpression windowExpr = windowExpressions.get(0);
-        if (windowExpr.children().size() != 1 || !(windowExpr.child(0) 
instanceof WindowExpression)) {
-            return Optional.empty();
-        }
+        // 1. The window function should be one of the 'row_number()', 
'rank()', 'dense_rank()'.
+        // 2. The window frame should be 'UNBOUNDED' to 'CURRENT'.
+        // 3. The 'PARTITION' key and 'ORDER' key can not be empty at the same 
time.
+        WindowExpression chosenWindowFunc = null;
+        long chosenPartitionLimit = Long.MAX_VALUE;
+        long chosenRowNumberPartitionLimit = Long.MAX_VALUE;
+        boolean hasRowNumber = false;
+        for (NamedExpression windowExpr : windowExpressions) {
+            WindowExpression windowFunc = (WindowExpression) 
windowExpr.child(0);

Review Comment:
   done



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to