@Immutable public abstract class Value extends Object implements Serializable
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.
Modifier and Type | Field and Description |
---|---|
static com.google.cloud.Timestamp |
COMMIT_TIMESTAMP
Placeholder value to be passed to a mutation to make Cloud Spanner store the commit timestamp
in that column.
|
Modifier and Type | Method and Description |
---|---|
static Value |
bool(boolean v)
Returns a
BOOL value. |
static Value |
bool(Boolean v)
Returns a
BOOL value. |
static Value |
boolArray(boolean[] v)
Returns an
ARRAY<BOOL> value. |
static Value |
boolArray(boolean[] v,
int pos,
int length)
Returns an
ARRAY<BOOL> value that takes its elements from a region of an array. |
static Value |
boolArray(Iterable<Boolean> v)
Returns an
ARRAY<BOOL> value. |
static Value |
bytes(com.google.cloud.ByteArray v)
Returns a
BYTES value. |
static Value |
bytesArray(Iterable<com.google.cloud.ByteArray> v)
Returns an
ARRAY<BYTES> value. |
static Value |
date(com.google.cloud.Date v)
Returns a
DATE value. |
static Value |
dateArray(Iterable<com.google.cloud.Date> v)
Returns an
ARRAY<DATE> value. |
static Value |
float64(double v)
Returns a
FLOAT64 value. |
static Value |
float64(Double v)
Returns a
FLOAT64 value. |
static Value |
float64Array(double[] v)
Returns an
ARRAY<FLOAT64> value. |
static Value |
float64Array(double[] v,
int pos,
int length)
Returns an
ARRAY<FLOAT64> value that takes its elements from a region of an array. |
static Value |
float64Array(Iterable<Double> v)
Returns an
ARRAY<FLOAT64> value. |
abstract boolean |
getBool()
Returns the value of a
BOOL -typed instance. |
abstract List<Boolean> |
getBoolArray()
Returns the value of an
ARRAY<BOOL> -typed instance. |
abstract com.google.cloud.ByteArray |
getBytes()
Returns the value of a
BYTES -typed instance. |
abstract List<com.google.cloud.ByteArray> |
getBytesArray()
Returns the value of an
ARRAY<BYTES> -typed instance. |
abstract com.google.cloud.Date |
getDate()
Returns the value of a
DATE -typed instance. |
abstract List<com.google.cloud.Date> |
getDateArray()
Returns the value of an
ARRAY<DATE> -typed instance. |
abstract double |
getFloat64()
Returns the value of a
FLOAT64 -typed instance. |
abstract List<Double> |
getFloat64Array()
Returns the value of an
ARRAY<FLOAT64> -typed instance. |
abstract long |
getInt64()
Returns the value of a
INT64 -typed instance. |
abstract List<Long> |
getInt64Array()
Returns the value of an
ARRAY<INT64> -typed instance. |
String |
getJson()
Returns the value of a
JSON -typed instance. |
List<String> |
getJsonArray()
Returns the value of an
ARRAY<JSON> -typed instance. |
abstract BigDecimal |
getNumeric()
Returns the value of a
NUMERIC -typed instance. |
abstract List<BigDecimal> |
getNumericArray()
Returns the value of an
ARRAY<NUMERIC> -typed instance. |
abstract String |
getString()
Returns the value of a
STRING -typed instance. |
abstract List<String> |
getStringArray()
Returns the value of an
ARRAY<STRING> -typed instance. |
abstract Struct |
getStruct()
Returns the value of a
STRUCT -typed instance. |
abstract List<Struct> |
getStructArray()
Returns the value of an
ARRAY<STRUCT<...>> -typed instance. |
abstract com.google.cloud.Timestamp |
getTimestamp()
Returns the value of a
TIMESTAMP -typed instance. |
abstract List<com.google.cloud.Timestamp> |
getTimestampArray()
Returns the value of an
ARRAY<TIMESTAMP> -typed instance. |
abstract Type |
getType()
Returns the type of this value.
|
static Value |
int64(long v)
Returns an
INT64 value. |
static Value |
int64(Long v)
Returns an
INT64 value. |
static Value |
int64Array(Iterable<Long> v)
Returns an
ARRAY<INT64> value. |
static Value |
int64Array(long[] v)
Returns an
ARRAY<INT64> value. |
static Value |
int64Array(long[] v,
int pos,
int length)
Returns an
ARRAY<INT64> value that takes its elements from a region of an array. |
abstract boolean |
isCommitTimestamp()
Returns true if this is a commit timestamp value.
|
abstract boolean |
isNull()
Returns
true if this instance represents a NULL value. |
static Value |
json(String v)
Returns a
STRING value. |
static Value |
jsonArray(Iterable<String> v)
Returns an
ARRAY<STRING> value. |
static Value |
numeric(BigDecimal v)
Returns a
NUMERIC value. |
static Value |
numericArray(Iterable<BigDecimal> v)
Returns an
ARRAY<NUMERIC> value. |
static Value |
string(String v)
Returns a
STRING value. |
static Value |
stringArray(Iterable<String> v)
Returns an
ARRAY<STRING> value. |
static Value |
struct(Struct v)
Returns a non-
NULL {#code STRUCT} value. |
static Value |
struct(Type type,
Struct v)
Returns a
STRUCT value of Type type. |
static Value |
structArray(Type elementType,
Iterable<Struct> v)
Returns an
ARRAY<STRUCT<...>> value. |
static Value |
timestamp(com.google.cloud.Timestamp v)
Returns a
TIMESTAMP value. |
static Value |
timestampArray(Iterable<com.google.cloud.Timestamp> v)
Returns an
ARRAY<TIMESTAMP> value. |
String |
toString() |
public static final com.google.cloud.Timestamp COMMIT_TIMESTAMP
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.
public static Value bool(@Nullable Boolean v)
BOOL
value.v
- the value, which may be nullpublic static Value bool(boolean v)
BOOL
value.public static Value int64(@Nullable Long v)
INT64
value.v
- the value, which may be nullpublic static Value int64(long v)
INT64
value.public static Value float64(@Nullable Double v)
FLOAT64
value.v
- the value, which may be nullpublic static Value float64(double v)
FLOAT64
value.public static Value numeric(@Nullable BigDecimal v)
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.
v
- the value, which may be nullpublic static Value string(@Nullable String v)
STRING
value.v
- the value, which may be nullpublic static Value json(@Nullable String v)
STRING
value.v
- the value, which may be nullpublic static Value bytes(@Nullable com.google.cloud.ByteArray v)
BYTES
value.v
- the value, which may be nullpublic static Value timestamp(@Nullable com.google.cloud.Timestamp v)
TIMESTAMP
value.public static Value date(@Nullable com.google.cloud.Date v)
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.public static Value struct(Type type, @Nullable Struct v)
STRUCT
value of Type
type.type
- the type of the STRUCT
valuev
- the struct STRUCT
value. This may be null
to produce a value for which
isNull()
is true
. If non-null
, StructReader.getType()
must match
type.public static Value boolArray(@Nullable boolean[] v)
ARRAY<BOOL>
value.v
- the source of element values, which may be null to produce a value for which isNull()
is true
public static Value boolArray(@Nullable boolean[] v, int pos, int length)
ARRAY<BOOL>
value that takes its elements from a region of an array.v
- the source of element values, which may be null to produce a value for which isNull()
is true
pos
- the start position of v
to copy values from. Ignored if v
is null
.length
- the number of values to copy from v
. Ignored if v
is null
.public static Value boolArray(@Nullable Iterable<Boolean> v)
ARRAY<BOOL>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value int64Array(@Nullable long[] v)
ARRAY<INT64>
value.v
- the source of element values, which may be null to produce a value for which isNull()
is true
public static Value int64Array(@Nullable long[] v, int pos, int length)
ARRAY<INT64>
value that takes its elements from a region of an array.v
- the source of element values, which may be null to produce a value for which isNull()
is true
pos
- the start position of v
to copy values from. Ignored if v
is null
.length
- the number of values to copy from v
. Ignored if v
is null
.public static Value int64Array(@Nullable Iterable<Long> v)
ARRAY<INT64>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value float64Array(@Nullable double[] v)
ARRAY<FLOAT64>
value.v
- the source of element values, which may be null to produce a value for which isNull()
is true
public static Value float64Array(@Nullable double[] v, int pos, int length)
ARRAY<FLOAT64>
value that takes its elements from a region of an array.v
- the source of element values, which may be null to produce a value for which isNull()
is true
pos
- the start position of v
to copy values from. Ignored if v
is null
.length
- the number of values to copy from v
. Ignored if v
is null
.public static Value float64Array(@Nullable Iterable<Double> v)
ARRAY<FLOAT64>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value numericArray(@Nullable Iterable<BigDecimal> v)
ARRAY<NUMERIC>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value stringArray(@Nullable Iterable<String> v)
ARRAY<STRING>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value jsonArray(@Nullable Iterable<String> v)
ARRAY<STRING>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value bytesArray(@Nullable Iterable<com.google.cloud.ByteArray> v)
ARRAY<BYTES>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value timestampArray(@Nullable Iterable<com.google.cloud.Timestamp> v)
ARRAY<TIMESTAMP>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value dateArray(@Nullable Iterable<com.google.cloud.Date> v)
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.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value structArray(Type elementType, @Nullable Iterable<Struct> v)
ARRAY<STRUCT<...>>
value.elementType
- v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public abstract Type getType()
isNull()
is true.public abstract boolean isNull()
true
if this instance represents a NULL
value.public abstract boolean getBool()
BOOL
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract long getInt64()
INT64
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract double getFloat64()
FLOAT64
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract BigDecimal getNumeric()
NUMERIC
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract String getString()
STRING
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic String getJson()
JSON
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract com.google.cloud.ByteArray getBytes()
BYTES
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract com.google.cloud.Timestamp getTimestamp()
TIMESTAMP
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected type or
isCommitTimestamp()
.public abstract boolean isCommitTimestamp()
public abstract com.google.cloud.Date getDate()
DATE
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract Struct getStruct()
STRUCT
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<Boolean> getBoolArray()
ARRAY<BOOL>
-typed instance. While the returned list itself will
never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<Long> getInt64Array()
ARRAY<INT64>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<Double> getFloat64Array()
ARRAY<FLOAT64>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<BigDecimal> getNumericArray()
ARRAY<NUMERIC>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<String> getStringArray()
ARRAY<STRING>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic List<String> getJsonArray()
ARRAY<JSON>
-typed instance. While the returned list itself will
never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<com.google.cloud.ByteArray> getBytesArray()
ARRAY<BYTES>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<com.google.cloud.Timestamp> getTimestampArray()
ARRAY<TIMESTAMP>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<com.google.cloud.Date> getDateArray()
ARRAY<DATE>
-typed instance. While the returned list itself will
never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<Struct> getStructArray()
ARRAY<STRUCT<...>>
-typed instance. While the returned list
itself will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typeCopyright © 2021 Google LLC. All rights reserved.