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



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/StreamingSessionWindowStateManager.scala
##########
@@ -0,0 +1,370 @@
+/*
+ * 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.streaming.state
+
+import scala.collection.mutable.ArrayBuffer
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Attribute, Literal, 
UnsafeProjection, UnsafeRow}
+import 
org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
+import org.apache.spark.sql.types.{StructType, TimestampType}
+import org.apache.spark.util.NextIterator
+
+sealed trait StreamingSessionWindowStateManager extends Serializable {
+  /**
+   * Returns the schema for key of the state.
+   */
+  def getStateKeySchema: StructType
+
+  /**
+   * Returns the schema for value of the state.
+   */
+  def getStateValueSchema: StructType
+
+  /**
+   * Returns the number of columns for `prefix key` in key schema.
+   */
+  def getNumColsForPrefixKey: Int
+
+  /**
+   * Extracts the key without session window from the row.
+   * This can be used to group session windows by key.
+   */
+  def extractKeyWithoutSession(value: UnsafeRow): UnsafeRow
+
+  /**
+   * Check whether the given value is a new session, or the session has been
+   * updated.
+   * This can be used to control the output in UPDATE mode.
+   */
+  def newOrModified(store: ReadStateStore, value: UnsafeRow): Boolean
+
+  /**
+   * Returns all sessions for the key.
+   *
+   * @param key The key without session, which can be retrieved from
+   *            {@code extractKeyWithoutSession}.
+   */
+  def getSessions(store: ReadStateStore, key: UnsafeRow): Iterator[UnsafeRow]
+
+  /**
+   * Replaces all sessions for the key to given one.

Review comment:
       The return value is just same as sessions.length so not that useful.
   
   I think we'd want to measure the number of rows on "added/updated" vs 
"deleted" and we have both cases on executing method, which requires another 
sort of return type. Let's keep this as Unit and change it in session window 
implementation PR.




-- 
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: reviews-unsubscr...@spark.apache.org

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



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

Reply via email to