YangShaw commented on code in PR #14397:
URL: https://github.com/apache/doris/pull/14397#discussion_r1095317228


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Window.java:
##########
@@ -0,0 +1,97 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.algebra;
+
+import org.apache.doris.analysis.AnalyticWindow;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.glue.translator.ExpressionTranslator;
+import org.apache.doris.nereids.glue.translator.PlanTranslatorContext;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.WindowFrame;
+import 
org.apache.doris.nereids.trees.expressions.functions.window.FrameBoundType;
+import 
org.apache.doris.nereids.trees.expressions.functions.window.FrameBoundary;
+import 
org.apache.doris.nereids.trees.expressions.functions.window.FrameUnitsType;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * interface for LogicalWindow and PhysicalWindow
+ */
+public interface Window {
+
+    List<NamedExpression> getOutputExpressions();
+
+    default List<Expression> 
extractExpressionsFromWindow(List<NamedExpression> windowExpressions) {
+        return windowExpressions.stream().map(expression -> 
expression.child(0))
+            .map(org.apache.doris.nereids.trees.expressions.Window.class::cast)
+            .flatMap(window -> window.getExpressionsInWindowSpec().stream())
+            .collect(Collectors.toList());
+    }
+
+    /**
+     * translate WindowFrame to AnalyticWindow
+     */
+    default AnalyticWindow translateWindowFrame(WindowFrame windowFrame, 
PlanTranslatorContext context) {
+        FrameUnitsType frameUnits = windowFrame.getFrameUnits();
+        FrameBoundary leftBoundary = windowFrame.getLeftBoundary();
+        FrameBoundary rightBoundary = windowFrame.getRightBoundary();
+
+        AnalyticWindow.Type type = frameUnits == FrameUnitsType.ROWS
+                ? AnalyticWindow.Type.ROWS : AnalyticWindow.Type.RANGE;
+
+        AnalyticWindow.Boundary left = withFrameBoundary(leftBoundary, 
context);
+        AnalyticWindow.Boundary right = withFrameBoundary(rightBoundary, 
context);
+
+        return new AnalyticWindow(type, left, right);
+    }

Review Comment:
   due to that AnalyticWindow doesn't extend Expr, it is hard to use 
visitWindowFrame() in ExpressionTranslator. And in consider of that the code 
related of translate windowFrame is long, I put these functions in Window 
interface rather than PhysicalPlanTranslator. 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to