public interface SchemaBuilder
Schema
.
A schema defines the records and fields that may occur in a RecordV2 topic value.
The schema must declare at least one record type and every record must have at least one field type declared.
Every record type and field type has a 'multiplicity' which defines the number of times that the record or field may occur within the data. Multiplicity is specified as a 'minimum' and 'maximum' number of occurrences or where the minimum and maximum are the same (fixed multiplicity) then the multiplicity may be specified as a single 'occurs' value. If the minimum and maximum are different, this is referred to a 'variable' multiplicity. Only the last record declared or the last field within a record may have variable multiplicity. The maximum value may be declared as -1 to indicate that the record or field can have an unlimited number of occurrences.
The builder is used to add a record definition followed by the fields within
it. After all fields have been added to a record another may then be added,
and so on, and then finally build()
is called to create an immutable
schema object.
Every call returns the builder instance allowing calls to be chained, for example:
Schema schema = builder.record("R1").string("S1").string("S2", 1, 5) .record("R2", 0, -1).decimal("D", 5).build();A builder is obtained using the
RecordV2DataType.schemaBuilder()
method.Modifier and Type | Method and Description |
---|---|
Schema |
build()
Build an immutable Schema.
|
SchemaBuilder |
decimal(String name,
int scale)
Add a single occurrence decimal field to the current record.
|
SchemaBuilder |
decimal(String name,
int scale,
int occurs)
Add a fixed multiplicity decimal field to the current record.
|
SchemaBuilder |
decimal(String name,
int scale,
int min,
int max)
Add a decimal field to the current record.
|
SchemaBuilder |
integer(String name)
Add a single occurrence integer field to the current record.
|
SchemaBuilder |
integer(String name,
int occurs)
Add a fixed multiplicity integer field to the current record.
|
SchemaBuilder |
integer(String name,
int min,
int max)
Add an integer field to the current record.
|
SchemaBuilder |
record(String name)
Add a new single occurrence record to the schema.
|
SchemaBuilder |
record(String name,
int occurs)
Add a new fixed multiplicity record to the schema.
|
SchemaBuilder |
record(String name,
int min,
int max)
Add a new record to the schema.
|
SchemaBuilder |
string(String name)
Add a single occurrence string field to the current record.
|
SchemaBuilder |
string(String name,
int occurs)
Add a fixed multiplicity string field to the current record.
|
SchemaBuilder |
string(String name,
int min,
int max)
Add a string field to the current record.
|
SchemaBuilder record(String name) throws SchemaViolationException
This is the equivalent to calling record(name, 1)
name
- the record nameSchemaViolationException
- if schema rules are violatedSchemaBuilder record(String name, int occurs) throws SchemaViolationException
This is the equivalent to calling record(name, occurs, occurs)
.
name
- the record nameoccurs
- the number of times the record is to occur. This must be a
positive value.SchemaViolationException
- if schema rules are violatedSchemaBuilder record(String name, int min, int max) throws SchemaViolationException
The record added must not have the same name as a previously added record.
A record may not be added after a record with variable multiplicity.
A record may not be added directly after another record which has had no fields added.
name
- the record namemin
- the minimum number of occurrences of the record. This must not
be negative.max
- the maximum number of occurrences of the record. This must
either be -1 to indicate an unlimited number or it must be a
positive number greater than or equal to min
.SchemaViolationException
- if schema rules are violatedSchemaBuilder string(String name) throws SchemaViolationException
This is the equivalent of calling string(name, 1)
.
name
- field nameSchemaViolationException
- if schema rules are violatedSchemaBuilder string(String name, int occurs) throws SchemaViolationException
This is the equivalent of calling string(name, occurs, occurs)
.
name
- field nameoccurs
- the fixed number of times the field should occur within the
record. This must be positive.SchemaViolationException
- if schema rules are violatedSchemaBuilder string(String name, int min, int max) throws SchemaViolationException
A field may not be added after a field that has variable multiplicity (min != max).
name
- field name. This must not be the same as any field already
added to the record.min
- the minimum number of times the field may occur within the
record. This must not be negative.max
- the maximum number of times that the field may occur within
the record. This must either be -1 (indicating no upper limit) or
a positive value that is not less than min.SchemaViolationException
- if schema rules are violatedSchemaBuilder integer(String name) throws SchemaViolationException
This is the equivalent of calling integer(name, 1)
.
name
- field nameSchemaViolationException
- if schema rules are violatedSchemaBuilder integer(String name, int occurs) throws SchemaViolationException
This is the equivalent of calling integer(name, occurs, occurs)
.
name
- field nameoccurs
- the fixed number of times the field should occur within the
record. This must be positive.SchemaViolationException
- if schema rules are violatedSchemaBuilder integer(String name, int min, int max) throws SchemaViolationException
A field may not be added after a field that has variable multiplicity (min != max).
name
- field name. This must not be the same as any field already
added to the record.min
- the minimum number of times the field may occur within the
record. This must not be negative.max
- the maximum number of times that the field may occur within
the record. This must either be -1 (indicating no upper limit) or
a positive value that is not less than min.SchemaViolationException
- if schema rules are violatedSchemaBuilder decimal(String name, int scale) throws SchemaViolationException
This is the equivalent of calling decimal(name, scale, 1)
.
name
- field namescale
- the scale of the field (the number of decimal places). This
must be a positive value.SchemaViolationException
- if schema rules are violatedSchemaBuilder decimal(String name, int scale, int occurs) throws SchemaViolationException
This is the equivalent of calling decimal(name, scale, occurs, occurs)
.
name
- field namescale
- the scale of the field (the number of decimal places). This
must be a positive value.occurs
- the fixed number of times the field should occur within the
record. This must be positive.SchemaViolationException
- if schema rules are violatedSchemaBuilder decimal(String name, int scale, int min, int max) throws SchemaViolationException
A field may not be added after a field that has variable multiplicity (min != max).
name
- field name. This must not be the same as any field already
added to the builder.scale
- the scale of the field (the number of decimal places). This
must be a positive value.min
- the minimum number of times the field may occur within the
record. This must not be negative.max
- the maximum number of times that the field may occur within
the record. This must either be -1 (indicating no upper limit) or
a positive value that is not less than min.SchemaViolationException
- if schema rules are violatedSchema build() throws SchemaViolationException
At least one record with at least one field must have been added to the builder.
SchemaViolationException
- if no record have been specified to the
builder.Copyright © 2022 Push Technology Ltd. All Rights Reserved.