Top Description Fields Constructors Methods
org.apache.avro.generic

public Class GenericRecordBuilder

extends RecordBuilderBase<GenericData.Record>
Class Inheritance
Imports
java.io.IOException, org.apache.avro.AvroRuntimeException, .Schema, .Schema.Field, org.apache.avro.data.RecordBuilderBase, org.apache.avro.generic.GenericData.Record

A RecordBuilder for generic records. GenericRecordBuilder fills in default values for fields if they are not specified.

Field Summary

Modifier and TypeField and Description
private final GenericData.Record

Constructor Summary

AccessConstructor and Description
public
GenericRecordBuilder(Schema
the schema associated with the record class.
schema
)

Creates a GenericRecordBuilder for building Record instances.

public
GenericRecordBuilder(GenericRecordBuilder
the GenericRecordBuilder to copy.
other
)

Creates a GenericRecordBuilder by copying an existing GenericRecordBuilder.

public
GenericRecordBuilder(GenericData.Record
the record instance to copy.
other
)

Creates a GenericRecordBuilder by copying an existing record instance.

Method Summary

Modifier and TypeMethod and Description
public GenericData.Record
build()

Implements org.apache.avro.data.RecordBuilder.build.

Constructs a new instance using the values set in the RecordBuilder.
public GenericRecordBuilder

Returns:

a reference to the RecordBuilder.
clear
(String
the name of the field to clear.
fieldName
)

Clears the value of the given field.

public GenericRecordBuilder

Returns:

a reference to the RecordBuilder.
clear
(Schema.Field
the field to clear.
field
)

Clears the value of the given field.

protected GenericRecordBuilder

Returns:

a reference to the RecordBuilder.
clear
(int
the position of the field to clear.
pos
)

Clears the value of the given field.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides org.apache.avro.data.RecordBuilderBase.equals.

Indicates whether some other object is "equal to" this one.
public Object

Returns:

the value of the field with the given name, or null if not set.
get
(String
the name of the field to get.
fieldName
)

Gets the value of a field.

public Object

Returns:

the value of the given field, or null if not set.
get
(Schema.Field
the field to get.
field
)

Gets the value of a field.

protected Object

Returns:

the value of the field with the given position, or null if not set.
get
(int
the position of the field to get.
pos
)

Gets the value of a field.

private Object

Returns:

the value set for the given field, the field's default value, or null.
getWithDefault
(Schema.Field
the field whose value should be retrieved.
field
)

Gets the value of the given field.

public boolean

Returns:

true if the given field is non-null; false otherwise.
has
(String
the name of the field to check.
fieldName
)

Checks whether a field has been set.

public boolean

Returns:

true if the given field is non-null; false otherwise.
has
(Schema.Field
the field to check.
field
)

Checks whether a field has been set.

protected boolean

Returns:

true if the given field is non-null; false otherwise.
has
(int
the position of the field to check.
pos
)

Checks whether a field has been set.

public int
hashCode()

Overrides org.apache.avro.data.RecordBuilderBase.hashCode.

Returns a hash code value for the object.
public GenericRecordBuilder

Returns:

a reference to the RecordBuilder.
set
(String
the name of the field to set.
fieldName
,
Object
the value to set.
value
)

Sets the value of a field.

public GenericRecordBuilder

Returns:

a reference to the RecordBuilder.
set
(Schema.Field
the field to set.
field
,
Object
the value to set.
value
)

Sets the value of a field.

protected GenericRecordBuilder

Returns:

a reference to the RecordBuilder.
set
(int
the field to set.
pos
,
Object
the value to set.
value
)

Sets the value of a field.

private GenericRecordBuilder

Returns:

a reference to the RecordBuilder.
set
(Schema.Field
the field to set.
field
,
int
the position of the field.
pos
,
Object
the value to set.
value
)

Sets the value of a field.

Inherited from org.apache.avro.data.RecordBuilderBase:
datadefaultValuefieldsfieldSetFlagsisValidValueschemavalidate

Field Detail

recordback to summary
private final GenericData.Record record

Constructor Detail

GenericRecordBuilderback to summary
public GenericRecordBuilder(Schema schema)

Creates a GenericRecordBuilder for building Record instances.

Parameters
schema:Schema

the schema associated with the record class.

GenericRecordBuilderback to summary
public GenericRecordBuilder(GenericRecordBuilder other)

Creates a GenericRecordBuilder by copying an existing GenericRecordBuilder.

Parameters
other:GenericRecordBuilder

the GenericRecordBuilder to copy.

GenericRecordBuilderback to summary
public GenericRecordBuilder(GenericData.Record other)

Creates a GenericRecordBuilder by copying an existing record instance.

Parameters
other:GenericData.Record

the record instance to copy.

Method Detail

buildback to summary
public GenericData.Record build()

Implements org.apache.avro.data.RecordBuilder.build.

Doc from org.apache.avro.data.RecordBuilder.build.

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:GenericData.Record

a new instance using values set in the RecordBuilder.

Annotations
@Override
clearback to summary
public GenericRecordBuilder clear(String fieldName)

Clears the value of the given field.

Parameters
fieldName:String

the name of the field to clear.

Returns:GenericRecordBuilder

a reference to the RecordBuilder.

clearback to summary
public GenericRecordBuilder clear(Schema.Field field)

Clears the value of the given field.

Parameters
field:Schema.Field

the field to clear.

Returns:GenericRecordBuilder

a reference to the RecordBuilder.

clearback to summary
protected GenericRecordBuilder clear(int pos)

Clears the value of the given field.

Parameters
pos:int

the position of the field to clear.

Returns:GenericRecordBuilder

a reference to the RecordBuilder.

equalsback to summary
public boolean equals(Object obj)

Overrides org.apache.avro.data.RecordBuilderBase.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getback to summary
public Object get(String fieldName)

Gets the value of a field.

Parameters
fieldName:String

the name of the field to get.

Returns:Object

the value of the field with the given name, or null if not set.

getback to summary
public Object get(Schema.Field field)

Gets the value of a field.

Parameters
field:Schema.Field

the field to get.

Returns:Object

the value of the given field, or null if not set.

getback to summary
protected Object get(int pos)

Gets the value of a field.

Parameters
pos:int

the position of the field to get.

Returns:Object

the value of the field with the given position, or null if not set.

getWithDefaultback to summary
private Object getWithDefault(Schema.Field field) throws IOException

Gets the value of the given field. If the field has been set, the set value is returned (even if it's null). If the field hasn't been set and has a default value, the default value is returned.

Parameters
field:Schema.Field

the field whose value should be retrieved.

Returns:Object

the value set for the given field, the field's default value, or null.

hasback to summary
public boolean has(String fieldName)

Checks whether a field has been set.

Parameters
fieldName:String

the name of the field to check.

Returns:boolean

true if the given field is non-null; false otherwise.

hasback to summary
public boolean has(Schema.Field field)

Checks whether a field has been set.

Parameters
field:Schema.Field

the field to check.

Returns:boolean

true if the given field is non-null; false otherwise.

hasback to summary
protected boolean has(int pos)

Checks whether a field has been set.

Parameters
pos:int

the position of the field to check.

Returns:boolean

true if the given field is non-null; false otherwise.

hashCodeback to summary
public int hashCode()

Overrides org.apache.avro.data.RecordBuilderBase.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
setback to summary
public GenericRecordBuilder set(String fieldName, Object value)

Sets the value of a field.

Parameters
fieldName:String

the name of the field to set.

value:Object

the value to set.

Returns:GenericRecordBuilder

a reference to the RecordBuilder.

setback to summary
public GenericRecordBuilder set(Schema.Field field, Object value)

Sets the value of a field.

Parameters
field:Schema.Field

the field to set.

value:Object

the value to set.

Returns:GenericRecordBuilder

a reference to the RecordBuilder.

setback to summary
protected GenericRecordBuilder set(int pos, Object value)

Sets the value of a field.

Parameters
pos:int

the field to set.

value:Object

the value to set.

Returns:GenericRecordBuilder

a reference to the RecordBuilder.

setback to summary
private GenericRecordBuilder set(Schema.Field field, int pos, Object value)

Sets the value of a field.

Parameters
field:Schema.Field

the field to set.

pos:int

the position of the field.

value:Object

the value to set.

Returns:GenericRecordBuilder

a reference to the RecordBuilder.