Class Value

public abstract class Value implements Serializable

Represents a value to be consumed by the Cloud Spanner API. A value can be NULL or non-NULL; regardless, values always have an associated type.

The Value API is optimized for construction, since this is the majority use-case when using this class with the Cloud Spanner libraries. The factory method signatures and internal representations are design to minimize memory usage and object creation while still maintaining the immutability contract of this class. In particular, arrays of primitive types can be constructed without requiring boxing into collections of wrapper types. The getters in this class are intended primarily for test purposes, and so do not share the same performance characteristics; in particular, getters for array types may be expensive.

Value instances are immutable.

Inheritance

java.lang.Object > Value

Implements

Serializable

Static Fields

COMMIT_TIMESTAMP

public static final Timestamp COMMIT_TIMESTAMP

Placeholder value to be passed to a mutation to make Cloud Spanner store the commit timestamp in that column. The commit timestamp is the timestamp corresponding to when Cloud Spanner commits the transaction containing the mutation.

Note that this particular timestamp instance has no semantic meaning. In particular the value of seconds and nanoseconds in this timestamp are meaningless. This placeholder can only be used for columns that have set the option "(allow_commit_timestamp=true)" in the schema.

When reading the value stored in such a column, the value returned is an actual timestamp corresponding to the commit time of the transaction, which has no relation to this placeholder. See Also: Transaction Semantics

Field Value
TypeDescription
com.google.cloud.Timestamp

NAN

public static final String NAN

Constant to specify a PG Numeric NaN value.

Field Value
TypeDescription
String

Static Methods

bool(boolean v)

public static Value bool(boolean v)

Returns a BOOL value.

Parameter
NameDescription
vboolean
Returns
TypeDescription
Value

bool(Boolean v)

public static Value bool(Boolean v)

Returns a BOOL value.

Parameter
NameDescription
vBoolean

the value, which may be null

Returns
TypeDescription
Value

boolArray(boolean[] v)

public static Value boolArray(boolean[] v)

Returns an ARRAY<BOOL> value.

Parameter
NameDescription
vboolean[]

the source of element values, which may be null to produce a value for which isNull() is true

Returns
TypeDescription
Value

boolArray(boolean[] v, int pos, int length)

public static Value boolArray(boolean[] v, int pos, int length)

Returns an ARRAY<BOOL> value that takes its elements from a region of an array.

Parameters
NameDescription
vboolean[]

the source of element values, which may be null to produce a value for which isNull() is true

posint

the start position of v to copy values from. Ignored if v is null.

lengthint

the number of values to copy from v. Ignored if v is null.

Returns
TypeDescription
Value

boolArray(Iterable<Boolean> v)

public static Value boolArray(Iterable<Boolean> v)

Returns an ARRAY<BOOL> value.

Parameter
NameDescription
vIterable<Boolean>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

bytes(ByteArray v)

public static Value bytes(ByteArray v)

Returns a BYTES value.

Parameter
NameDescription
vcom.google.cloud.ByteArray

the value, which may be null

Returns
TypeDescription
Value

bytesArray(Iterable<ByteArray> v)

public static Value bytesArray(Iterable<ByteArray> v)

Returns an ARRAY<BYTES> value.

Parameter
NameDescription
vIterable<com.google.cloud.ByteArray>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

date(Date v)

public static Value date(Date v)

Returns a DATE value. The range [1678-01-01, 2262-01-01) is the legal interval for cloud spanner dates. A write to a date column is rejected if the value is outside of that interval.

Parameter
NameDescription
vcom.google.cloud.Date
Returns
TypeDescription
Value

dateArray(Iterable<Date> v)

public static Value dateArray(Iterable<Date> v)

Returns an ARRAY<DATE> value. The range [1678-01-01, 2262-01-01) is the legal interval for cloud spanner dates. A write to a date column is rejected if the value is outside of that interval.

Parameter
NameDescription
vIterable<com.google.cloud.Date>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

float64(double v)

public static Value float64(double v)

Returns a FLOAT64 value.

Parameter
NameDescription
vdouble
Returns
TypeDescription
Value

float64(Double v)

public static Value float64(Double v)

Returns a FLOAT64 value.

Parameter
NameDescription
vDouble

the value, which may be null

Returns
TypeDescription
Value

float64Array(double[] v)

public static Value float64Array(double[] v)

Returns an ARRAY<FLOAT64> value.

Parameter
NameDescription
vdouble[]

the source of element values, which may be null to produce a value for which isNull() is true

Returns
TypeDescription
Value

float64Array(double[] v, int pos, int length)

public static Value float64Array(double[] v, int pos, int length)

Returns an ARRAY<FLOAT64> value that takes its elements from a region of an array.

Parameters
NameDescription
vdouble[]

the source of element values, which may be null to produce a value for which isNull() is true

posint

the start position of v to copy values from. Ignored if v is null.

lengthint

the number of values to copy from v. Ignored if v is null.

Returns
TypeDescription
Value

float64Array(Iterable<Double> v)

public static Value float64Array(Iterable<Double> v)

Returns an ARRAY<FLOAT64> value.

Parameter
NameDescription
vIterable<Double>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

int64(Long v)

public static Value int64(Long v)

Returns an INT64 value.

Parameter
NameDescription
vLong

the value, which may be null

Returns
TypeDescription
Value

int64(long v)

public static Value int64(long v)

Returns an INT64 value.

Parameter
NameDescription
vlong
Returns
TypeDescription
Value

int64Array(Iterable<Long> v)

public static Value int64Array(Iterable<Long> v)

Returns an ARRAY<INT64> value.

Parameter
NameDescription
vIterable<Long>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

int64Array(long[] v)

public static Value int64Array(long[] v)

Returns an ARRAY<INT64> value.

Parameter
NameDescription
vlong[]

the source of element values, which may be null to produce a value for which isNull() is true

Returns
TypeDescription
Value

int64Array(long[] v, int pos, int length)

public static Value int64Array(long[] v, int pos, int length)

Returns an ARRAY<INT64> value that takes its elements from a region of an array.

Parameters
NameDescription
vlong[]

the source of element values, which may be null to produce a value for which isNull() is true

posint

the start position of v to copy values from. Ignored if v is null.

lengthint

the number of values to copy from v. Ignored if v is null.

Returns
TypeDescription
Value

json(String v)

public static Value json(String v)

Returns a STRING value.

Parameter
NameDescription
vString

the value, which may be null

Returns
TypeDescription
Value

jsonArray(Iterable<String> v)

public static Value jsonArray(Iterable<String> v)

Returns an ARRAY<STRING> value.

Parameter
NameDescription
vIterable<String>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

numeric(BigDecimal v)

public static Value numeric(BigDecimal v)

Returns a NUMERIC value. The valid value range for the whole component of the BigDecimal is from -9,999,999,999,999,999,999,999,999 to +9,999,999,999,999,999,999,999,999 (both inclusive), i.e. the max length of the whole component is 29 digits. The max length of the fractional part is 9 digits. Trailing zeros in the fractional part are not considered and will be lost, as Cloud Spanner does not preserve the precision of a numeric value.

If you set a numeric value of a record to for example 0.10, Cloud Spanner will return this value as 0.1 in subsequent queries. Use BigDecimal#stripTrailingZeros() to compare inserted values with retrieved values if your application might insert numeric values with trailing zeros.

Parameter
NameDescription
vBigDecimal

the value, which may be null

Returns
TypeDescription
Value

numericArray(Iterable<BigDecimal> v)

public static Value numericArray(Iterable<BigDecimal> v)

Returns an ARRAY<NUMERIC> value.

Parameter
NameDescription
vIterable<BigDecimal>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

pgNumeric(String v)

public static Value pgNumeric(String v)

Returns a PG NUMERIC value. This value has flexible precision and scale which is specified in the Database DDL. This value also supports NaNs, which can be specified with Value.pgNumeric(Value.NAN) or simply as Value.pgNumeric("NaN").

Note that this flavour of numeric is different than Spanner numerics (Value#numeric(BigDecimal)). It should be used only for handling numerics in the PostgreSQL dialect.

Parameter
NameDescription
vString

the value, which may be null

Returns
TypeDescription
Value

pgNumericArray(Iterable<String> v)

public static Value pgNumericArray(Iterable<String> v)

Returns an ARRAY<PG_NUMERIC> value.

Parameter
NameDescription
vIterable<String>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null. Individual elements may be "NaN" or Value#NAN.

Returns
TypeDescription
Value

string(String v)

public static Value string(String v)

Returns a STRING value.

Parameter
NameDescription
vString

the value, which may be null

Returns
TypeDescription
Value

stringArray(Iterable<String> v)

public static Value stringArray(Iterable<String> v)

Returns an ARRAY<STRING> value.

Parameter
NameDescription
vIterable<String>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

struct(Struct v)

public static Value struct(Struct v)

Returns a non-NULL {#code STRUCT} value.

Parameter
NameDescription
vStruct
Returns
TypeDescription
Value

struct(Type type, Struct v)

public static Value struct(Type type, Struct v)

Returns a STRUCT value of Type type.

Parameters
NameDescription
typeType

the type of the STRUCT value

vStruct

the struct STRUCT value. This may be null to produce a value for which isNull() is true. If non-null, Struct#getType() must match type.

Returns
TypeDescription
Value

structArray(Type elementType, Iterable<Struct> v)

public static Value structArray(Type elementType, Iterable<Struct> v)

Returns an ARRAY<STRUCT<...>> value.

Parameters
NameDescription
elementTypeType
vIterable<Struct>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

timestamp(Timestamp v)

public static Value timestamp(Timestamp v)

Returns a TIMESTAMP value.

Parameter
NameDescription
vcom.google.cloud.Timestamp
Returns
TypeDescription
Value

timestampArray(Iterable<Timestamp> v)

public static Value timestampArray(Iterable<Timestamp> v)

Returns an ARRAY<TIMESTAMP> value.

Parameter
NameDescription
vIterable<com.google.cloud.Timestamp>

the source of element values. This may be null to produce a value for which isNull() is true. Individual elements may also be null.

Returns
TypeDescription
Value

untyped(Value value)

public static Value untyped(Value value)

Returns a Value that wraps the given proto value. This can be used to construct a value without a specific type, and let the backend infer the type based on the statement where it is used.

Parameter
NameDescription
valueValue

the non-null proto value (a NullValue is allowed)

Returns
TypeDescription
Value

Methods

getBool()

public abstract boolean getBool()

Returns the value of a BOOL-typed instance.

Returns
TypeDescription
boolean

getBoolArray()

public abstract List<Boolean> getBoolArray()

Returns the value of an ARRAY<BOOL>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<Boolean>

getBytes()

public abstract ByteArray getBytes()

Returns the value of a BYTES-typed instance.

Returns
TypeDescription
com.google.cloud.ByteArray

getBytesArray()

public abstract List<ByteArray> getBytesArray()

Returns the value of an ARRAY<BYTES>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<com.google.cloud.ByteArray>

getDate()

public abstract Date getDate()

Returns the value of a DATE-typed instance.

Returns
TypeDescription
com.google.cloud.Date

getDateArray()

public abstract List<Date> getDateArray()

Returns the value of an ARRAY<DATE>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<com.google.cloud.Date>

getFloat64()

public abstract double getFloat64()

Returns the value of a FLOAT64-typed instance.

Returns
TypeDescription
double

getFloat64Array()

public abstract List<Double> getFloat64Array()

Returns the value of an ARRAY<FLOAT64>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<Double>

getInt64()

public abstract long getInt64()

Returns the value of a INT64-typed instance.

Returns
TypeDescription
long

getInt64Array()

public abstract List<Long> getInt64Array()

Returns the value of an ARRAY<INT64>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<Long>

getJson()

public String getJson()

Returns the value of a JSON-typed instance.

Returns
TypeDescription
String

getJsonArray()

public List<String> getJsonArray()

Returns the value of an ARRAY<JSON>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<String>

getNumeric()

public abstract BigDecimal getNumeric()

Returns the value of a NUMERIC-typed instance.

Returns
TypeDescription
BigDecimal

getNumericArray()

public abstract List<BigDecimal> getNumericArray()

Returns the value of an ARRAY<NUMERIC>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<BigDecimal>

getString()

public abstract String getString()

Returns the value of a STRING-typed instance.

Returns
TypeDescription
String

getStringArray()

public abstract List<String> getStringArray()

Returns the value of an ARRAY<STRING>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<String>

getStruct()

public abstract Struct getStruct()

Returns the value of a STRUCT-typed instance.

Returns
TypeDescription
Struct

getStructArray()

public abstract List<Struct> getStructArray()

Returns the value of an ARRAY<STRUCT<...>>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<Struct>

getTimestamp()

public abstract Timestamp getTimestamp()

Returns the value of a TIMESTAMP-typed instance.

Returns
TypeDescription
com.google.cloud.Timestamp

getTimestampArray()

public abstract List<Timestamp> getTimestampArray()

Returns the value of an ARRAY<TIMESTAMP>-typed instance. While the returned list itself will never be null, elements of that list may be null.

Returns
TypeDescription
List<com.google.cloud.Timestamp>

getType()

public abstract Type getType()

Returns the type of this value. This will return a type even if isNull() is true.

Returns
TypeDescription
Type

isCommitTimestamp()

public abstract boolean isCommitTimestamp()

Returns true if this is a commit timestamp value.

Returns
TypeDescription
boolean

isNull()

public abstract boolean isNull()

Returns true if this instance represents a NULL value.

Returns
TypeDescription
boolean

toString()

public String toString()
Returns
TypeDescription
String
Overrides