gaborgsomogyi 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_r269069574
##########
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:
Thanks for explaining.
----------------------------------------------------------------
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]