sahnib commented on code in PR #44961:
URL: https://github.com/apache/spark/pull/44961#discussion_r1492922006


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBStateStoreProvider.scala:
##########
@@ -75,6 +76,61 @@ private[sql] class RocksDBStateStoreProvider
       value
     }
 
+    /**
+     * Provides an iterator containing all values of a non-null key.
+     *
+     * Inside RocksDB, the values are merged together and stored as a byte 
Array.
+     * This operation relies on state store value encoder to be able to split 
the
+     * single array into multiple values.
+     *
+     * Also see [[MultiValuedStateEncoder]] which supports encoding/decoding 
multiple
+     * values per key.
+     */
+    override def valuesIterator(key: UnsafeRow, colFamilyName: String): 
Iterator[UnsafeRow] = {
+      verify(key != null, "Key cannot be null")
+
+      val kvEncoder = keyValueEncoderMap.get(colFamilyName)
+      val valueEncoder = kvEncoder._2
+      val keyEncoder = kvEncoder._1
+
+      verify(valueEncoder.supportsMultipleValuesPerKey, "valuesIterator 
requires a encoder " +
+      "that supports multiple values for a single key.")
+      val encodedKey = rocksDB.get(keyEncoder.encodeKey(key), colFamilyName)
+      val valueIterator = valueEncoder.decodeValues(encodedKey)
+
+      if (valueIterator.nonEmpty) {
+        new Iterator[UnsafeRow] {
+          override def hasNext: Boolean = {
+            valueIterator.hasNext
+          }
+
+          override def next(): UnsafeRow = {
+            val value = valueIterator.next()
+            if (value != null) {
+              StateStoreProvider.validateStateRowFormat(

Review Comment:
   Removed the wrapper iterator, we don't need it anymore.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBStateStoreProvider.scala:
##########
@@ -75,6 +76,61 @@ private[sql] class RocksDBStateStoreProvider
       value
     }
 
+    /**
+     * Provides an iterator containing all values of a non-null key.
+     *
+     * Inside RocksDB, the values are merged together and stored as a byte 
Array.
+     * This operation relies on state store value encoder to be able to split 
the
+     * single array into multiple values.
+     *
+     * Also see [[MultiValuedStateEncoder]] which supports encoding/decoding 
multiple
+     * values per key.
+     */
+    override def valuesIterator(key: UnsafeRow, colFamilyName: String): 
Iterator[UnsafeRow] = {
+      verify(key != null, "Key cannot be null")
+
+      val kvEncoder = keyValueEncoderMap.get(colFamilyName)
+      val valueEncoder = kvEncoder._2
+      val keyEncoder = kvEncoder._1
+
+      verify(valueEncoder.supportsMultipleValuesPerKey, "valuesIterator 
requires a encoder " +
+      "that supports multiple values for a single key.")
+      val encodedKey = rocksDB.get(keyEncoder.encodeKey(key), colFamilyName)
+      val valueIterator = valueEncoder.decodeValues(encodedKey)
+
+      if (valueIterator.nonEmpty) {
+        new Iterator[UnsafeRow] {
+          override def hasNext: Boolean = {
+            valueIterator.hasNext
+          }
+
+          override def next(): UnsafeRow = {
+            val value = valueIterator.next()
+            if (value != null) {
+              StateStoreProvider.validateStateRowFormat(

Review Comment:
   Removed the wrapper iterator, we don't need it anymore. Thanks for pointing 
this out. 



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