Package org.apache.beam.sdk.values
Class Row
- java.lang.Object
-
- org.apache.beam.sdk.values.Row
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
RowWithGetters
,RowWithStorage
@Experimental(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 aPCollection
. The fields are described with aSchema
.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();
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Row.Builder
Builder forRow
.static class
Row.Equals
static class
Row.FieldValueBuilder
Builder forRow
that bases a row on another row.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 extends @Nullable java.lang.Object>
TgetBaseValue(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 extends @Nullable java.lang.Object>
TgetBaseValue(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 aBoolean
value by field index,ClassCastException
is thrown if schema doesn't match.@Nullable java.lang.Boolean
getBoolean(java.lang.String fieldName)
Get aSchema.TypeName.BOOLEAN
value by field name,IllegalStateException
is thrown if schema doesn't match.@Nullable java.lang.Byte
getByte(int idx)
Get aSchema.TypeName.BYTE
value by field index,ClassCastException
is thrown if schema doesn't match.@Nullable java.lang.Byte
getByte(java.lang.String fieldName)
Get aSchema.TypeName.BYTE
value by field name,IllegalStateException
is thrown if schema doesn't match.byte @Nullable []
getBytes(int idx)
Get aSchema.TypeName.BYTES
value by field index,ClassCastException
is thrown if schema doesn't match.byte @Nullable []
getBytes(java.lang.String fieldName)
Get aSchema.TypeName.BYTES
value by field name,IllegalStateException
is thrown if schema doesn't match.@Nullable org.joda.time.ReadableDateTime
getDateTime(int idx)
Get aSchema.TypeName.DATETIME
value by field index,IllegalStateException
is thrown if schema doesn't match.@Nullable org.joda.time.ReadableDateTime
getDateTime(java.lang.String fieldName)
Get aSchema.TypeName.DATETIME
value by field name,IllegalStateException
is thrown if schema doesn't match.@Nullable java.math.BigDecimal
getDecimal(int idx)
Get aBigDecimal
value by field index,ClassCastException
is thrown if schema doesn't match.@Nullable java.math.BigDecimal
getDecimal(java.lang.String fieldName)
Get aSchema.TypeName.DECIMAL
value by field name,IllegalStateException
is thrown if schema doesn't match.@Nullable java.lang.Double
getDouble(int idx)
Get aSchema.TypeName.DOUBLE
value by field index,ClassCastException
is thrown if schema doesn't match.@Nullable java.lang.Double
getDouble(java.lang.String fieldName)
Get aSchema.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 aSchema.TypeName.FLOAT
value by field index,ClassCastException
is thrown if schema doesn't match.@Nullable java.lang.Float
getFloat(java.lang.String fieldName)
Get aSchema.TypeName.FLOAT
value by field name,IllegalStateException
is thrown if schema doesn't match.@Nullable java.lang.Short
getInt16(int idx)
Get aSchema.TypeName.INT16
value by field index,ClassCastException
is thrown if schema doesn't match.@Nullable java.lang.Short
getInt16(java.lang.String fieldName)
Get aSchema.TypeName.INT16
value by field name,IllegalStateException
is thrown if schema doesn't match.@Nullable java.lang.Integer
getInt32(int idx)
Get aSchema.TypeName.INT32
value by field index,ClassCastException
is thrown if schema doesn't match.@Nullable java.lang.Integer
getInt32(java.lang.String fieldName)
Get aSchema.TypeName.INT32
value by field name,IllegalStateException
is thrown if schema doesn't match.@Nullable java.lang.Long
getInt64(int idx)
Get aSchema.TypeName.INT64
value by field index,ClassCastException
is thrown if schema doesn't match.@Nullable java.lang.Long
getInt64(java.lang.String fieldName)
Get aSchema.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 extends @Nullable java.lang.Object>
TgetLogicalTypeValue(int idx, java.lang.Class<T> clazz)
Returns the Logical Type input type for this field.<T extends @Nullable java.lang.Object>
TgetLogicalTypeValue(java.lang.String fieldName, java.lang.Class<T> clazz)
Returns the Logical Type input type for this field.<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 aRow
value by field index,IllegalStateException
is thrown if schema doesn't match.@Nullable Row
getRow(java.lang.String fieldName)
Get aSchema.TypeName.ROW
value by field name,IllegalStateException
is thrown if schema doesn't match.Schema
getSchema()
ReturnSchema
which describes the fields.@Nullable java.lang.String
getString(int idx)
Get aString
value by field index,ClassCastException
is thrown if schema doesn't match.@Nullable java.lang.String
getString(java.lang.String fieldName)
Get aSchema.TypeName.STRING
value by field name,IllegalStateException
is thrown if schema doesn't match.abstract <T extends @Nullable java.lang.Object>
TgetValue(int fieldIdx)
Get value by field index,ClassCastException
is thrown if schema doesn't match.<T extends @Nullable java.lang.Object>
TgetValue(java.lang.String fieldName)
Get value by field name,ClassCastException
is thrown if type doesn't match.abstract java.util.List<@Nullable java.lang.Object>
getValues()
Return the list of raw unmodified data values to enable 0-copy code.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 aRow
from the list of values andgetSchema()
.java.lang.String
toString()
java.lang.String
toString(boolean includeFieldNames)
Convert Row to String.static Row.Builder
withSchema(Schema schema)
Creates a row builder with specifiedgetSchema()
.
-
-
-
Method Detail
-
getValue
public abstract <T extends @Nullable java.lang.Object> T getValue(int fieldIdx)
Get value by field index,ClassCastException
is thrown if schema doesn't match.
-
getFieldCount
public abstract int getFieldCount()
Return the size of data fields.
-
getValues
public abstract java.util.List<@Nullable java.lang.Object> getValues()
Return the list of raw unmodified data values to enable 0-copy code.
-
getBaseValues
public java.util.List<java.lang.Object> getBaseValues()
Return a list of data values. Any LogicalType values are returned as base values. *
-
getValue
public <T extends @Nullable java.lang.Object> T getValue(java.lang.String fieldName)
Get value by field name,ClassCastException
is thrown if type doesn't match.
-
getByte
public @Nullable java.lang.Byte getByte(java.lang.String fieldName)
Get aSchema.TypeName.BYTE
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getBytes
public byte @Nullable [] getBytes(java.lang.String fieldName)
Get aSchema.TypeName.BYTES
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getInt16
public @Nullable java.lang.Short getInt16(java.lang.String fieldName)
Get aSchema.TypeName.INT16
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getInt32
public @Nullable java.lang.Integer getInt32(java.lang.String fieldName)
Get aSchema.TypeName.INT32
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getInt64
public @Nullable java.lang.Long getInt64(java.lang.String fieldName)
Get aSchema.TypeName.INT64
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getDecimal
public @Nullable java.math.BigDecimal getDecimal(java.lang.String fieldName)
Get aSchema.TypeName.DECIMAL
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getFloat
public @Nullable java.lang.Float getFloat(java.lang.String fieldName)
Get aSchema.TypeName.FLOAT
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getDouble
public @Nullable java.lang.Double getDouble(java.lang.String fieldName)
Get aSchema.TypeName.DOUBLE
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getString
public @Nullable java.lang.String getString(java.lang.String fieldName)
Get aSchema.TypeName.STRING
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getDateTime
public @Nullable org.joda.time.ReadableDateTime getDateTime(java.lang.String fieldName)
Get aSchema.TypeName.DATETIME
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getBoolean
public @Nullable java.lang.Boolean getBoolean(java.lang.String fieldName)
Get aSchema.TypeName.BOOLEAN
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getArray
public <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.
-
getIterable
public <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.
-
getMap
public <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.
-
getLogicalTypeValue
public <T extends @Nullable java.lang.Object> T getLogicalTypeValue(java.lang.String fieldName, java.lang.Class<T> clazz)
Returns the Logical Type input type for this field.IllegalStateException
is thrown if schema doesn't match.
-
getBaseValue
public <T extends @Nullable java.lang.Object> T getBaseValue(java.lang.String fieldName, java.lang.Class<T> clazz)
Returns the base type for this field. If this is a logical type, we convert to the base value. Otherwise the field itself is returned.
-
getBaseValue
public @Nullable java.lang.Object getBaseValue(java.lang.String fieldName)
Returns the base type for this field. If this is a logical type, we convert to the base value. Otherwise the field itself is returned.
-
getRow
public @Nullable Row getRow(java.lang.String fieldName)
Get aSchema.TypeName.ROW
value by field name,IllegalStateException
is thrown if schema doesn't match.
-
getByte
public @Nullable java.lang.Byte getByte(int idx)
Get aSchema.TypeName.BYTE
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getBytes
public byte @Nullable [] getBytes(int idx)
Get aSchema.TypeName.BYTES
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getInt16
public @Nullable java.lang.Short getInt16(int idx)
Get aSchema.TypeName.INT16
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getInt32
public @Nullable java.lang.Integer getInt32(int idx)
Get aSchema.TypeName.INT32
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getFloat
public @Nullable java.lang.Float getFloat(int idx)
Get aSchema.TypeName.FLOAT
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getDouble
public @Nullable java.lang.Double getDouble(int idx)
Get aSchema.TypeName.DOUBLE
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getInt64
public @Nullable java.lang.Long getInt64(int idx)
Get aSchema.TypeName.INT64
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getString
public @Nullable java.lang.String getString(int idx)
Get aString
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getDateTime
public @Nullable org.joda.time.ReadableDateTime getDateTime(int idx)
Get aSchema.TypeName.DATETIME
value by field index,IllegalStateException
is thrown if schema doesn't match.
-
getDecimal
public @Nullable java.math.BigDecimal getDecimal(int idx)
Get aBigDecimal
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getBoolean
public @Nullable java.lang.Boolean getBoolean(int idx)
Get aBoolean
value by field index,ClassCastException
is thrown if schema doesn't match.
-
getArray
public <T> @Nullable java.util.Collection<T> getArray(int idx)
Get an array value by field index,IllegalStateException
is thrown if schema doesn't match.
-
getIterable
public <T> @Nullable java.lang.Iterable<T> getIterable(int idx)
Get an iterable value by field index,IllegalStateException
is thrown if schema doesn't match.
-
getMap
public <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.
-
getLogicalTypeValue
public <T extends @Nullable java.lang.Object> T getLogicalTypeValue(int idx, java.lang.Class<T> clazz)
Returns the Logical Type input type for this field.IllegalStateException
is thrown if schema doesn't match.
-
getBaseValue
public <T extends @Nullable java.lang.Object> T getBaseValue(int idx, java.lang.Class<T> clazz)
Returns the base type for this field. If this is a logical type, we convert to the base value. Otherwise the field itself is returned.
-
getBaseValue
public @Nullable java.lang.Object getBaseValue(int idx)
Returns the base type for this field. If this is a logical type, we convert to the base value. Otherwise the field itself is returned.
-
getRow
public @Nullable Row getRow(int idx)
Get aRow
value by field index,IllegalStateException
is thrown if schema doesn't match.
-
equals
public boolean equals(@Nullable java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
public java.lang.String toString(boolean includeFieldNames)
Convert Row to String.
-
withSchema
public static Row.Builder withSchema(Schema schema)
Creates a row builder with specifiedgetSchema()
.Row.Builder.build()
will throw anIllegalArgumentException
if number of fields ingetSchema()
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 aClassCastException
.
-
fromRow
public static Row.FieldValueBuilder fromRow(Row row)
Creates a row builder based on the specified row. Field values in the new row can be explicitly set usingRow.FieldValueBuilder.withFieldValue(java.lang.String, java.lang.Object)
. Any values not so overridden will be the same as the values in the original row.
-
toRow
public static <T> java.util.stream.Collector<T,java.util.List<java.lang.Object>,Row> toRow(Schema schema)
Creates aRow
from the list of values andgetSchema()
.
-
-