Class Type

  • All Implemented Interfaces:
    Serializable

    @Immutable
    public final class Type
    extends Object
    implements Serializable
    Describes a type in the Cloud Spanner type system. Types can either be primitive (for example, INT64 and STRING) or composite (for example, ARRAY<INT64> or STRUCT<INT64,STRING>).

    Type instances are immutable.

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Type.Code
      Enumerates the categories of types.
      static class  Type.StructField
      Describes an individual field in a STRUCT type.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Type array​(Type elementType)
      Returns a descriptor for an array of elementType.
      static Type bool()
      Returns the descriptor for the BOOL type.
      static Type bytes()
      Returns the descriptor for the BYTES type: a variable-length byte string.
      static Type date()
      Returns the descriptor for the DATE type: a timezone independent date in the range [0001-01-01, 9999-12-31).
      boolean equals​(Object o)  
      static Type float64()
      Returns the descriptor for the FLOAT64 type: a floating point type with the same value domain as a Java {code double}.
      Type getArrayElementType()
      Returns the type descriptor for elements of this ARRAY type.
      Type.Code getCode()
      Returns the type code corresponding to this type.
      int getFieldIndex​(String fieldName)
      Returns the index of the field named fieldName in this STRUCT type.
      List<Type.StructField> getStructFields()
      Returns the fields of this STRUCT type.
      int hashCode()  
      static Type int64()
      Returns the descriptor for the INT64 type: an integral type with the same value domain as a Java long.
      static Type json()
      Returns the descriptor for the JSON type.
      static Type numeric()
      Returns the descriptor for the NUMERIC type.
      static Type pgJsonb()
      Returns the descriptor for the JSONB type.
      static Type pgNumeric()
      Returns the descriptor for the NUMERIC type with the PG_NUMERIC type annotation.
      static Type string()
      Returns the descriptor for the STRING type: a variable-length Unicode character string.
      static Type struct​(Type.StructField... fields)
      Returns a descriptor for a STRUCT type: an ordered collection of named and typed fields.
      static Type struct​(Iterable<Type.StructField> fields)
      Returns a descriptor for a STRUCT type: an ordered collection of named and typed fields.
      static Type timestamp()
      Returns the descriptor for the TIMESTAMP type: a nano precision timestamp in the range [0000-01-01 00:00:00, 9999-12-31 23:59:59.999999999 UTC].
      String toString()  
    • Method Detail

      • bool

        public static Type bool()
        Returns the descriptor for the BOOL type.
      • int64

        public static Type int64()
        Returns the descriptor for the INT64 type: an integral type with the same value domain as a Java long.
      • float64

        public static Type float64()
        Returns the descriptor for the FLOAT64 type: a floating point type with the same value domain as a Java {code double}.
      • numeric

        public static Type numeric()
        Returns the descriptor for the NUMERIC type.
      • pgNumeric

        public static Type pgNumeric()
        Returns the descriptor for the NUMERIC type with the PG_NUMERIC type annotation.
      • string

        public static Type string()
        Returns the descriptor for the STRING type: a variable-length Unicode character string.
      • json

        public static Type json()
        Returns the descriptor for the JSON type.
      • pgJsonb

        public static Type pgJsonb()
        Returns the descriptor for the JSONB type.
      • bytes

        public static Type bytes()
        Returns the descriptor for the BYTES type: a variable-length byte string.
      • timestamp

        public static Type timestamp()
        Returns the descriptor for the TIMESTAMP type: a nano precision timestamp in the range [0000-01-01 00:00:00, 9999-12-31 23:59:59.999999999 UTC].
      • date

        public static Type date()
        Returns the descriptor for the DATE type: a timezone independent date in the range [0001-01-01, 9999-12-31).
      • array

        public static Type array​(Type elementType)
        Returns a descriptor for an array of elementType.
      • struct

        public static Type struct​(Iterable<Type.StructField> fields)
        Returns a descriptor for a STRUCT type: an ordered collection of named and typed fields.
      • struct

        public static Type struct​(Type.StructField... fields)
        Returns a descriptor for a STRUCT type: an ordered collection of named and typed fields.
      • getCode

        public Type.Code getCode()
        Returns the type code corresponding to this type.
      • getArrayElementType

        public Type getArrayElementType()
        Returns the type descriptor for elements of this ARRAY type.
        Throws:
        IllegalStateException - if code() != Code.ARRAY
      • getStructFields

        public List<Type.StructField> getStructFields()
        Returns the fields of this STRUCT type.
        Returns:
        an immutable list of the fields
        Throws:
        IllegalStateException - if code() != Code.STRUCT
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object