Package org.apache.kafka.connect.data
Class Struct
java.lang.Object
org.apache.kafka.connect.data.Struct
A structured record containing a set of named fields with values, each field using an independent Schema.
Struct objects must specify a complete Schema up front, and only fields specified in the Schema may be set.
The Struct's put(String, Object) method returns the Struct itself to provide a fluent API for constructing
complete objects:
Schema schema = SchemaBuilder.struct().name("com.example.Person")
.field("name", Schema.STRING_SCHEMA).field("age", Schema.INT32_SCHEMA).build()
Struct struct = new Struct(schema).put("name", "Bobby McGee").put("age", 21)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanGet the value of a field, returning the default value if no value has been set yet and a default value is specified in the field's schema.Get the value of a field, returning the default value if no value has been set yet and a default value is specified in the field's schema.<T> List<T> Equivalent to callingget(String)and casting the result to a List.getBoolean(String fieldName) Equivalent to callingget(String)and casting the result to a Boolean.byte[]Equivalent to callingget(String)and casting the result to a byte[].getFloat32(String fieldName) Equivalent to callingget(String)and casting the result to a Float.getFloat64(String fieldName) Equivalent to callingget(String)and casting the result to a Double.Equivalent to callingget(String)and casting the result to a Short.Equivalent to callingget(String)and casting the result to an Integer.Equivalent to callingget(String)and casting the result to a Long.Equivalent to callingget(String)and casting the result to a Byte.<K,V> Map <K, V> Equivalent to callingget(String)and casting the result to a Map.Equivalent to callingget(String)and casting the result to a String.Equivalent to callingget(String)and casting the result to a Struct.getWithoutDefault(String fieldName) Get the underlying raw value for the field without accounting for default values.inthashCode()Set the value of a field.Set the value of a field.schema()Get the schema for this Struct.toString()voidvalidate()Validates that this struct has filled in all the necessary data with valid values.
-
Constructor Details
-
Method Details
-
schema
Get the schema for this Struct.- Returns:
- the Struct's schema
-
get
Get the value of a field, returning the default value if no value has been set yet and a default value is specified in the field's schema. Because this handles fields of all types, the value is returned as anObjectand must be cast to a more specific type.- Parameters:
fieldName- the field name to lookup- Returns:
- the value for the field
-
get
Get the value of a field, returning the default value if no value has been set yet and a default value is specified in the field's schema. Because this handles fields of all types, the value is returned as anObjectand must be cast to a more specific type.- Parameters:
field- the field to lookup- Returns:
- the value for the field
-
getWithoutDefault
Get the underlying raw value for the field without accounting for default values.- Parameters:
fieldName- the field to get the value of- Returns:
- the raw value
-
getInt8
Equivalent to callingget(String)and casting the result to a Byte. -
getInt16
Equivalent to callingget(String)and casting the result to a Short. -
getInt32
Equivalent to callingget(String)and casting the result to an Integer. -
getInt64
Equivalent to callingget(String)and casting the result to a Long. -
getFloat32
Equivalent to callingget(String)and casting the result to a Float. -
getFloat64
Equivalent to callingget(String)and casting the result to a Double. -
getBoolean
Equivalent to callingget(String)and casting the result to a Boolean. -
getString
Equivalent to callingget(String)and casting the result to a String. -
getBytes
Equivalent to callingget(String)and casting the result to a byte[]. -
getArray
Equivalent to callingget(String)and casting the result to a List. -
getMap
Equivalent to callingget(String)and casting the result to a Map. -
getStruct
Equivalent to callingget(String)and casting the result to a Struct. -
put
Set the value of a field. Validates the value, throwing aDataExceptionif it does not match the field'sSchema.- Parameters:
fieldName- the name of the field to setvalue- the value of the field- Returns:
- the Struct, to allow chaining of
put(String, Object)calls
-
put
Set the value of a field. Validates the value, throwing aDataExceptionif it does not match the field'sSchema.- Parameters:
field- the field to setvalue- the value of the field- Returns:
- the Struct, to allow chaining of
put(String, Object)calls
-
validate
public void validate()Validates that this struct has filled in all the necessary data with valid values. For required fields without defaults, this validates that a value has been set and has matching types/schemas. If any validation fails, throws aDataException. -
equals
-
hashCode
public int hashCode() -
toString
-