HeartSaVioR commented on a change in pull request #24173: [SPARK-27237][SS]
Introduce State schema validation among query restart
URL: https://github.com/apache/spark/pull/24173#discussion_r268174623
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/state/StateStoreSuite.scala
##########
@@ -198,6 +198,71 @@ class StateStoreSuite extends
StateStoreSuiteBase[HDFSBackedStateStoreProvider]
assert(loadedMaps.size() === 0)
}
+ testQuietly("changing schema of state when restarting query") {
+ val opId = Random.nextInt
+ val partitionId = 0
+ val dir = newDir()
+ val queryId = UUID.randomUUID()
+
+ val originKeySchema = new StructType()
+ .add(StructField("key1", IntegerType))
+ .add(StructField("key2", StringType))
+
+ val originValueSchema = new StructType()
+ .add(StructField("value1", IntegerType))
+ .add(StructField("value2", StringType))
+
+ val hadoopConf: Configuration = new Configuration()
+
+ def initializeStoreProvider(newKeySchema: StructType, newValueSchema:
StructType): Unit = {
+ // in fact, Spark doesn't support online state schema change, so need to
check
+ // schema only once for each running of JVM
+ val providerId = StateStoreProviderId(
+ StateStoreId(dir, opId, partitionId), queryId)
+ StateStore.unload(providerId)
+ StateStore.get(providerId, newKeySchema, newValueSchema, None, 0,
+ new StateStoreConf(new SQLConf), hadoopConf)
+ // we don't do anything with retrieved state store: we just want to
initialize provider
+ }
+
+ def verifyException(newKeySchema: StructType, newValueSchema: StructType):
Unit = {
+ val e = intercept[IllegalStateException] {
+ initializeStoreProvider(newKeySchema, newValueSchema)
+ }
+
+ e.getMessage.contains("Provided schema doesn't match to the schema for
existing state!")
Review comment:
Same here.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]