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_r269054217
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/StateSchemaCompatibilityChecker.scala
 ##########
 @@ -40,14 +40,19 @@ class StateSchemaCompatibilityChecker(
       logDebug(s"Schema file for provider $providerId exists. Comparing with 
provided schema.")
       val (storedKeySchema, storedValueSchema) = readSchemaFile()
 
-      def fieldToType: StructField => (DataType, Boolean) = f => (f.dataType, 
f.nullable)
-
-      def typesEq(schema1: StructType, schema2: StructType): Boolean = {
-        (schema1.length == schema2.length) && schema1.map(fieldToType) == 
schema2.map(fieldToType)
+      def fieldCompatible(fieldOld: StructField, fieldNew: StructField): 
Boolean = {
+        // compatibility for nullable
+        // - same: OK
+        // - non-nullable -> nullable: OK
+        // - nullable -> non-nullable: Not compatible
+        (fieldOld.dataType == fieldNew.dataType) &&
+          ((fieldOld.nullable == fieldNew.nullable) ||
+            (!fieldOld.nullable && fieldNew.nullable))
       }
 
-      def namesEq(schema1: StructType, schema2: StructType): Boolean = {
-        schema1.fieldNames.sameElements(schema2.fieldNames)
+      def schemaCompatible(schemaOld: StructType, schemaNew: StructType): 
Boolean = {
+        (schemaOld.length == schemaNew.length) &&
 
 Review comment:
   Undefined behavior, as state would be stored in file as unsafe byte array, 
and we just rely on new schema to parse it. It might be fine while reading if 
all column(s) is(are) dropped from rightmost, but the some of information in 
row (like numFields) would be incorrect so not sure which operation refers it 
and finally make query crash. If column(s) is(are) dropped from other spots, 
query would be crashed sooner.

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

Reply via email to