anishshri-db commented on code in PR #44961:
URL: https://github.com/apache/spark/pull/44961#discussion_r1483680705
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/state/RocksDBSuite.scala:
##########
@@ -845,6 +859,96 @@ class RocksDBSuite extends
AlsoTestWithChangelogCheckpointingEnabled with Shared
}
}
+ testWithChangelogCheckpointingEnabled("ensure merge operation is not
supported" +
+ " with changelog checkpoint if column families is not enabled") {
+ withTempDir { dir =>
+ val remoteDir = Utils.createTempDir().toString
+ val conf = dbConf.copy(minDeltasForSnapshot = 5, compactOnCommit = false)
+ new File(remoteDir).delete() // to make sure that the directory gets
created
+ withDB(remoteDir, conf = conf, useColumnFamilies = false) { db =>
+ db.load(0)
+ db.put("a", "1")
+ intercept[UnsupportedOperationException](
+ db.merge("a", "2")
+ )
+ }
+ }
+ }
+
+ testWithChangelogCheckpointingDisabled("ensure merge operation is supported"
+
+ " without changelog checkpoint if column families is not enabled") {
Review Comment:
So should we update the test to run with changelog checkpointing enabled and
disabled both ?
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/state/RocksDBStateStoreSuite.scala:
##########
@@ -189,12 +232,15 @@ class RocksDBStateStoreSuite extends
StateStoreSuiteBase[RocksDBStateStoreProvid
numColsPrefixKey: Int,
sqlConf: Option[SQLConf] = None,
conf: Configuration = new Configuration,
- useColumnFamilies: Boolean = false): RocksDBStateStoreProvider = {
+ useColumnFamilies: Boolean = false,
+ useMultipleValuesPerKey: Boolean = false): RocksDBStateStoreProvider = {
val provider = new RocksDBStateStoreProvider()
provider.init(
storeId, keySchema, valueSchema, numColsPrefixKey = numColsPrefixKey,
useColumnFamilies,
- new StateStoreConf(sqlConf.getOrElse(SQLConf.get)), conf)
+ new StateStoreConf(sqlConf.getOrElse(SQLConf.get)), conf,
+ useMultipleValuesPerKey
Review Comment:
Nit: indent ?
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/StateStoreChangelog.scala:
##########
@@ -155,6 +161,11 @@ class StateStoreChangelogWriterV1(
operationName = "Delete", entity = "changelog writer v1")
}
+ override def merge(key: Array[Byte], value: Array[Byte], colFamilyName:
String): Unit = {
+ throw new UnsupportedOperationException("Operation not supported with
state " +
Review Comment:
Do we need to integrate with NERF here ?
##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithListStateSuite.scala:
##########
@@ -0,0 +1,215 @@
+/*
+ * 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.streaming
+
+import org.apache.spark.SparkException
+import org.apache.spark.sql.execution.streaming.MemoryStream
+import
org.apache.spark.sql.execution.streaming.state.{AlsoTestWithChangelogCheckpointingEnabled,
RocksDBStateStoreProvider}
+import org.apache.spark.sql.internal.SQLConf
+
+case class InputRow(key: String, action: String, value: String)
+
+class TestListStateProcessor
+ extends StatefulProcessor[String, InputRow, (String, String)] {
+
+ @transient var _processorHandle: StatefulProcessorHandle = _
+ @transient var _listState: ListState[String] = _
+
+ override def init(handle: StatefulProcessorHandle, outputMode: OutputMode):
Unit = {
+ _processorHandle = handle
+ _listState = handle.getListState("testListState")
+ }
+
+ override def handleInputRows(key: String,
+ rows: Iterator[InputRow],
+ timerValues: TimerValues): Iterator[(String, String)] = {
+
+ var output = List[(String, String)]()
+
+ for (row <- rows) {
+ if (row.action == "emit") {
+ output = (key, row.value) :: output
+ } else if (row.action == "emitAllInState") {
+ _listState.get().foreach(v => {
+ output = (key, v) :: output
+ })
+ _listState.remove()
+ } else if (row.action == "append") {
+ _listState.appendValue(row.value)
+ } else if (row.action == "appendAll") {
+ _listState.appendList(row.value.split(","))
+ } else if (row.action == "put") {
+ _listState.put(row.value.split(","))
+ } else if (row.action == "remove") {
+ _listState.remove()
+ } else if (row.action == "tryAppendingNull") {
+ _listState.appendValue(null)
+ } else if (row.action == "tryAppendingNullValueInList") {
+ _listState.appendList(Array(null))
+ } else if (row.action == "tryAppendingNullList") {
+ _listState.appendList(null)
+ } else if (row.action == "tryPutNullList") {
+ _listState.put(null)
+ } else if (row.action == "tryPuttingNullInList") {
+ _listState.put(Array(null))
+ }
+ }
+
+ output.iterator
+ }
+
+
+ override def close(): Unit = {
+ }
+}
+
+class TransformWithListStateSuite extends StreamTest
+ with AlsoTestWithChangelogCheckpointingEnabled {
+ import testImplicits._
+
+ test("test appending null value in list state throw exception") {
+ withSQLConf(SQLConf.STATE_STORE_PROVIDER_CLASS.key ->
+ classOf[RocksDBStateStoreProvider].getName) {
+
+ val inputData = MemoryStream[InputRow]
+ val result = inputData.toDS()
+ .groupByKey(x => x.key)
+ .transformWithState(new TestListStateProcessor(),
+ TimeoutMode.NoTimeouts(),
+ OutputMode.Update())
+
+ testStream(result, OutputMode.Update()) (
+ AddData(inputData, InputRow("k1", "tryAppendingNull", "")),
+ ExpectFailure[SparkException](e => {
+ assert(e.getMessage.contains("CANNOT_WRITE_STATE_STORE.NULL_VALUE"))
+ })
+ )
+ }
+ }
+
+ test("test putting null value in list state throw exception") {
+ withSQLConf(SQLConf.STATE_STORE_PROVIDER_CLASS.key ->
+ classOf[RocksDBStateStoreProvider].getName) {
+
+ val inputData = MemoryStream[InputRow]
+ val result = inputData.toDS()
+ .groupByKey(x => x.key)
+ .transformWithState(new TestListStateProcessor(),
+ TimeoutMode.NoTimeouts(),
+ OutputMode.Update())
+
+ testStream(result, OutputMode.Update())(
+ AddData(inputData, InputRow("k1", "tryPuttingNullInList", "")),
+ ExpectFailure[SparkException](e => {
+ assert(e.getMessage.contains("CANNOT_WRITE_STATE_STORE.NULL_VALUE"))
+ })
+ )
+ }
+ }
+
+ test("test putting null list in list state throw exception") {
+ withSQLConf(SQLConf.STATE_STORE_PROVIDER_CLASS.key ->
+ classOf[RocksDBStateStoreProvider].getName) {
+
+ val inputData = MemoryStream[InputRow]
+ val result = inputData.toDS()
+ .groupByKey(x => x.key)
+ .transformWithState(new TestListStateProcessor(),
+ TimeoutMode.NoTimeouts(),
+ OutputMode.Update())
+
+ testStream(result, OutputMode.Update())(
+ AddData(inputData, InputRow("k1", "tryPutNullList", "")),
+ ExpectFailure[SparkException](e => {
+ assert(e.getMessage.contains("CANNOT_WRITE_STATE_STORE.NULL_VALUE"))
+ })
+ )
+ }
+ }
+
+ test("test appending null list in list state throw exception") {
+ withSQLConf(SQLConf.STATE_STORE_PROVIDER_CLASS.key ->
+ classOf[RocksDBStateStoreProvider].getName) {
+
+ val inputData = MemoryStream[InputRow]
+ val result = inputData.toDS()
+ .groupByKey(x => x.key)
+ .transformWithState(new TestListStateProcessor(),
+ TimeoutMode.NoTimeouts(),
+ OutputMode.Update())
+
+ testStream(result, OutputMode.Update())(
+ AddData(inputData, InputRow("k1", "tryAppendingNullList", "")),
+ ExpectFailure[SparkException](e => {
+ assert(e.getMessage.contains("CANNOT_WRITE_STATE_STORE.NULL_VALUE"))
+ })
+ )
+ }
+ }
+
+ test("test list state correctness") {
Review Comment:
Do we add this somewhere ?
--
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]