Package org.apache.kafka.connect.data
Class ConnectSchema
java.lang.Object
org.apache.kafka.connect.data.ConnectSchema
- All Implemented Interfaces:
Schema
public class ConnectSchema extends Object implements Schema
-
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
Modifier and Type Method Description Object
defaultValue()
String
doc()
boolean
equals(Object o)
Field
field(String fieldName)
Get a field for this Schema by name.List<Field>
fields()
Get the list of fields for this Schema.int
hashCode()
boolean
isOptional()
Schema
keySchema()
Get the key schema for this map schema.String
name()
Map<String,String>
parameters()
Get a map of schema parameters.ConnectSchema
schema()
Return a concrete instance of theSchema
static Schema.Type
schemaType(Class<?> klass)
Get theSchema.Type
associated with the given class.String
toString()
Schema.Type
type()
void
validateValue(Object value)
Validate that the value can be used for this schema, i.e.static void
validateValue(String name, Schema schema, Object value)
static void
validateValue(Schema schema, Object value)
Validate that the value can be used with the schema, i.e.Schema
valueSchema()
Get the value schema for this map or array schema.Integer
version()
Get the optional version of the schema.
-
Constructor Details
-
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, preferringSchemaBuilder
instead. -
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
Construct a default schema for a primitive type. The schema is required, has no default value, name, version, or documentation.
-
-
Method Details
-
type
-
isOptional
public boolean isOptional()- Specified by:
isOptional
in interfaceSchema
- Returns:
- true if this field is optional, false otherwise
-
defaultValue
- Specified by:
defaultValue
in interfaceSchema
- Returns:
- the default value for this schema
-
name
-
version
Description copied from interface:Schema
Get the optional version of the schema. If a version is included, newer versions *must* be larger than older ones. -
doc
-
parameters
Description copied from interface:Schema
Get a map of schema parameters.- Specified by:
parameters
in interfaceSchema
- Returns:
- Map containing parameters for this schema, or null if there are no parameters
-
fields
Description copied from interface:Schema
Get the list of fields for this Schema. Throws a DataException if this schema is not a struct. -
field
Description copied from interface:Schema
Get a field for this Schema by name. Throws a DataException if this schema is not a struct. -
keySchema
Description copied from interface:Schema
Get the key schema for this map schema. Throws a DataException if this schema is not a map. -
valueSchema
Description copied from interface:Schema
Get the value schema for this map or array schema. Throws a DataException if this schema is not a map or array.- Specified by:
valueSchema
in interfaceSchema
- Returns:
- the value schema
-
validateValue
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
-
validateValue
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
Description copied from interface:Schema
Return a concrete instance of theSchema
-
equals
-
hashCode
public int hashCode() -
toString
-
schemaType
Get theSchema.Type
associated with the given class.- Parameters:
klass
- the Class to- Returns:
- the corresponding type, or null if there is no matching type
-