@Experimental(value=SCHEMAS) public abstract class Row extends java.lang.Object implements java.io.Serializable
Row
is an immutable tuple-like schema to represent one element in a PCollection
.
The fields are described with a Schema
.
Schema
contains the names and types for each field.
There are several ways to build a new Row object. To build a row from scratch using a schema
object, withSchema(org.apache.beam.sdk.schemas.Schema)
can be used. Schema fields can be specified by name, and nested
fields can be specified using the field selection syntax. For example:
Row row = Row.withSchema(schema)
.withFieldValue("userId", "user1)
.withFieldValue("location.city", "seattle")
.withFieldValue("location.state", "wa")
.build();
The fromRow(org.apache.beam.sdk.values.Row)
builder can be used to base a row off of another row. The builder can
be used to specify values for specific fields, and all the remaining values will be taken from
the original row. For example, the following produces a row identical to the above row except for
the location.city field.
Row modifiedRow =
Row.fromRow(row)
.withFieldValue("location.city", "tacoma")
.build();
Modifier and Type | Class and Description |
---|---|
static class |
Row.Builder
Builder for
Row . |
static class |
Row.Equals |
static class |
Row.FieldValueBuilder
Builder for
Row that bases a row on another row. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(@Nullable java.lang.Object o) |
static Row.FieldValueBuilder |
fromRow(Row row)
Creates a row builder based on the specified row.
|
<T> @Nullable java.util.Collection<T> |
getArray(int idx)
Get an array value by field index,
IllegalStateException is thrown if schema doesn't
match. |
<T> @Nullable java.util.Collection<T> |
getArray(java.lang.String fieldName)
Get an array value by field name,
IllegalStateException is thrown if schema doesn't
match. |
@Nullable java.lang.Object |
getBaseValue(int idx)
Returns the base type for this field.
|
<T> T |
getBaseValue(int idx,
java.lang.Class<T> clazz)
Returns the base type for this field.
|
@Nullable java.lang.Object |
getBaseValue(java.lang.String fieldName)
Returns the base type for this field.
|
<T> T |
getBaseValue(java.lang.String fieldName,
java.lang.Class<T> clazz)
Returns the base type for this field.
|
java.util.List<java.lang.Object> |
getBaseValues()
Return a list of data values.
|
@Nullable java.lang.Boolean |
getBoolean(int idx)
Get a
Boolean value by field index, ClassCastException is thrown if schema
doesn't match. |
@Nullable java.lang.Boolean |
getBoolean(java.lang.String fieldName)
Get a
Schema.TypeName.BOOLEAN value by field name, IllegalStateException is thrown if
schema doesn't match. |
@Nullable java.lang.Byte |
getByte(int idx)
Get a
Schema.TypeName.BYTE value by field index, ClassCastException is thrown if
schema doesn't match. |
@Nullable java.lang.Byte |
getByte(java.lang.String fieldName)
Get a
Schema.TypeName.BYTE value by field name, IllegalStateException is thrown if
schema doesn't match. |
byte[] |
getBytes(int idx)
Get a
Schema.TypeName.BYTES value by field index, ClassCastException is thrown if
schema doesn't match. |
byte[] |
getBytes(java.lang.String fieldName)
Get a
Schema.TypeName.BYTES value by field name, IllegalStateException is thrown if
schema doesn't match. |
@Nullable ReadableDateTime |
getDateTime(int idx)
Get a
Schema.TypeName.DATETIME value by field index, IllegalStateException is thrown
if schema doesn't match. |
@Nullable ReadableDateTime |
getDateTime(java.lang.String fieldName)
Get a
Schema.TypeName.DATETIME value by field name, IllegalStateException is thrown if
schema doesn't match. |
@Nullable java.math.BigDecimal |
getDecimal(int idx)
Get a
BigDecimal value by field index, ClassCastException is thrown if schema
doesn't match. |
@Nullable java.math.BigDecimal |
getDecimal(java.lang.String fieldName)
Get a
Schema.TypeName.DECIMAL value by field name, IllegalStateException is thrown if
schema doesn't match. |
@Nullable java.lang.Double |
getDouble(int idx)
Get a
Schema.TypeName.DOUBLE value by field index, ClassCastException is thrown if
schema doesn't match. |
@Nullable java.lang.Double |
getDouble(java.lang.String fieldName)
Get a
Schema.TypeName.DOUBLE value by field name, IllegalStateException is thrown if
schema doesn't match. |
abstract int |
getFieldCount()
Return the size of data fields.
|
@Nullable java.lang.Float |
getFloat(int idx)
Get a
Schema.TypeName.FLOAT value by field index, ClassCastException is thrown if
schema doesn't match. |
@Nullable java.lang.Float |
getFloat(java.lang.String fieldName)
Get a
Schema.TypeName.FLOAT value by field name, IllegalStateException is thrown if
schema doesn't match. |
@Nullable java.lang.Short |
getInt16(int idx)
Get a
Schema.TypeName.INT16 value by field index, ClassCastException is thrown if
schema doesn't match. |
@Nullable java.lang.Short |
getInt16(java.lang.String fieldName)
Get a
Schema.TypeName.INT16 value by field name, IllegalStateException is thrown if
schema doesn't match. |
@Nullable java.lang.Integer |
getInt32(int idx)
Get a
Schema.TypeName.INT32 value by field index, ClassCastException is thrown if
schema doesn't match. |
@Nullable java.lang.Integer |
getInt32(java.lang.String fieldName)
Get a
Schema.TypeName.INT32 value by field name, IllegalStateException is thrown if
schema doesn't match. |
@Nullable java.lang.Long |
getInt64(int idx)
Get a
Schema.TypeName.INT64 value by field index, ClassCastException is thrown if
schema doesn't match. |
@Nullable java.lang.Long |
getInt64(java.lang.String fieldName)
Get a
Schema.TypeName.INT64 value by field name, IllegalStateException is thrown if
schema doesn't match. |
<T> @Nullable java.lang.Iterable<T> |
getIterable(int idx)
Get an iterable value by field index,
IllegalStateException is thrown if schema doesn't
match. |
<T> @Nullable java.lang.Iterable<T> |
getIterable(java.lang.String fieldName)
Get an iterable value by field name,
IllegalStateException is thrown if schema doesn't
match. |
<T> T |
getLogicalTypeValue(int idx,
java.lang.Class<T> clazz)
Returns the Logical Type input type for this field.
|
<T> T |
getLogicalTypeValue(java.lang.String fieldName,
java.lang.Class<T> clazz) |
<T1,T2> @Nullable java.util.Map<T1,T2> |
getMap(int idx)
Get a MAP value by field index,
IllegalStateException is thrown if schema doesn't
match. |
<T1,T2> @Nullable java.util.Map<T1,T2> |
getMap(java.lang.String fieldName)
Get a MAP value by field name,
IllegalStateException is thrown if schema doesn't match. |
@Nullable Row |
getRow(int idx)
Get a
Row value by field index, IllegalStateException is thrown if schema
doesn't match. |
@Nullable Row |
getRow(java.lang.String fieldName)
Get a
Schema.TypeName.ROW value by field name, IllegalStateException is thrown if
schema doesn't match. |
Schema |
getSchema()
Return
Schema which describes the fields. |
@Nullable java.lang.String |
getString(int idx)
Get a
String value by field index, ClassCastException is thrown if schema
doesn't match. |
@Nullable java.lang.String |
getString(java.lang.String fieldName)
Get a
Schema.TypeName.STRING value by field name, IllegalStateException is thrown if
schema doesn't match. |
abstract <T> T |
getValue(int fieldIdx)
Get value by field index,
ClassCastException is thrown if schema doesn't match. |
<T> T |
getValue(java.lang.String fieldName)
Get value by field name,
ClassCastException is thrown if type doesn't match. |
abstract java.util.List<java.lang.Object> |
getValues()
Return the list of data values.
|
int |
hashCode() |
static Row |
nullRow(Schema schema)
Creates a new record filled with nulls.
|
static <T> java.util.stream.Collector<T,java.util.List<java.lang.Object>,Row> |
toRow(Schema schema)
Creates a
Row from the list of values and getSchema() . |
java.lang.String |
toString() |
static Row.Builder |
withSchema(Schema schema)
Creates a row builder with specified
getSchema() . |
public abstract <T> T getValue(int fieldIdx)
ClassCastException
is thrown if schema doesn't match.public abstract int getFieldCount()
public abstract java.util.List<java.lang.Object> getValues()
public java.util.List<java.lang.Object> getBaseValues()
public <T> T getValue(java.lang.String fieldName)
ClassCastException
is thrown if type doesn't match.public @Nullable java.lang.Byte getByte(java.lang.String fieldName)
Schema.TypeName.BYTE
value by field name, IllegalStateException
is thrown if
schema doesn't match.public byte[] getBytes(java.lang.String fieldName)
Schema.TypeName.BYTES
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable java.lang.Short getInt16(java.lang.String fieldName)
Schema.TypeName.INT16
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable java.lang.Integer getInt32(java.lang.String fieldName)
Schema.TypeName.INT32
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable java.lang.Long getInt64(java.lang.String fieldName)
Schema.TypeName.INT64
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable java.math.BigDecimal getDecimal(java.lang.String fieldName)
Schema.TypeName.DECIMAL
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable java.lang.Float getFloat(java.lang.String fieldName)
Schema.TypeName.FLOAT
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable java.lang.Double getDouble(java.lang.String fieldName)
Schema.TypeName.DOUBLE
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable java.lang.String getString(java.lang.String fieldName)
Schema.TypeName.STRING
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable ReadableDateTime getDateTime(java.lang.String fieldName)
Schema.TypeName.DATETIME
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable java.lang.Boolean getBoolean(java.lang.String fieldName)
Schema.TypeName.BOOLEAN
value by field name, IllegalStateException
is thrown if
schema doesn't match.public <T> @Nullable java.util.Collection<T> getArray(java.lang.String fieldName)
IllegalStateException
is thrown if schema doesn't
match.public <T> @Nullable java.lang.Iterable<T> getIterable(java.lang.String fieldName)
IllegalStateException
is thrown if schema doesn't
match.public <T1,T2> @Nullable java.util.Map<T1,T2> getMap(java.lang.String fieldName)
IllegalStateException
is thrown if schema doesn't match.public <T> T getLogicalTypeValue(java.lang.String fieldName, java.lang.Class<T> clazz)
public <T> T getBaseValue(java.lang.String fieldName, java.lang.Class<T> clazz)
public @Nullable java.lang.Object getBaseValue(java.lang.String fieldName)
public @Nullable Row getRow(java.lang.String fieldName)
Schema.TypeName.ROW
value by field name, IllegalStateException
is thrown if
schema doesn't match.public @Nullable java.lang.Byte getByte(int idx)
Schema.TypeName.BYTE
value by field index, ClassCastException
is thrown if
schema doesn't match.public byte[] getBytes(int idx)
Schema.TypeName.BYTES
value by field index, ClassCastException
is thrown if
schema doesn't match.public @Nullable java.lang.Short getInt16(int idx)
Schema.TypeName.INT16
value by field index, ClassCastException
is thrown if
schema doesn't match.public @Nullable java.lang.Integer getInt32(int idx)
Schema.TypeName.INT32
value by field index, ClassCastException
is thrown if
schema doesn't match.public @Nullable java.lang.Float getFloat(int idx)
Schema.TypeName.FLOAT
value by field index, ClassCastException
is thrown if
schema doesn't match.public @Nullable java.lang.Double getDouble(int idx)
Schema.TypeName.DOUBLE
value by field index, ClassCastException
is thrown if
schema doesn't match.public @Nullable java.lang.Long getInt64(int idx)
Schema.TypeName.INT64
value by field index, ClassCastException
is thrown if
schema doesn't match.public @Nullable java.lang.String getString(int idx)
String
value by field index, ClassCastException
is thrown if schema
doesn't match.public @Nullable ReadableDateTime getDateTime(int idx)
Schema.TypeName.DATETIME
value by field index, IllegalStateException
is thrown
if schema doesn't match.public @Nullable java.math.BigDecimal getDecimal(int idx)
BigDecimal
value by field index, ClassCastException
is thrown if schema
doesn't match.public @Nullable java.lang.Boolean getBoolean(int idx)
Boolean
value by field index, ClassCastException
is thrown if schema
doesn't match.public <T> @Nullable java.util.Collection<T> getArray(int idx)
IllegalStateException
is thrown if schema doesn't
match.public <T> @Nullable java.lang.Iterable<T> getIterable(int idx)
IllegalStateException
is thrown if schema doesn't
match.public <T1,T2> @Nullable java.util.Map<T1,T2> getMap(int idx)
IllegalStateException
is thrown if schema doesn't
match.public <T> T getLogicalTypeValue(int idx, java.lang.Class<T> clazz)
IllegalStateException
is thrown if
schema doesn't match.public <T> T getBaseValue(int idx, java.lang.Class<T> clazz)
public @Nullable java.lang.Object getBaseValue(int idx)
public @Nullable Row getRow(int idx)
Row
value by field index, IllegalStateException
is thrown if schema
doesn't match.public boolean equals(@Nullable java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static Row.Builder withSchema(Schema schema)
getSchema()
. Row.Builder.build()
will throw
an IllegalArgumentException
if number of fields in getSchema()
does not match
the number of fields specified. If any of the arguments don't match the expected types for the
schema fields, Row.Builder.build()
will throw a ClassCastException
.public static Row.FieldValueBuilder fromRow(Row row)
Row.FieldValueBuilder.withFieldValue(java.lang.String, java.lang.Object)
. Any values not so overridden will be the
same as the values in the original row.public static <T> java.util.stream.Collector<T,java.util.List<java.lang.Object>,Row> toRow(Schema schema)
Row
from the list of values and getSchema()
.