Package com.google.cloud.spanner
Class Type
- java.lang.Object
-
- com.google.cloud.spanner.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
andSTRING
) or composite (for example,ARRAY<INT64>
orSTRUCT<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 aSTRUCT 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 ofelementType
.static Type
bool()
Returns the descriptor for theBOOL type
.static Type
bytes()
Returns the descriptor for theBYTES
type: a variable-length byte string.static Type
date()
Returns the descriptor for theDATE
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 theFLOAT64
type: a floating point type with the same value domain as a Java {code double}.Type
getArrayElementType()
Returns the type descriptor for elements of thisARRAY
type.Type.Code
getCode()
Returns the type code corresponding to this type.int
getFieldIndex(String fieldName)
Returns the index of the field namedfieldName
in thisSTRUCT
type.List<Type.StructField>
getStructFields()
Returns the fields of thisSTRUCT
type.int
hashCode()
static Type
int64()
Returns the descriptor for theINT64
type: an integral type with the same value domain as a Javalong
.static Type
json()
Returns the descriptor for theJSON
type.static Type
numeric()
Returns the descriptor for theNUMERIC
type.static Type
pgJsonb()
Returns the descriptor for theJSONB
type.static Type
pgNumeric()
Returns the descriptor for theNUMERIC
type with thePG_NUMERIC
type annotation.static Type
string()
Returns the descriptor for theSTRING
type: a variable-length Unicode character string.static Type
struct(Type.StructField... fields)
Returns a descriptor for aSTRUCT
type: an ordered collection of named and typed fields.static Type
struct(Iterable<Type.StructField> fields)
Returns a descriptor for aSTRUCT
type: an ordered collection of named and typed fields.static Type
timestamp()
Returns the descriptor for theTIMESTAMP
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 theBOOL type
.
-
int64
public static Type int64()
Returns the descriptor for theINT64
type: an integral type with the same value domain as a Javalong
.
-
float64
public static Type float64()
Returns the descriptor for theFLOAT64
type: a floating point type with the same value domain as a Java {code double}.
-
numeric
public static Type numeric()
Returns the descriptor for theNUMERIC
type.
-
pgNumeric
public static Type pgNumeric()
Returns the descriptor for theNUMERIC
type with thePG_NUMERIC
type annotation.
-
string
public static Type string()
Returns the descriptor for theSTRING
type: a variable-length Unicode character string.
-
json
public static Type json()
Returns the descriptor for theJSON
type.
-
pgJsonb
public static Type pgJsonb()
Returns the descriptor for theJSONB
type.
-
bytes
public static Type bytes()
Returns the descriptor for theBYTES
type: a variable-length byte string.
-
timestamp
public static Type timestamp()
Returns the descriptor for theTIMESTAMP
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 theDATE
type: a timezone independent date in the range [0001-01-01, 9999-12-31).
-
struct
public static Type struct(Iterable<Type.StructField> fields)
Returns a descriptor for aSTRUCT
type: an ordered collection of named and typed fields.
-
struct
public static Type struct(Type.StructField... fields)
Returns a descriptor for aSTRUCT
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 thisARRAY
type.- Throws:
IllegalStateException
- ifcode() != Code.ARRAY
-
getStructFields
public List<Type.StructField> getStructFields()
Returns the fields of thisSTRUCT
type.- Returns:
- an immutable list of the fields
- Throws:
IllegalStateException
- ifcode() != Code.STRUCT
-
getFieldIndex
public int getFieldIndex(String fieldName)
Returns the index of the field namedfieldName
in thisSTRUCT
type.- Throws:
IllegalArgumentException
- if there is not exactly one element ofgetStructFields()
withType.StructField.getName()
equal tofieldName
IllegalStateException
- ifcode() != Code.STRUCT
-
-