org.apache.avro.SchemaCompatibility Java Examples

The following examples show how to use org.apache.avro.SchemaCompatibility. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AvroSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves writer/reader schema compatibly.
 *
 * <p>Checks whenever a new version of a schema (reader) can read values serialized with the old schema (writer).
 * If the schemas are compatible according to {@code Avro} schema resolution rules
 * (@see <a href="https://avro.apache.org/docs/current/spec.html#Schema+Resolution">Schema Resolution</a>).
 */
@VisibleForTesting
static <T> TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(
	Schema writerSchema,
	Schema readerSchema) {

	if (Objects.equals(writerSchema, readerSchema)) {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}

	final SchemaPairCompatibility compatibility =
		SchemaCompatibility.checkReaderWriterCompatibility(readerSchema, writerSchema);

	return avroCompatibilityToFlinkCompatibility(compatibility);
}
 
Example #2
Source File: AvroSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves writer/reader schema compatibly.
 *
 * <p>Checks whenever a new version of a schema (reader) can read values serialized with the old schema (writer).
 * If the schemas are compatible according to {@code Avro} schema resolution rules
 * (@see <a href="https://avro.apache.org/docs/current/spec.html#Schema+Resolution">Schema Resolution</a>).
 */
@VisibleForTesting
static <T> TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(
	Schema writerSchema,
	Schema readerSchema) {

	if (Objects.equals(writerSchema, readerSchema)) {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}

	final SchemaPairCompatibility compatibility =
		SchemaCompatibility.checkReaderWriterCompatibility(readerSchema, writerSchema);

	return avroCompatibilityToFlinkCompatibility(compatibility);
}
 
Example #3
Source File: AvroSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves writer/reader schema compatibly.
 *
 * <p>Checks whenever a new version of a schema (reader) can read values serialized with the old schema (writer).
 * If the schemas are compatible according to {@code Avro} schema resolution rules
 * (@see <a href="https://avro.apache.org/docs/current/spec.html#Schema+Resolution">Schema Resolution</a>).
 */
@VisibleForTesting
static <T> TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(
	Schema writerSchema,
	Schema readerSchema) {

	if (Objects.equals(writerSchema, readerSchema)) {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}

	final SchemaPairCompatibility compatibility =
		SchemaCompatibility.checkReaderWriterCompatibility(readerSchema, writerSchema);

	return avroCompatibilityToFlinkCompatibility(compatibility);
}
 
Example #4
Source File: AvroUtils.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that the provided reader schema can be used to decode avro data written with the
 * provided writer schema.
 * @param readerSchema schema to check.
 * @param writerSchema schema to check.
 * @param ignoreNamespace whether name and namespace should be ignored in validation
 * @return true if validation passes
 */
public static boolean checkReaderWriterCompatibility(Schema readerSchema, Schema writerSchema, boolean ignoreNamespace) {
  if (ignoreNamespace) {
    List<Schema.Field> fields = deepCopySchemaFields(readerSchema);
    readerSchema = Schema.createRecord(writerSchema.getName(), writerSchema.getDoc(), writerSchema.getNamespace(),
        readerSchema.isError());
    readerSchema.setFields(fields);
  }

  return SchemaCompatibility.checkReaderWriterCompatibility(readerSchema, writerSchema).getType().equals(SchemaCompatibility.SchemaCompatibilityType.COMPATIBLE);
}
 
Example #5
Source File: MRCompactorAvroKeyDedupJobRunner.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
/**
 * keySchema is valid if a record with newestSchema can be converted to a record with keySchema.
 */
public static boolean isKeySchemaValid(Schema keySchema, Schema topicSchema) {
  return SchemaCompatibility.checkReaderWriterCompatibility(keySchema, topicSchema).getType()
      .equals(SchemaCompatibilityType.COMPATIBLE);
}