Package org.apache.kafka.connect.data
Class ConnectSchema
- java.lang.Object
-
- org.apache.kafka.connect.data.ConnectSchema
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.kafka.connect.data.Schema
Schema.Type
-
-
Field Summary
-
Fields inherited from interface org.apache.kafka.connect.data.Schema
BOOLEAN_SCHEMA, BYTES_SCHEMA, FLOAT32_SCHEMA, FLOAT64_SCHEMA, INT16_SCHEMA, INT32_SCHEMA, INT64_SCHEMA, INT8_SCHEMA, OPTIONAL_BOOLEAN_SCHEMA, OPTIONAL_BYTES_SCHEMA, OPTIONAL_FLOAT32_SCHEMA, OPTIONAL_FLOAT64_SCHEMA, OPTIONAL_INT16_SCHEMA, OPTIONAL_INT32_SCHEMA, OPTIONAL_INT64_SCHEMA, OPTIONAL_INT8_SCHEMA, OPTIONAL_STRING_SCHEMA, STRING_SCHEMA
-
-
Constructor Summary
Constructors Constructor Description ConnectSchema(Schema.Type type)Construct a default schema for a primitive type.ConnectSchema(Schema.Type type, boolean optional, Object defaultValue, String name, Integer version, String doc)Construct a Schema for a primitive type, setting schema parameters, struct fields, and key and value schemas to null.ConnectSchema(Schema.Type type, boolean optional, Object defaultValue, String name, Integer version, String doc, Map<String,String> parameters, List<Field> fields, Schema keySchema, Schema valueSchema)Construct a Schema.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectdefaultValue()Stringdoc()booleanequals(Object o)Fieldfield(String fieldName)Get a field for this Schema by name.List<Field>fields()Get the list of fields for this Schema.inthashCode()booleanisOptional()SchemakeySchema()Get the key schema for this map schema.Stringname()Map<String,String>parameters()Get a map of schema parameters.ConnectSchemaschema()Return a concrete instance of theSchemastatic Schema.TypeschemaType(Class<?> klass)Get theSchema.Typeassociated with the given class.StringtoString()Schema.Typetype()voidvalidateValue(Object value)Validate that the value can be used for this schema, i.e.static voidvalidateValue(String name, Schema schema, Object value)static voidvalidateValue(Schema schema, Object value)Validate that the value can be used with the schema, i.e.SchemavalueSchema()Get the value schema for this map or array schema.Integerversion()Get the optional version of the schema.
-
-
-
Constructor Detail
-
ConnectSchema
public ConnectSchema(Schema.Type type, boolean optional, Object defaultValue, String name, Integer version, String doc, Map<String,String> parameters, List<Field> fields, Schema keySchema, Schema valueSchema)
Construct a Schema. Most users should not construct schemas manually, preferringSchemaBuilderinstead.
-
ConnectSchema
public ConnectSchema(Schema.Type type, boolean optional, Object defaultValue, String name, Integer version, String doc)
Construct a Schema for a primitive type, setting schema parameters, struct fields, and key and value schemas to null.
-
ConnectSchema
public ConnectSchema(Schema.Type type)
Construct a default schema for a primitive type. The schema is required, has no default value, name, version, or documentation.
-
-
Method Detail
-
type
public Schema.Type type()
-
isOptional
public boolean isOptional()
- Specified by:
isOptionalin interfaceSchema- Returns:
- true if this field is optional, false otherwise
-
defaultValue
public Object defaultValue()
- Specified by:
defaultValuein interfaceSchema- Returns:
- the default value for this schema
-
version
public Integer version()
Description copied from interface:SchemaGet the optional version of the schema. If a version is included, newer versions *must* be larger than older ones.
-
doc
public String doc()
-
parameters
public Map<String,String> parameters()
Description copied from interface:SchemaGet a map of schema parameters.- Specified by:
parametersin interfaceSchema- Returns:
- Map containing parameters for this schema, or null if there are no parameters
-
fields
public List<Field> fields()
Description copied from interface:SchemaGet the list of fields for this Schema. Throws a DataException if this schema is not a struct.
-
field
public Field field(String fieldName)
Description copied from interface:SchemaGet a field for this Schema by name. Throws a DataException if this schema is not a struct.
-
keySchema
public Schema keySchema()
Description copied from interface:SchemaGet the key schema for this map schema. Throws a DataException if this schema is not a map.
-
valueSchema
public Schema valueSchema()
Description copied from interface:SchemaGet the value schema for this map or array schema. Throws a DataException if this schema is not a map or array.- Specified by:
valueSchemain interfaceSchema- Returns:
- the value schema
-
validateValue
public static void validateValue(Schema schema, Object value)
Validate that the value can be used with the schema, i.e. that its type matches the schema type and nullability requirements. Throws a DataException if the value is invalid.- Parameters:
schema- Schema to testvalue- value to test
-
validateValue
public void validateValue(Object value)
Validate that the value can be used for this schema, i.e. that its type matches the schema type and optional requirements. Throws a DataException if the value is invalid.- Parameters:
value- the value to validate
-
schema
public ConnectSchema schema()
Description copied from interface:SchemaReturn a concrete instance of theSchema
-
schemaType
public static Schema.Type schemaType(Class<?> klass)
Get theSchema.Typeassociated with the given class.- Parameters:
klass- the Class to- Returns:
- the corresponding type, or null if there is no matching type
-
-