HeartSaVioR commented on a change in pull request #31570:
URL: https://github.com/apache/spark/pull/31570#discussion_r597938585



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/SessionWindowExec.scala
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.spark.sql.execution
+
+import scala.collection.mutable
+
+import org.apache.spark.rdd.RDD
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions._
+import 
org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
+import org.apache.spark.sql.catalyst.plans.physical.{ClusteredDistribution, 
Distribution, Partitioning}
+
+/**
+ * Used for calculating the session window start and end for each row, so this 
plan requires
+ * child distributed by sessionSpec and sorted by time column in each part. 
The value for
+ * window start is time value of the first row in this window, the value for 
window end is
+ * time value of the last row plus the windowGap.
+ *
+ * @param windowExpressions session window expression for the exec node.
+ * @param sessionSpec the partition key of this session window, it is the rest 
column of
+ *                    groupingExpr in parent aggregate node.
+ * @param windowGap window gap in micro second.
+ * @param child child plan for this node.
+ */
+case class SessionWindowExec(
+    windowExpressions: NamedExpression,
+    timeColumn: Expression,
+    sessionSpec: Seq[Expression],
+    windowGap: Long,
+    child: SparkPlan)
+  extends UnaryExecNode {
+
+  override def requiredChildDistribution: Seq[Distribution] = {
+    ClusteredDistribution(sessionSpec) :: Nil
+  }
+
+  override def requiredChildOrdering: Seq[Seq[SortOrder]] =
+    Seq(sessionSpec.map(SortOrder(_, Ascending)) :+ SortOrder(timeColumn, 
Ascending))
+
+  override def producedAttributes: AttributeSet = 
AttributeSet(windowExpressions.toAttribute)
+
+  override def output: Seq[Attribute] = child.output ++ 
Seq(windowExpressions.toAttribute)
+
+  override def outputPartitioning: Partitioning = child.outputPartitioning
+
+  override def outputOrdering: Seq[SortOrder] = child.outputOrdering
+
+  /**
+   * Produces the result of the query as an `RDD[InternalRow]`
+   *
+   * Overridden by concrete implementations of SparkPlan.
+   */
+  override protected def doExecute(): RDD[InternalRow] = {

Review comment:
       That is a one of concerns. Another concern is, to buffer row you'll need 
to "copy" the row, which makes entire input rows going through buffer being 
copied. (Doesn't matter how many rows are buffered at specific time.) I see 
there're multiple physical ops to buffer rows, which makes me wondering about 
the performance and resource usage.
   
   I'll need to check the performance is really on par with mine - I think the 
major complexity of mine was introduced on linked-list of state format. 
Migrating state format to the one in agreement here would reduce the complexity 
significantly, so after applying the change on mine, we could reevaluate both 
properly.




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



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

Reply via email to