Interface SqlType<T>

Type Parameters:
T - the corresponding java type
All Superinterfaces:
Serializable
All Known Subinterfaces:
SqlType.Array<Elem>, SqlType.Map<K,V>, SqlType.Struct
All Known Implementing Classes:
Type.Array, Type.Bool, Type.Bytes, Type.Date, Type.Float32, Type.Float64, Type.Int64, Type.Map, Type.SchemalessStruct, Type.String, Type.StructWithSchema, Type.Timestamp

public interface SqlType<T> extends Serializable
Represents a data type in a SQL query.

Complex types (SqlType.Map, SqlType.Array, & SqlType.Struct provide additional information about the schema of the type.

  • Method Details

    • getCode

      SqlType.Code getCode()
      Returns:
      SqlType.Code enum for this type
    • bytes

      static SqlType<com.google.protobuf.ByteString> bytes()
      returns a SqlType for the BYTES type.
    • string

      static SqlType<String> string()
      returns a SqlType for the STRING type.
    • int64

      static SqlType<Long> int64()
      returns a SqlType for the INT64 type.
    • float64

      static SqlType<Double> float64()
      returns a SqlType for the FLOAT64 type.
    • float32

      static SqlType<Float> float32()
      returns a SqlType for the FLOAT32 type.
    • bool

      static SqlType<Boolean> bool()
      returns a SqlType for the BOOL type.
    • timestamp

      static SqlType<Instant> timestamp()
      returns a SqlType for the TIMESTAMP type.
    • date

      static SqlType<com.google.cloud.Date> date()
      returns a SqlType for the DATE type.
    • struct

      static SqlType.Struct struct()
      returns a fake STRUCT type for use on in StructReader methods that require a SqlType to validate against. This does not specify a schema because the struct schem will be validated on calls to the structs data accessors.

      Attempts to access the schema of a struct created this way will throw exceptions.

      Example usage:

      
         List<Struct> structList = resultSet.getList("column", SqlType.arrayOf(SqlType.struct()));
       
    • arrayOf

      static <Elem> SqlType.Array<Elem> arrayOf(SqlType<Elem> elemType)
      returns a SqlType for an ARRAY with elements of type elemType
    • mapOf

      static <K, V> SqlType.Map<K,V> mapOf(SqlType<K> keyType, SqlType<V> valType)
      returns a SqlType for a @code MAP} with keys of type keyType and values of type valType
    • historicalMap

      static SqlType.Map<com.google.protobuf.ByteString,List<Struct>> historicalMap()
      returns the SqlType for the type returned for column families in with_history queries. This is equivalent to SqlType.mapOf(SqlType.bytes(), SqlType.arrayOf(SqlType.struct()))
    • fromProto

      @InternalApi static SqlType<?> fromProto(Type proto)
      Creates a SqlType from the protobuf representation of Types.

      This is considered an internal implementation detail and not meant to be used by applications.

    • typesMatch

      @InternalApi static boolean typesMatch(SqlType<?> left, SqlType<?> right)
      This can be used to check whether StructReader get calls are being called for the correct type when compared to the schema. This is different that equals because we do not require users to specify the full struct schema for struct get calls. This is safe because the struct schema will be validated on calls to the struct.

      This is considered an internal implementation detail and not meant to be used by applications.