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_r268174479
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingAggregationSuite.scala
##########
@@ -638,6 +638,53 @@ class StreamingAggregationSuite extends
StateStoreMetricsTest with Assertions {
)
}
+ testQuietlyWithAllStateVersions("changing schema of state when restarting
query") {
+ withTempDir { tempDir =>
+ val inputData = MemoryStream[Int]
+ val aggregated = inputData.toDF()
+ .selectExpr("value % 10 AS id", "value")
+ .groupBy($"id")
+ .agg(
+ sum("value").as("sum_value"),
+ avg("value").as("avg_value"),
+ max("value").as("max_value"))
+
+ testStream(aggregated, Update())(
+ StartStream(checkpointLocation = tempDir.getAbsolutePath),
+ AddData(inputData, 1, 11),
+ CheckLastBatch((1L, 12L, 6.0, 11)),
+ StopStream
+ )
+
+ StateStore.unloadAll()
+
+ val inputData2 = MemoryStream[Int]
+ val aggregated2 = inputData2.toDF()
+ .selectExpr("value % 10 AS id", "value")
+ .groupBy($"id")
+ .agg(
+ sum("value").as("sum_value"),
+ avg("value").as("avg_value"),
+ collect_list("value").as("values"))
+
+ // if we don't have verification phase on state schema, modified query
would throw NPE with
+ // stack trace which end users would not easily understand
+
+ inputData2.addData(1, 11)
+
+ testStream(aggregated2, Update())(
+ StartStream(checkpointLocation = tempDir.getAbsolutePath),
+ AddData(inputData2, 21),
+ ExpectFailure[SparkException] { e =>
+ val cause = e.getCause
+ assert(cause.isInstanceOf[IllegalStateException])
+ val msg = cause.getMessage
+ assert(msg.contains("Provided schema doesn't match to the schema for
existing state"))
Review comment:
I prefer to have log message which is self-describe. If we would like to
reduce a bit, how about `New schema for state doesn't match to current schema`?
----------------------------------------------------------------
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]