Interface StructReader
-
- All Known Subinterfaces:
AsyncResultSet
,ResultSet
- All Known Implementing Classes:
AbstractStructReader
,ForwardingAsyncResultSet
,ForwardingResultSet
,ForwardingStructReader
,Struct
public interface StructReader
A base interface for reading the fields of aSTRUCT
. The Cloud Spanner yieldsStructReader
instances as one of the subclassesResultSet
orStruct
, most commonly as the result of a read or query operation. At any point in time, aStructReader
provides access to a single tuple of data comprising multiple typed columns. Each column may have aNULL
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)
andgetString(String)
exist for reading columns of typeType.string()
; attempting to call those methods for columns of other types will result in anIllegalStateException
. ThegetTypeName()
methods should only be called for non-NULL
values, otherwise aNullPointerException
is raised;isNull(int)
/isNull(String)
can be used to test forNULL
-ness if necessary.All methods for accessing a column have overloads that accept an
int
column index and aString
column name. Column indices are zero-based. The column name overloads will fail withIllegalArgumentException
if the column name does not appear exactly once in this instance'sgetType()
. Theint
overloads are typically more efficient than theirString
counterparts.StructReader
itself does not define whether the implementing type is mutable or immutable. For example,ResultSet
is a mutable implementation ofStructReader
, where theStructReader
methods provide access to the row that the result set is currently positioned over andResultSet.next()
changes that view to the next row, whereasStruct
is an immutable implementation ofStructReader
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description BigDecimal
getBigDecimal(int columnIndex)
Returns the value of a non-NULL
column with typeType.numeric()
.BigDecimal
getBigDecimal(String columnName)
Returns the value of a non-NULL
column with typeType.numeric()
.List<BigDecimal>
getBigDecimalList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.numeric())
.List<BigDecimal>
getBigDecimalList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.numeric())
.boolean
getBoolean(int columnIndex)
Returns the value of a non-NULL
column with typeType.bool()
.boolean
getBoolean(String columnName)
Returns the value of a non-NULL
column with typeType.bool()
.boolean[]
getBooleanArray(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.bool())
.boolean[]
getBooleanArray(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.bool())
.List<Boolean>
getBooleanList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.bool())
.List<Boolean>
getBooleanList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.bool())
.com.google.cloud.ByteArray
getBytes(int columnIndex)
Returns the value of a non-NULL
column with typeType.bytes()
.com.google.cloud.ByteArray
getBytes(String columnName)
Returns the value of a non-NULL
column with typeType.bytes()
.List<com.google.cloud.ByteArray>
getBytesList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.bytes())
.List<com.google.cloud.ByteArray>
getBytesList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.bytes())
.int
getColumnCount()
Returns the number of columns in the underlying data.int
getColumnIndex(String columnName)
Returns the index of the column namedcolumnName
.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 typeType.date()
.com.google.cloud.Date
getDate(String columnName)
Returns the value of a non-NULL
column with typeType.date()
.List<com.google.cloud.Date>
getDateList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.date())
.List<com.google.cloud.Date>
getDateList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.date())
.double
getDouble(int columnIndex)
Returns the value of a non-NULL
column with typeType.float64()
.double
getDouble(String columnName)
Returns the value of a non-NULL
column with typeType.float64()
.double[]
getDoubleArray(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.float64())
.double[]
getDoubleArray(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.float64())
.List<Double>
getDoubleList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.float64())
.List<Double>
getDoubleList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.float64())
.default String
getJson(int columnIndex)
Returns the value of a non-NULL
column with typeType.string()
.default String
getJson(String columnName)
Returns the value of a non-NULL
column with typeType.string()
.default List<String>
getJsonList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.string())
.default List<String>
getJsonList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.string())
.long
getLong(int columnIndex)
Returns the value of a non-NULL
column with typeType.int64()
.long
getLong(String columnName)
Returns the value of a non-NULL
column with typeType.int64()
.long[]
getLongArray(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.int64())
.long[]
getLongArray(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.int64())
.List<Long>
getLongList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.int64())
.List<Long>
getLongList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.int64())
.String
getString(int columnIndex)
Returns the value of a non-NULL
column with typeType.string()
.String
getString(String columnName)
Returns the value of a non-NULL
column with typeType.string()
.List<String>
getStringList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.string())
.List<String>
getStringList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.string())
.List<Struct>
getStructList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.struct(...))
.List<Struct>
getStructList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.struct(...))
.com.google.cloud.Timestamp
getTimestamp(int columnIndex)
Returns the value of a non-NULL
column with typeType.timestamp()
.com.google.cloud.Timestamp
getTimestamp(String columnName)
Returns the value of a non-NULL
column with typeType.timestamp()
.List<com.google.cloud.Timestamp>
getTimestampList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.timestamp())
.List<com.google.cloud.Timestamp>
getTimestampList(String columnName)
Returns the value of a non-NULL
column with typeType.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 aValue
.default Value
getValue(String columnName)
Returns the value of a nullable column as aValue
.boolean
isNull(int columnIndex)
Returnstrue
if a column contains aNULL
value.boolean
isNull(String columnName)
Returnstrue
if a column contains aNULL
value.
-
-
-
Method Detail
-
getType
Type getType()
Returns the type of the underlying data. This will always be aSTRUCT
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 theread()
call or named in the query text, in order.
-
getColumnCount
int getColumnCount()
Returns the number of columns in the underlying data. This includes any columns withNULL
values.
-
getColumnIndex
int getColumnIndex(String columnName)
Returns the index of the column namedcolumnName
.- Throws:
IllegalArgumentException
- if there is not exactly one element oftype().structFields()
withType.StructField.getName()
equal tocolumnName
-
getColumnType
Type getColumnType(int columnIndex)
Returns the type of a column.
-
isNull
boolean isNull(int columnIndex)
Returnstrue
if a column contains aNULL
value.
-
isNull
boolean isNull(String columnName)
Returnstrue
if a column contains aNULL
value.
-
getBoolean
boolean getBoolean(int columnIndex)
Returns the value of a non-NULL
column with typeType.bool()
.
-
getBoolean
boolean getBoolean(String columnName)
Returns the value of a non-NULL
column with typeType.bool()
.
-
getLong
long getLong(int columnIndex)
Returns the value of a non-NULL
column with typeType.int64()
.
-
getLong
long getLong(String columnName)
Returns the value of a non-NULL
column with typeType.int64()
.
-
getDouble
double getDouble(int columnIndex)
Returns the value of a non-NULL
column with typeType.float64()
.
-
getDouble
double getDouble(String columnName)
Returns the value of a non-NULL
column with typeType.float64()
.
-
getBigDecimal
BigDecimal getBigDecimal(int columnIndex)
Returns the value of a non-NULL
column with typeType.numeric()
.
-
getBigDecimal
BigDecimal getBigDecimal(String columnName)
Returns the value of a non-NULL
column with typeType.numeric()
.
-
getString
String getString(int columnIndex)
Returns the value of a non-NULL
column with typeType.string()
.
-
getString
String getString(String columnName)
Returns the value of a non-NULL
column with typeType.string()
.
-
getJson
default String getJson(int columnIndex)
Returns the value of a non-NULL
column with typeType.string()
.
-
getJson
default String getJson(String columnName)
Returns the value of a non-NULL
column with typeType.string()
.
-
getBytes
com.google.cloud.ByteArray getBytes(int columnIndex)
Returns the value of a non-NULL
column with typeType.bytes()
.
-
getBytes
com.google.cloud.ByteArray getBytes(String columnName)
Returns the value of a non-NULL
column with typeType.bytes()
.
-
getTimestamp
com.google.cloud.Timestamp getTimestamp(int columnIndex)
Returns the value of a non-NULL
column with typeType.timestamp()
.
-
getTimestamp
com.google.cloud.Timestamp getTimestamp(String columnName)
Returns the value of a non-NULL
column with typeType.timestamp()
.
-
getDate
com.google.cloud.Date getDate(int columnIndex)
Returns the value of a non-NULL
column with typeType.date()
.
-
getDate
com.google.cloud.Date getDate(String columnName)
Returns the value of a non-NULL
column with typeType.date()
.
-
getValue
default Value getValue(int columnIndex)
Returns the value of a nullable column as aValue
.
-
getValue
default Value getValue(String columnName)
Returns the value of a nullable column as aValue
.
-
getBooleanArray
boolean[] getBooleanArray(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.bool())
.- Throws:
NullPointerException
- if any element of the array value isNULL
. If the array may containNULL
values, usegetBooleanList(int)
instead.
-
getBooleanArray
boolean[] getBooleanArray(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.bool())
.- Throws:
NullPointerException
- if any element of the array value isNULL
. If the array may containNULL
values, usegetBooleanList(String)
instead.
-
getBooleanList
List<Boolean> getBooleanList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.bool())
.
-
getBooleanList
List<Boolean> getBooleanList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.bool())
.
-
getLongArray
long[] getLongArray(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.int64())
.- Throws:
NullPointerException
- if any element of the array value isNULL
. If the array may containNULL
values, usegetLongList(int)
instead.
-
getLongArray
long[] getLongArray(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.int64())
.- Throws:
NullPointerException
- if any element of the array value isNULL
. If the array may containNULL
values, usegetLongList(String)
instead.
-
getLongList
List<Long> getLongList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.int64())
.
-
getLongList
List<Long> getLongList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.int64())
.
-
getDoubleArray
double[] getDoubleArray(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.float64())
.- Throws:
NullPointerException
- if any element of the array value isNULL
. If the array may containNULL
values, usegetDoubleList(int)
instead.
-
getDoubleArray
double[] getDoubleArray(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.float64())
.- Throws:
NullPointerException
- if any element of the array value isNULL
. If the array may containNULL
values, usegetDoubleList(String)
instead.
-
getDoubleList
List<Double> getDoubleList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.float64())
.
-
getDoubleList
List<Double> getDoubleList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.float64())
.
-
getBigDecimalList
List<BigDecimal> getBigDecimalList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.numeric())
.
-
getBigDecimalList
List<BigDecimal> getBigDecimalList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.numeric())
.
-
getStringList
List<String> getStringList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.string())
.
-
getStringList
List<String> getStringList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.string())
.
-
getJsonList
default List<String> getJsonList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.string())
.
-
getJsonList
default List<String> getJsonList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.string())
.
-
getBytesList
List<com.google.cloud.ByteArray> getBytesList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.bytes())
.
-
getBytesList
List<com.google.cloud.ByteArray> getBytesList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.bytes())
.
-
getTimestampList
List<com.google.cloud.Timestamp> getTimestampList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.timestamp())
.
-
getTimestampList
List<com.google.cloud.Timestamp> getTimestampList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.timestamp())
.
-
getDateList
List<com.google.cloud.Date> getDateList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.date())
.
-
getDateList
List<com.google.cloud.Date> getDateList(String columnName)
Returns the value of a non-NULL
column with typeType.array(Type.date())
.
-
getStructList
List<Struct> getStructList(int columnIndex)
Returns the value of a non-NULL
column with typeType.array(Type.struct(...))
.
-
-