public interface StructReader
STRUCT
. The Cloud Spanner yields StructReader
instances as one of the subclasses ResultSet
or Struct
, most
commonly as the result of a read or query operation. At any point in time, a StructReader
provides access to a single tuple of data comprising multiple typed columns. Each column may have
a NULL
or non-NULL
value; in both cases, columns always have a type.
Column values are accessed using the getTypeName()
methods; a set of methods exists
for each Java type that a column may be read as, and depending on the type of the column, only a
subset of those methods will be appropriate. For example, getString(int)
and getString(String)
exist for reading columns of type Type.string()
; attempting to call
those methods for columns of other types will result in an IllegalStateException
. The
getTypeName()
methods should only be called for non-NULL
values, otherwise a
NullPointerException
is raised; isNull(int)
/isNull(String)
can be used
to test for NULL
-ness if necessary.
All methods for accessing a column have overloads that accept an int
column index and
a String
column name. Column indices are zero-based. The column name overloads will fail
with IllegalArgumentException
if the column name does not appear exactly once in this
instance's getType()
. The int
overloads are typically more efficient than their
String
counterparts.
StructReader
itself does not define whether the implementing type is mutable or
immutable. For example, ResultSet
is a mutable implementation of StructReader
,
where the StructReader
methods provide access to the row that the result set is currently
positioned over and ResultSet.next()
changes that view to the next row, whereas Struct
is an immutable implementation of StructReader
.
Modifier and Type | Method and Description |
---|---|
BigDecimal |
getBigDecimal(int columnIndex)
Returns the value of a non-
NULL column with type Type.numeric() . |
BigDecimal |
getBigDecimal(String columnName)
Returns the value of a non-
NULL column with type Type.numeric() . |
List<BigDecimal> |
getBigDecimalList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.numeric()) . |
List<BigDecimal> |
getBigDecimalList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.numeric()) . |
boolean |
getBoolean(int columnIndex)
Returns the value of a non-
NULL column with type Type.bool() . |
boolean |
getBoolean(String columnName)
Returns the value of a non-
NULL column with type Type.bool() . |
boolean[] |
getBooleanArray(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.bool()) . |
boolean[] |
getBooleanArray(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.bool()) . |
List<Boolean> |
getBooleanList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.bool()) . |
List<Boolean> |
getBooleanList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.bool()) . |
com.google.cloud.ByteArray |
getBytes(int columnIndex)
Returns the value of a non-
NULL column with type Type.bytes() . |
com.google.cloud.ByteArray |
getBytes(String columnName)
Returns the value of a non-
NULL column with type Type.bytes() . |
List<com.google.cloud.ByteArray> |
getBytesList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.bytes()) . |
List<com.google.cloud.ByteArray> |
getBytesList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.bytes()) . |
int |
getColumnCount()
Returns the number of columns in the underlying data.
|
int |
getColumnIndex(String columnName)
Returns the index of the column named
columnName . |
Type |
getColumnType(int columnIndex)
Returns the type of a column.
|
Type |
getColumnType(String columnName)
Returns the type of a column.
|
com.google.cloud.Date |
getDate(int columnIndex)
Returns the value of a non-
NULL column with type Type.date() . |
com.google.cloud.Date |
getDate(String columnName)
Returns the value of a non-
NULL column with type Type.date() . |
List<com.google.cloud.Date> |
getDateList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.date()) . |
List<com.google.cloud.Date> |
getDateList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.date()) . |
double |
getDouble(int columnIndex)
Returns the value of a non-
NULL column with type Type.float64() . |
double |
getDouble(String columnName)
Returns the value of a non-
NULL column with type Type.float64() . |
double[] |
getDoubleArray(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.float64()) . |
double[] |
getDoubleArray(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.float64()) . |
List<Double> |
getDoubleList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.float64()) . |
List<Double> |
getDoubleList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.float64()) . |
default String |
getJson(int columnIndex)
Returns the value of a non-
NULL column with type Type.string() . |
default String |
getJson(String columnName)
Returns the value of a non-
NULL column with type Type.string() . |
default List<String> |
getJsonList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.string()) . |
default List<String> |
getJsonList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.string()) . |
long |
getLong(int columnIndex)
Returns the value of a non-
NULL column with type Type.int64() . |
long |
getLong(String columnName)
Returns the value of a non-
NULL column with type Type.int64() . |
long[] |
getLongArray(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.int64()) . |
long[] |
getLongArray(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.int64()) . |
List<Long> |
getLongList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.int64()) . |
List<Long> |
getLongList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.int64()) . |
String |
getString(int columnIndex)
Returns the value of a non-
NULL column with type Type.string() . |
String |
getString(String columnName)
Returns the value of a non-
NULL column with type Type.string() . |
List<String> |
getStringList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.string()) . |
List<String> |
getStringList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.string()) . |
List<Struct> |
getStructList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.struct(...)) . |
List<Struct> |
getStructList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.struct(...)) . |
com.google.cloud.Timestamp |
getTimestamp(int columnIndex)
Returns the value of a non-
NULL column with type Type.timestamp() . |
com.google.cloud.Timestamp |
getTimestamp(String columnName)
Returns the value of a non-
NULL column with type Type.timestamp() . |
List<com.google.cloud.Timestamp> |
getTimestampList(int columnIndex)
Returns the value of a non-
NULL column with type Type.array(Type.timestamp()) . |
List<com.google.cloud.Timestamp> |
getTimestampList(String columnName)
Returns the value of a non-
NULL column with type Type.array(Type.timestamp()) . |
Type |
getType()
Returns the type of the underlying data.
|
default Value |
getValue(int columnIndex)
Returns the value of a nullable column as a
Value . |
default Value |
getValue(String columnName)
Returns the value of a nullable column as a
Value . |
boolean |
isNull(int columnIndex)
Returns
true if a column contains a NULL value. |
boolean |
isNull(String columnName)
Returns
true if a column contains a NULL value. |
Type getType()
STRUCT
type, with fields
corresponding to the data's columns. For the result of a read or query, this will always match
the columns passed to the read()
call or named in the query text, in order.int getColumnCount()
NULL
values.int getColumnIndex(String columnName)
columnName
.IllegalArgumentException
- if there is not exactly one element of type().structFields()
with Type.StructField.getName()
equal to columnName
Type getColumnType(int columnIndex)
boolean isNull(int columnIndex)
true
if a column contains a NULL
value.boolean isNull(String columnName)
true
if a column contains a NULL
value.boolean getBoolean(int columnIndex)
NULL
column with type Type.bool()
.boolean getBoolean(String columnName)
NULL
column with type Type.bool()
.long getLong(int columnIndex)
NULL
column with type Type.int64()
.long getLong(String columnName)
NULL
column with type Type.int64()
.double getDouble(int columnIndex)
NULL
column with type Type.float64()
.double getDouble(String columnName)
NULL
column with type Type.float64()
.BigDecimal getBigDecimal(int columnIndex)
NULL
column with type Type.numeric()
.BigDecimal getBigDecimal(String columnName)
NULL
column with type Type.numeric()
.String getString(int columnIndex)
NULL
column with type Type.string()
.String getString(String columnName)
NULL
column with type Type.string()
.default String getJson(int columnIndex)
NULL
column with type Type.string()
.default String getJson(String columnName)
NULL
column with type Type.string()
.com.google.cloud.ByteArray getBytes(int columnIndex)
NULL
column with type Type.bytes()
.com.google.cloud.ByteArray getBytes(String columnName)
NULL
column with type Type.bytes()
.com.google.cloud.Timestamp getTimestamp(int columnIndex)
NULL
column with type Type.timestamp()
.com.google.cloud.Timestamp getTimestamp(String columnName)
NULL
column with type Type.timestamp()
.com.google.cloud.Date getDate(int columnIndex)
NULL
column with type Type.date()
.com.google.cloud.Date getDate(String columnName)
NULL
column with type Type.date()
.default Value getValue(String columnName)
Value
.boolean[] getBooleanArray(int columnIndex)
NULL
column with type Type.array(Type.bool())
.NullPointerException
- if any element of the array value is NULL
. If the array
may contain NULL
values, use getBooleanList(int)
instead.boolean[] getBooleanArray(String columnName)
NULL
column with type Type.array(Type.bool())
.NullPointerException
- if any element of the array value is NULL
. If the array
may contain NULL
values, use getBooleanList(String)
instead.List<Boolean> getBooleanList(int columnIndex)
NULL
column with type Type.array(Type.bool())
.List<Boolean> getBooleanList(String columnName)
NULL
column with type Type.array(Type.bool())
.long[] getLongArray(int columnIndex)
NULL
column with type Type.array(Type.int64())
.NullPointerException
- if any element of the array value is NULL
. If the array
may contain NULL
values, use getLongList(int)
instead.long[] getLongArray(String columnName)
NULL
column with type Type.array(Type.int64())
.NullPointerException
- if any element of the array value is NULL
. If the array
may contain NULL
values, use getLongList(String)
instead.List<Long> getLongList(int columnIndex)
NULL
column with type Type.array(Type.int64())
.List<Long> getLongList(String columnName)
NULL
column with type Type.array(Type.int64())
.double[] getDoubleArray(int columnIndex)
NULL
column with type Type.array(Type.float64())
.NullPointerException
- if any element of the array value is NULL
. If the array
may contain NULL
values, use getDoubleList(int)
instead.double[] getDoubleArray(String columnName)
NULL
column with type Type.array(Type.float64())
.NullPointerException
- if any element of the array value is NULL
. If the array
may contain NULL
values, use getDoubleList(String)
instead.List<Double> getDoubleList(int columnIndex)
NULL
column with type Type.array(Type.float64())
.List<Double> getDoubleList(String columnName)
NULL
column with type Type.array(Type.float64())
.List<BigDecimal> getBigDecimalList(int columnIndex)
NULL
column with type Type.array(Type.numeric())
.List<BigDecimal> getBigDecimalList(String columnName)
NULL
column with type Type.array(Type.numeric())
.List<String> getStringList(int columnIndex)
NULL
column with type Type.array(Type.string())
.List<String> getStringList(String columnName)
NULL
column with type Type.array(Type.string())
.default List<String> getJsonList(int columnIndex)
NULL
column with type Type.array(Type.string())
.default List<String> getJsonList(String columnName)
NULL
column with type Type.array(Type.string())
.List<com.google.cloud.ByteArray> getBytesList(int columnIndex)
NULL
column with type Type.array(Type.bytes())
.List<com.google.cloud.ByteArray> getBytesList(String columnName)
NULL
column with type Type.array(Type.bytes())
.List<com.google.cloud.Timestamp> getTimestampList(int columnIndex)
NULL
column with type Type.array(Type.timestamp())
.List<com.google.cloud.Timestamp> getTimestampList(String columnName)
NULL
column with type Type.array(Type.timestamp())
.List<com.google.cloud.Date> getDateList(int columnIndex)
NULL
column with type Type.array(Type.date())
.List<com.google.cloud.Date> getDateList(String columnName)
NULL
column with type Type.array(Type.date())
.List<Struct> getStructList(int columnIndex)
NULL
column with type Type.array(Type.struct(...))
.Copyright © 2022 Google LLC. All rights reserved.