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

The following examples show how to use org.apache.kafka.connect.data.Schema#name() . 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: HeaderToFieldConfig.java    From kafka-connect-transform-common with Apache License 2.0 6 votes vote down vote up
public static String toString(Schema schema, String schemaNameOverride) {
  StringBuilder builder = new StringBuilder();
  builder.append(schema.type());
  if (!Strings.isNullOrEmpty(schema.name())) {
    String schemaName = Strings.isNullOrEmpty(schemaNameOverride) ? schema.name() : schemaNameOverride;
    builder.append("(");
    builder.append(schemaName);

    if (Decimal.LOGICAL_NAME.equals(schema.name())) {
      builder.append("[scale=");
      builder.append(schema.parameters().get(Decimal.SCALE_FIELD));
      builder.append("]");
    }

    builder.append(")");
  }
  return builder.toString();
}
 
Example 2
Source File: SchemaSerializationModule.java    From connect-utils with Apache License 2.0 6 votes vote down vote up
Storage(Schema schema) {
  this.name = schema.name();
  this.doc = schema.doc();
  this.type = schema.type();
  this.defaultValue = schema.defaultValue();
  this.version = schema.version();
  this.parameters = schema.parameters();
  this.isOptional = schema.isOptional();

  if (Schema.Type.MAP == this.type) {
    this.keySchema = schema.keySchema();
    this.valueSchema = schema.valueSchema();
  } else if (Schema.Type.ARRAY == this.type) {
    this.keySchema = null;
    this.valueSchema = schema.valueSchema();
  } else if (Schema.Type.STRUCT == this.type) {
    this.fieldSchemas = new LinkedHashMap<>();
    for (Field field : schema.fields()) {
      this.fieldSchemas.put(field.name(), field.schema());
    }
  }
}
 
Example 3
Source File: AvroData.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
private static Object toAvroLogical(Schema schema, Object value) {
    if (schema != null && schema.name() != null) {
        LogicalTypeConverter logicalConverter = TO_AVRO_LOGICAL_CONVERTERS.get(schema.name());
        if (logicalConverter != null && value != null) {
            return logicalConverter.convert(schema, value);
        }
    }
    return value;
}
 
Example 4
Source File: AvroData.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
private static Object toConnectLogical(Schema schema, Object value) {
    if (schema != null && schema.name() != null) {
        LogicalTypeConverter logicalConverter = TO_CONNECT_LOGICAL_CONVERTERS.get(schema.name());
        if (logicalConverter != null && value != null) {
            return logicalConverter.convert(schema, value);
        }
    }
    return value;
}
 
Example 5
Source File: AvroData.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
private String unionMemberFieldName(Schema schema) {
    if (schema.type() == Schema.Type.STRUCT || isEnumSchema(schema)) {
        if (enhancedSchemaSupport) {
            return schema.name();
        } else {
            return splitName(schema.name())[1];
        }
    }
    return CONNECT_TYPES_TO_AVRO_TYPES.get(schema.type()).getName();
}
 
Example 6
Source File: AvroData.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
public static Schema nonOptional(Schema schema) {
    return new ConnectSchema(schema.type(), false, schema.defaultValue(), schema.name(),
                             schema.version(), schema.doc(),
                             schema.parameters(),
                             fields(schema),
                             keySchema(schema),
                             valueSchema(schema));
}
 
Example 7
Source File: AvroData.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
private static boolean crossReferenceSchemaNames(final Schema schema,
                                                 final org.apache.avro.Schema avroSchema) {
    return Objects.equals(avroSchema.getFullName(), schema.name())
           || Objects.equals(avroSchema.getType().getName(), schema.type().getName())
           || (schema.name() == null && avroSchema.getFullName().equals(DEFAULT_SCHEMA_FULL_NAME));
}
 
Example 8
Source File: AvroData.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
private static boolean isEnumSchema(Schema schema) {
    return schema.type() == Schema.Type.STRING
           && schema.name() != null
           && schema.name().equals(AVRO_TYPE_ENUM);
}
 
Example 9
Source File: AvroJsonSchemafulRecordConverter.java    From mongo-kafka with Apache License 2.0 4 votes vote down vote up
private boolean isSupportedLogicalType(final Schema schema) {
  if (schema.name() == null) {
    return false;
  }
  return LOGICAL_TYPE_NAMES.contains(schema.name());
}
 
Example 10
Source File: NormalizeSchema.java    From kafka-connect-transform-common with Apache License 2.0 4 votes vote down vote up
public static SchemaKey of(Schema schema) {
  return new SchemaKey(schema.name(), schema.type());
}
 
Example 11
Source File: ConversionHandler.java    From kafka-connect-transform-common with Apache License 2.0 4 votes vote down vote up
public static SchemaKey of(Schema schema) {
  return new SchemaKey(schema.name(), schema.type());
}
 
Example 12
Source File: ParserKey.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
ParserKey(Schema schema) {
  this(schema.type(), schema.name());
}
 
Example 13
Source File: SchemaKey.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
private SchemaKey(final Schema schema) {
  this.name = schema.name();
  this.version = schema.version();
  this.type = schema.type();
}