Class Schema.Field

java.lang.Object
com.streambase.sb.Schema.Field
All Implemented Interfaces:
Serializable
Enclosing class:
Schema

public static class Schema.Field extends Object implements Serializable
Information (name, type, and optionally size) about a field in a Schema.

A field can be looked up within a schema in three ways:

  1. By index: By the zero-based ordinal position of the field within the schema
  2. By simple name: By the name of the field itself (e.g., "myint")
  3. By path name: By a dot-separated list of names that define a path through a set of nested schemas that arise through the use of fields of type Tuple (e.g., "mynestedtuple.myint").

A Field object can be used to obtain the value of a field in a tuple. However, there are rules that must be obeyed in doing so. For example, one must obtain the Field object from a Schema object that describes the schema of the tuple (i.e., as opposed to directly from a Field constructor).

See the "client" StreamBase sample (streambase-install-dir/sample/client) for examples of proper use of Field objects.

Note: Serializations of instances of this class that are created (e.g., by using ObjectOutputStream) in one version of StreamBase in general will not be deserializable in any other version of StreamBase.

See Also:
  • Constructor Details

    • Field

      public Field(String name, CompleteDataType completeType, com.streambase.sb.util.Location loc)
      Constructor
      Parameters:
      name - Field name
      completeType - Field data type
      loc - Source location
    • Field

      public Field(Schema.Field field)
      Construct a Field from an existing Field.
      Parameters:
      field - Field to copy data from
    • Field

      public Field(String name, Schema.Field field)
      Construct a Field from an existing Field, giving the new field a specified name
      Parameters:
      name - The name of the field
      field - Field to copy data from
    • Field

      @Deprecated public Field(String name, DataType dataType)
      Deprecated.
      Construct a Field of a specified type, giving the new field a specified name.
      Parameters:
      name - The name of the Field
      dataType - The DataType of the Field
      Throws:
      IllegalArgumentException - if dataType requires a schema or an element type
    • Field

      @Deprecated public Field(String name, DataType dataType, Schema s)
      Deprecated.
      Use Field(String, CompleteDataType) instead with new Schema(name, CompleteDataType.forTuple(s)), or Schema.createTupleField(String, Schema)
      Construct a Field of a specified type and bound to a specified schema, giving the new field a specified name.
      Parameters:
      name - The name of the Field
      dataType - The DataType of the Field
      s - The schema of the Field
      Throws:
      IllegalArgumentException - if dataType doesn't require a schema or requires an element type
  • Method Details

    • sanitizedField

      static Schema.Field sanitizedField(int index, CompleteDataType type)
      Create a sanitized field from the parameters, using cached string name if possible and bypassing identifier validation.
      Parameters:
      index - The index to create a field for
      type - The type of field
      Returns:
      A newly created field
    • getLocation

      public com.streambase.sb.util.Location getLocation()
      Get location
      Returns:
      Location
    • equalsNoCapture

      public boolean equalsNoCapture(Schema.Field other)
      Compare non-capture fields
      Parameters:
      other - Compare with this field
      Returns:
      true if equal
    • checkType

      @Deprecated public void checkType(DataType dataType) throws TupleException
      Check to make sure that the given type is the same as the type of this Field
      Parameters:
      dataType - The DataType to check
      Throws:
      TupleException - thrown when the types do not match
    • checkType

      public void checkType(CompleteDataType dataType) throws TupleException
      Check to make sure that the given type is the same as the type of this Field
      Parameters:
      dataType - The CompleteDataType to check
      Throws:
      TupleException - thrown when the types do not match
      Since:
      6.3.7
    • getDataType

      public DataType getDataType()
      Return the DataType of the Field
      Returns:
      DataType of the Field
    • getCompleteDataType

      public CompleteDataType getCompleteDataType()
      Return the CompleteDataType of the Field
      Returns:
      CompleteDataType of the Field
      Since:
      6.3
    • getName

      public String getName()
      Return the name of the Field. If the Field was constructed from a field path name, that path name is returned
      Returns:
      The name of the Field
    • getShortName

      public String getShortName()
      Return the last (which might be the only) segment of this Field
      Returns:
      the last segment of this Field
    • getIndex

      public int getIndex()
      Return the index of this field within the Schema
      Returns:
      The index of the field within the Schema
    • getSize

      public int getSize()
      Return the size of the field (in bytes) without any header information.
      Returns:
      The size of the Field in bytes (without header information)
    • getSchema

      public Schema getSchema()
      Return the schema for this field. Valid only if the type of the field is Tuple.
      Returns:
      The schema, or null if field type is not Tuple
      Since:
      6.0
    • getNestedField

      public Schema.Field getNestedField(String fieldPathName) throws TupleException
      Return a field that identifies a field in a nested tuple field. This method can be applied only to a field whose type is Tuple.
      Parameters:
      fieldPathName - the path name to the desired nested tuple field
      Returns:
      the field
      Throws:
      TupleException - if the field path name is invalid or this field isn't of type Tuple
      Since:
      6.0
    • getNestedFields

      public Schema.Field[] getNestedFields() throws TupleException
      Return an array of fields, each of which identifies a field in a nested tuple field. This method can be applied only to a field whose type is Tuple.
      Returns:
      the array of fields
      Throws:
      TupleException - if this field is not of type Tuple.
      Since:
      6.0
    • toString

      public String toString()
      Return a String representation of this field.
      Overrides:
      toString in class Object
      Returns:
      String representation of this Field
    • getDescription

      public String getDescription()
      Returns the description currently set for this field. At runtime this method will return null, and the description can only be guaranteed to have meaning during application development in the authoring environment.
      Returns:
      this field's description String null when unknown
    • setDescription

      public void setDescription(String description)
      Sets this field's description.
      Parameters:
      description - the description String for this field
    • getContainingSchema

      Schema getContainingSchema()
      Returns the schema of which this field is a part.
      Returns:
      the schema
    • getFieldPath

      List<Schema.Field> getFieldPath()
      Returns a list of Field's for navigating from this field's containing schema to the subtuple containing this field. If this field is "top-level" within the result is null.
      Returns:
      a list of Field's or null.
    • toPathlessField

      Schema.Field toPathlessField()
      Return a Field like this Field except with any field path stripped out. If this field has no path, it's what's returned.
      Returns:
      a simple Field
    • getElementType

      public CompleteDataType getElementType()
      Return the element type for this field. Valid only if the type of the field is List.
      Returns:
      The schema, or null if field type is not List
      Since:
      6.3