Package org.apache.avro.generic
Class GenericRecordBuilder
java.lang.Object
org.apache.avro.data.RecordBuilderBase<GenericData.Record>
org.apache.avro.generic.GenericRecordBuilder
- All Implemented Interfaces:
RecordBuilder<GenericData.Record>
A RecordBuilder for generic records. GenericRecordBuilder fills in default
values for fields if they are not specified.
-
Constructor Summary
ConstructorDescriptionCreates a GenericRecordBuilder by copying an existing record instance.Creates a GenericRecordBuilder by copying an existing GenericRecordBuilder.GenericRecordBuilder
(Schema schema) Creates a GenericRecordBuilder for building Record instances. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Constructs a new instance using the values set in the RecordBuilder.protected GenericRecordBuilder
clear
(int pos) Clears the value of the given field.Clears the value of the given field.clear
(Schema.Field field) Clears the value of the given field.boolean
protected Object
get
(int pos) Gets the value of a field.Gets the value of a field.get
(Schema.Field field) Gets the value of a field.protected boolean
has
(int pos) Checks whether a field has been set.boolean
Checks whether a field has been set.boolean
has
(Schema.Field field) Checks whether a field has been set.int
hashCode()
protected GenericRecordBuilder
Sets the value of a field.Sets the value of a field.set
(Schema.Field field, Object value) Sets the value of a field.Methods inherited from class org.apache.avro.data.RecordBuilderBase
data, defaultValue, fields, fieldSetFlags, isValidValue, schema, validate
-
Constructor Details
-
GenericRecordBuilder
Creates a GenericRecordBuilder for building Record instances.- Parameters:
schema
- the schema associated with the record class.
-
GenericRecordBuilder
Creates a GenericRecordBuilder by copying an existing GenericRecordBuilder.- Parameters:
other
- the GenericRecordBuilder to copy.
-
GenericRecordBuilder
Creates a GenericRecordBuilder by copying an existing record instance.- Parameters:
other
- the record instance to copy.
-
-
Method Details
-
get
Gets the value of a field.- Parameters:
fieldName
- the name of the field to get.- Returns:
- the value of the field with the given name, or null if not set.
-
get
Gets the value of a field.- Parameters:
field
- the field to get.- Returns:
- the value of the given field, or null if not set.
-
get
Gets the value of a field.- Parameters:
pos
- the position of the field to get.- Returns:
- the value of the field with the given position, or null if not set.
-
set
Sets the value of a field.- Parameters:
fieldName
- the name of the field to set.value
- the value to set.- Returns:
- a reference to the RecordBuilder.
-
set
Sets the value of a field.- Parameters:
field
- the field to set.value
- the value to set.- Returns:
- a reference to the RecordBuilder.
-
set
Sets the value of a field.- Parameters:
pos
- the field to set.value
- the value to set.- Returns:
- a reference to the RecordBuilder.
-
has
Checks whether a field has been set.- Parameters:
fieldName
- the name of the field to check.- Returns:
- true if the given field is non-null; false otherwise.
-
has
Checks whether a field has been set.- Parameters:
field
- the field to check.- Returns:
- true if the given field is non-null; false otherwise.
-
has
protected boolean has(int pos) Checks whether a field has been set.- Parameters:
pos
- the position of the field to check.- Returns:
- true if the given field is non-null; false otherwise.
-
clear
Clears the value of the given field.- Parameters:
fieldName
- the name of the field to clear.- Returns:
- a reference to the RecordBuilder.
-
clear
Clears the value of the given field.- Parameters:
field
- the field to clear.- Returns:
- a reference to the RecordBuilder.
-
clear
Clears the value of the given field.- Parameters:
pos
- the position of the field to clear.- Returns:
- a reference to the RecordBuilder.
-
build
Description copied from interface:RecordBuilder
Constructs a new instance using the values set in the RecordBuilder. If a particular value was not set and the schema defines a default value, the default value will be used.- Returns:
- a new instance using values set in the RecordBuilder.
-
hashCode
public int hashCode()- Overrides:
hashCode
in classRecordBuilderBase<GenericData.Record>
-
equals
- Overrides:
equals
in classRecordBuilderBase<GenericData.Record>
-