// Each schema in the writer union can be decoded with the reader:
return SchemaCompatibilityType.COMPATIBLE;
}
default: {
throw new InternalKijiError("Unknown schema type: " + reader.getType());
}
}
} else {
// Reader and writer have different schema types:
// Handle the corner case where writer is a union of a singleton branch: { X } === X
if ((writer.getType() == Schema.Type.UNION)
&& writer.getTypes().size() == 1) {
return getCompatibility(reader, writer.getTypes().get(0));
}
switch (reader.getType()) {
case NULL: return SchemaCompatibilityType.INCOMPATIBLE;
case BOOLEAN: return SchemaCompatibilityType.INCOMPATIBLE;
case INT: return SchemaCompatibilityType.INCOMPATIBLE;
case LONG: {
return (writer.getType() == Type.INT)
? SchemaCompatibilityType.COMPATIBLE
: SchemaCompatibilityType.INCOMPATIBLE;
}
case FLOAT: {
return ((writer.getType() == Type.INT)
|| (writer.getType() == Type.LONG))
? SchemaCompatibilityType.COMPATIBLE
: SchemaCompatibilityType.INCOMPATIBLE;
}
case DOUBLE: {
return ((writer.getType() == Type.INT)
|| (writer.getType() == Type.LONG)
|| (writer.getType() == Type.FLOAT))
? SchemaCompatibilityType.COMPATIBLE
: SchemaCompatibilityType.INCOMPATIBLE;
}
case BYTES: return SchemaCompatibilityType.INCOMPATIBLE;
case STRING: return SchemaCompatibilityType.INCOMPATIBLE;
case ARRAY: return SchemaCompatibilityType.INCOMPATIBLE;
case MAP: return SchemaCompatibilityType.INCOMPATIBLE;
case FIXED: return SchemaCompatibilityType.INCOMPATIBLE;
case ENUM: return SchemaCompatibilityType.INCOMPATIBLE;
case RECORD: return SchemaCompatibilityType.INCOMPATIBLE;
case UNION: {
for (final Schema readerBranch : reader.getTypes()) {
if (getCompatibility(readerBranch, writer) == SchemaCompatibilityType.COMPATIBLE) {
return SchemaCompatibilityType.COMPATIBLE;
}
}
// No branch in the reader union has been found compatible with the writer schema:
return SchemaCompatibilityType.INCOMPATIBLE;
}
default: {
throw new InternalKijiError("Unknown schema type: " + reader.getType());
}
}
}
}