xuanyuanking commented on a change in pull request #33038:
URL: https://github.com/apache/spark/pull/33038#discussion_r661517930



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/HDFSBackedStateStoreMap.scala
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.sql.catalyst.expressions.{BoundReference, 
UnsafeProjection, UnsafeRow}
+import org.apache.spark.sql.types.{StructField, StructType}
+
+trait HDFSBackedStateStoreMap {
+  def size(): Int
+  def get(key: UnsafeRow): UnsafeRow
+  def put(key: UnsafeRow, value: UnsafeRow): UnsafeRow
+  def putAll(map: HDFSBackedStateStoreMap): Unit
+  def remove(key: UnsafeRow): UnsafeRow
+  def iterator(): Iterator[UnsafeRowPair]
+  def prefixScan(prefixKey: UnsafeRow): Iterator[UnsafeRowPair]
+  def clear(): Unit
+}
+
+object HDFSBackedStateStoreMap {
+  def create(keySchema: StructType, numColsPrefixKey: Int): 
HDFSBackedStateStoreMap = {
+    if (numColsPrefixKey > 0) {
+      new PrefixScannableHDFSBackedStateStoreMap(keySchema, numColsPrefixKey)
+    } else {
+      new NoPrefixHDFSBackedStateStoreMap()
+    }
+  }
+}
+
+class NoPrefixHDFSBackedStateStoreMap extends HDFSBackedStateStoreMap {
+  // ConcurrentHashMap is used because it generates fail-safe iterators on 
filtering
+  // - The iterator is weakly consistent with the map, i.e., iterator's data 
reflect the values in
+  //   the map when the iterator was created
+  // - Any updates to the map while iterating through the filtered iterator 
does not throw
+  //   java.util.ConcurrentModificationException
+  private val map = new java.util.concurrent.ConcurrentHashMap[UnsafeRow, 
UnsafeRow]()

Review comment:
       nit: maybe we can still keep the type definition as 
https://github.com/apache/spark/pull/33038/files#diff-36ad1664106a22a3f6ffabd4e3ed812201e8055dc3b5f6b116dbeb8de72baac0L79,
 then we can avoid copying the long comment in here and L88.

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/HDFSBackedStateStoreProvider.scala
##########
@@ -252,6 +238,12 @@ private[state] class HDFSBackedStateStoreProvider extends 
StateStoreProvider wit
     this.storeConf = storeConf
     this.hadoopConf = hadoopConf
     this.numberOfVersionsToRetainInMemory = 
storeConf.maxVersionsToRetainInMemory
+
+    require((keySchema.length == 0 && numColsPrefixKey == 0) ||

Review comment:
       Do we accept passing an empty keySchema? Or it's just want to make the 
assertion safe?




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