sahnib commented on code in PR #44961:
URL: https://github.com/apache/spark/pull/44961#discussion_r1489763397
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala:
##########
@@ -316,6 +321,38 @@ class RocksDB(
}
}
+ /**
+ * Merge the given value for the given key. This is equivalent to the Atomic
+ * Read-Modify-Write operation in RocksDB, known as the "Merge" operation.
The
+ * modification is appending the provided value to current list of values for
+ * the given key.
+ *
+ * @note This operation requires that the encoder used can decode multiple
values for
+ * a key from the values byte array.
+ *
+ * @note This update is not committed to disk until commit() is called.
+ */
+ def merge(
+ key: Array[Byte],
+ value: Array[Byte],
+ colFamilyName: String = StateStore.DEFAULT_COL_FAMILY_NAME): Unit = {
+ if (!useColumnFamilies) {
+ throw new RuntimeException("Merge operation uses changelog checkpointing
v2 which" +
+ " requires column families to be enabled.")
+ }
+ verifyColFamilyExists(colFamilyName)
+
+ if (conf.trackTotalNumberOfRows) {
+ val oldValue = db.get(colFamilyNameToHandleMap(colFamilyName),
readOptions, key)
+ if (oldValue == null) {
+ numKeysOnWritingVersion += 1
+ }
+ }
+ db.merge(colFamilyNameToHandleMap(colFamilyName), writeOptions, key, value)
Review Comment:
Yes, this works same as put with one value. See
https://github.com/facebook/rocksdb/blob/f405e55cfa1e8a722b23223407e0d3a600cb0855/utilities/merge_operators/string_append/stringappend.cc#L48-L50
--
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]