Interface StructReader
-
- All Known Subinterfaces:
AsyncResultSet
,PartitionedQueryResultSet
,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)
BigDecimal
getBigDecimal(String columnName)
List<BigDecimal>
getBigDecimalList(int columnIndex)
List<BigDecimal>
getBigDecimalList(String columnName)
boolean
getBoolean(int columnIndex)
boolean
getBoolean(String columnName)
boolean[]
getBooleanArray(int columnIndex)
boolean[]
getBooleanArray(String columnName)
List<Boolean>
getBooleanList(int columnIndex)
List<Boolean>
getBooleanList(String columnName)
com.google.cloud.ByteArray
getBytes(int columnIndex)
com.google.cloud.ByteArray
getBytes(String columnName)
List<com.google.cloud.ByteArray>
getBytesList(int columnIndex)
List<com.google.cloud.ByteArray>
getBytesList(String columnName)
int
getColumnCount()
int
getColumnIndex(String columnName)
Type
getColumnType(int columnIndex)
Type
getColumnType(String columnName)
com.google.cloud.Date
getDate(int columnIndex)
com.google.cloud.Date
getDate(String columnName)
List<com.google.cloud.Date>
getDateList(int columnIndex)
List<com.google.cloud.Date>
getDateList(String columnName)
double
getDouble(int columnIndex)
double
getDouble(String columnName)
double[]
getDoubleArray(int columnIndex)
double[]
getDoubleArray(String columnName)
List<Double>
getDoubleList(int columnIndex)
List<Double>
getDoubleList(String columnName)
default String
getJson(int columnIndex)
default String
getJson(String columnName)
default List<String>
getJsonList(int columnIndex)
default List<String>
getJsonList(String columnName)
long
getLong(int columnIndex)
long
getLong(String columnName)
long[]
getLongArray(int columnIndex)
long[]
getLongArray(String columnName)
List<Long>
getLongList(int columnIndex)
List<Long>
getLongList(String columnName)
default String
getPgJsonb(int columnIndex)
default String
getPgJsonb(String columnName)
default List<String>
getPgJsonbList(int columnIndex)
default List<String>
getPgJsonbList(String columnName)
String
getString(int columnIndex)
String
getString(String columnName)
List<String>
getStringList(int columnIndex)
List<String>
getStringList(String columnName)
List<Struct>
getStructList(int columnIndex)
List<Struct>
getStructList(String columnName)
com.google.cloud.Timestamp
getTimestamp(int columnIndex)
com.google.cloud.Timestamp
getTimestamp(String columnName)
List<com.google.cloud.Timestamp>
getTimestampList(int columnIndex)
List<com.google.cloud.Timestamp>
getTimestampList(String columnName)
Type
getType()
default Value
getValue(int columnIndex)
default Value
getValue(String columnName)
boolean
isNull(int columnIndex)
boolean
isNull(String columnName)
-
-
-
Method Detail
-
getType
Type getType()
- Returns:
- the type of the underlying data. This will always be a
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 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 with
NULL
values.
-
getColumnIndex
int getColumnIndex(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the index of the column named
columnName
. - Throws:
IllegalArgumentException
- if there is not exactly one element oftype().structFields()
withType.StructField.getName()
equal tocolumnName
-
getColumnType
Type getColumnType(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the type of a column.
-
getColumnType
Type getColumnType(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the type of a column.
-
isNull
boolean isNull(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
true
if a column contains aNULL
value.
-
isNull
boolean isNull(String columnName)
- Parameters:
columnName
- name of the column- Returns:
true
if a column contains aNULL
value.
-
getBoolean
boolean getBoolean(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.bool()
.
-
getBoolean
boolean getBoolean(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.bool()
.
-
getLong
long getLong(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.int64()
.
-
getLong
long getLong(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.int64()
.
-
getDouble
double getDouble(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.float64()
.
-
getDouble
double getDouble(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.float64()
.
-
getBigDecimal
BigDecimal getBigDecimal(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.numeric()
.
-
getBigDecimal
BigDecimal getBigDecimal(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.numeric()
.
-
getString
String getString(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.string()
.
-
getString
String getString(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.string()
.
-
getJson
default String getJson(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.json()
.
-
getJson
default String getJson(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.json()
.
-
getPgJsonb
default String getPgJsonb(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.pgJsonb()
.
-
getPgJsonb
default String getPgJsonb(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.pgJsonb()
.
-
getBytes
com.google.cloud.ByteArray getBytes(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.bytes()
.
-
getBytes
com.google.cloud.ByteArray getBytes(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.bytes()
.
-
getTimestamp
com.google.cloud.Timestamp getTimestamp(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.timestamp()
.
-
getTimestamp
com.google.cloud.Timestamp getTimestamp(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.timestamp()
.
-
getDate
com.google.cloud.Date getDate(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.date()
.
-
getDate
com.google.cloud.Date getDate(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.date()
.
-
getValue
default Value getValue(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a nullable column as a
Value
.
-
getValue
default Value getValue(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a nullable column as a
Value
.
-
getBooleanArray
boolean[] getBooleanArray(int columnIndex)
- Parameters:
columnIndex
- index of the column- 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)
- Parameters:
columnName
- name of the column- 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)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.bool())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBooleanList
List<Boolean> getBooleanList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.bool())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getLongArray
long[] getLongArray(int columnIndex)
- Parameters:
columnIndex
- index of the column- 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)
- Parameters:
columnName
- name of the column- 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)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.int64())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getLongList
List<Long> getLongList(String columnName)
- Parameters:
columnName
-- Returns:
- the value of a non-
NULL
column with typeType.array(Type.int64())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getDoubleArray
double[] getDoubleArray(int columnIndex)
- Parameters:
columnIndex
- index of the column- 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)
- Parameters:
columnName
- name of the column- 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)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.float64())
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getDoubleList
List<Double> getDoubleList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.float64())
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBigDecimalList
List<BigDecimal> getBigDecimalList(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.numeric())
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBigDecimalList
List<BigDecimal> getBigDecimalList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.numeric())
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getStringList
List<String> getStringList(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.string())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getStringList
List<String> getStringList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.string())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getJsonList
default List<String> getJsonList(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.json())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getJsonList
default List<String> getJsonList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.json())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getPgJsonbList
default List<String> getPgJsonbList(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.pgJsonb())
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getPgJsonbList
default List<String> getPgJsonbList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.pgJsonb())
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBytesList
List<com.google.cloud.ByteArray> getBytesList(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.bytes())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBytesList
List<com.google.cloud.ByteArray> getBytesList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.bytes())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getTimestampList
List<com.google.cloud.Timestamp> getTimestampList(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.timestamp())
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getTimestampList
List<com.google.cloud.Timestamp> getTimestampList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.timestamp())
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getDateList
List<com.google.cloud.Date> getDateList(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.date())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getDateList
List<com.google.cloud.Date> getDateList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.date())
. The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getStructList
List<Struct> getStructList(int columnIndex)
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.struct(...))
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getStructList
List<Struct> getStructList(String columnName)
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.array(Type.struct(...))
The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
-