Java Code Examples for org.apache.kafka.connect.data.Schema#equals()

The following examples show how to use org.apache.kafka.connect.data.Schema#equals() . 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: SchemaUtils.java    From streamx with Apache License 2.0 6 votes vote down vote up
public static boolean shouldChangeSchema(Schema valueSchema, Schema currentSchema, Compatibility compatibility) {
  if (currentSchema == null) {
    return true;
  }
  if ((valueSchema.version() == null || currentSchema.version() == null) && compatibility != Compatibility.NONE) {
    throw new SchemaProjectorException("Schema version required for " + compatibility.toString() + " compatibility");
  }
  switch (compatibility) {
    case BACKWARD:
    case FULL:
      return (valueSchema.version()).compareTo(currentSchema.version()) > 0;
    case FORWARD:
      return (valueSchema.version()).compareTo(currentSchema.version()) < 0;
    default:
      return !valueSchema.equals(currentSchema);
  }
}
 
Example 2
Source File: SchemaUtils.java    From streamx with Apache License 2.0 6 votes vote down vote up
public static SinkRecord project(SinkRecord record, Schema currentSchema, Compatibility compatibility) {
  switch (compatibility) {
    case BACKWARD:
    case FULL:
    case FORWARD:
      Schema sourceSchema = record.valueSchema();
      Object value = record.value();
      if (sourceSchema == currentSchema || sourceSchema.equals(currentSchema)) {
        return record;
      }
      Object projected = SchemaProjector.project(sourceSchema, value, currentSchema);
      return new SinkRecord(record.topic(), record.kafkaPartition(), record.keySchema(),
                            record.key(), currentSchema, projected, record.kafkaOffset());
    default:
      return record;
  }
}