@@ -529,7 +529,7 @@ public void validateSchema(Schema actualSchema, FailureCollector collector) {
529
529
}
530
530
531
531
@ VisibleForTesting
532
- static void validateSchema (Schema actualSchema , Schema configSchema , FailureCollector collector ) {
532
+ void validateSchema (Schema actualSchema , Schema configSchema , FailureCollector collector ) {
533
533
if (configSchema == null ) {
534
534
collector .addFailure ("Schema should not be null or empty." , null )
535
535
.withConfigProperty (SCHEMA );
@@ -550,14 +550,20 @@ static void validateSchema(Schema actualSchema, Schema configSchema, FailureColl
550
550
Schema expectedFieldSchema = field .getSchema ().isNullable () ?
551
551
field .getSchema ().getNonNullable () : field .getSchema ();
552
552
553
- if (actualFieldSchema .getType () != expectedFieldSchema .getType () ||
554
- actualFieldSchema .getLogicalType () != expectedFieldSchema .getLogicalType ()) {
555
- collector .addFailure (
556
- String .format ("Schema field '%s' has type '%s but found '%s'." ,
557
- field .getName (), expectedFieldSchema .getDisplayName (),
558
- actualFieldSchema .getDisplayName ()), null )
559
- .withOutputSchemaField (field .getName ());
560
- }
553
+ validateField (collector , field , actualFieldSchema , expectedFieldSchema );
554
+ }
555
+ }
556
+
557
+ protected void validateField (FailureCollector collector , Schema .Field field , Schema actualFieldSchema ,
558
+ Schema expectedFieldSchema ) {
559
+ if (actualFieldSchema .getType () != expectedFieldSchema .getType () ||
560
+ actualFieldSchema .getLogicalType () != expectedFieldSchema .getLogicalType ()) {
561
+ collector .addFailure (
562
+ String .format ("Schema field '%s' is expected to have type '%s but found '%s'." , field .getName (),
563
+ expectedFieldSchema .getDisplayName (), actualFieldSchema .getDisplayName ()),
564
+ String .format ("Change the data type of field %s to %s." , field .getName (),
565
+ actualFieldSchema .getDisplayName ()))
566
+ .withOutputSchemaField (field .getName ());
561
567
}
562
568
}
563
569
0 commit comments