Class 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 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();
     
    See Also:
    Serialized Form
    • 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>
      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 extends @Nullable java.lang.Object>
      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 @Nullable [] getBytes​(int idx)
      Get a Schema.TypeName.BYTES value by field index, ClassCastException is thrown if schema doesn't match.
      byte @Nullable [] getBytes​(java.lang.String fieldName)
      Get a Schema.TypeName.BYTES value by field name, IllegalStateException is thrown if schema doesn't match.
      @Nullable org.joda.time.ReadableDateTime getDateTime​(int idx)
      Get a Schema.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 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 extends @Nullable java.lang.Object>
      T
      getLogicalTypeValue​(int idx, java.lang.Class<T> clazz)
      Returns the Logical Type input type for this field.
      <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.
      <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 extends @Nullable java.lang.Object>
      T
      getValue​(int fieldIdx)
      Get value by field index, ClassCastException is thrown if schema doesn't match.
      <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.
      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 a Row from the list of values and getSchema().
      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 specified getSchema().
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 a Schema.TypeName.BYTE value by field name, IllegalStateException is thrown if schema doesn't match.
      • getBytes

        public byte @Nullable [] getBytes​(java.lang.String fieldName)
        Get a Schema.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 a Schema.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 a Schema.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 a Schema.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 a Schema.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 a Schema.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 a Schema.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 a Schema.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 a Schema.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 a Schema.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 a Schema.TypeName.ROW value by field name, IllegalStateException is thrown if schema doesn't match.
      • getByte

        public @Nullable java.lang.Byte getByte​(int idx)
        Get a Schema.TypeName.BYTE value by field index, ClassCastException is thrown if schema doesn't match.
      • getBytes

        public byte @Nullable [] getBytes​(int idx)
        Get a Schema.TypeName.BYTES value by field index, ClassCastException is thrown if schema doesn't match.
      • getInt16

        public @Nullable java.lang.Short getInt16​(int idx)
        Get a Schema.TypeName.INT16 value by field index, ClassCastException is thrown if schema doesn't match.
      • getInt32

        public @Nullable java.lang.Integer getInt32​(int idx)
        Get a Schema.TypeName.INT32 value by field index, ClassCastException is thrown if schema doesn't match.
      • getFloat

        public @Nullable java.lang.Float getFloat​(int idx)
        Get a Schema.TypeName.FLOAT value by field index, ClassCastException is thrown if schema doesn't match.
      • getDouble

        public @Nullable java.lang.Double getDouble​(int idx)
        Get a Schema.TypeName.DOUBLE value by field index, ClassCastException is thrown if schema doesn't match.
      • getInt64

        public @Nullable java.lang.Long getInt64​(int idx)
        Get a Schema.TypeName.INT64 value by field index, ClassCastException is thrown if schema doesn't match.
      • getString

        public @Nullable java.lang.String getString​(int idx)
        Get a String value by field index, ClassCastException is thrown if schema doesn't match.
      • getDateTime

        public @Nullable org.joda.time.ReadableDateTime getDateTime​(int idx)
        Get a Schema.TypeName.DATETIME value by field index, IllegalStateException is thrown if schema doesn't match.
      • getDecimal

        public @Nullable java.math.BigDecimal getDecimal​(int idx)
        Get a BigDecimal value by field index, ClassCastException is thrown if schema doesn't match.
      • getBoolean

        public @Nullable java.lang.Boolean getBoolean​(int idx)
        Get a Boolean 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 a Row value by field index, IllegalStateException is thrown if schema doesn't match.
      • getSchema

        public Schema getSchema()
        Return Schema which describes the fields.
      • equals

        public boolean equals​(@Nullable java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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 specified 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.
      • toRow

        public 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().
      • nullRow

        public static Row nullRow​(Schema schema)
        Creates a new record filled with nulls.