Interface StructReader
- All Known Subinterfaces:
AsyncResultSet
,PartitionedQueryResultSet
,ResultSet
- All Known Implementing Classes:
AbstractStructReader
,ForwardingAsyncResultSet
,ForwardingResultSet
,ForwardingStructReader
,Struct
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
.
-
Method Summary
Modifier and TypeMethodDescriptiongetBigDecimal
(int columnIndex) getBigDecimal
(String columnName) getBigDecimalList
(int columnIndex) getBigDecimalList
(String columnName) boolean
getBoolean
(int columnIndex) boolean
getBoolean
(String columnName) boolean[]
getBooleanArray
(int columnIndex) boolean[]
getBooleanArray
(String columnName) getBooleanList
(int columnIndex) getBooleanList
(String columnName) com.google.cloud.ByteArray
getBytes
(int columnIndex) com.google.cloud.ByteArray
List<com.google.cloud.ByteArray>
getBytesList
(int columnIndex) List<com.google.cloud.ByteArray>
getBytesList
(String columnName) int
int
getColumnIndex
(String columnName) getColumnType
(int columnIndex) getColumnType
(String columnName) com.google.cloud.Date
getDate
(int columnIndex) com.google.cloud.Date
List<com.google.cloud.Date>
getDateList
(int columnIndex) List<com.google.cloud.Date>
getDateList
(String columnName) double
getDouble
(int columnIndex) double
double[]
getDoubleArray
(int columnIndex) double[]
getDoubleArray
(String columnName) getDoubleList
(int columnIndex) getDoubleList
(String columnName) default String
getJson
(int columnIndex) default String
getJsonList
(int columnIndex) getJsonList
(String columnName) long
getLong
(int columnIndex) long
long[]
getLongArray
(int columnIndex) long[]
getLongArray
(String columnName) getLongList
(int columnIndex) getLongList
(String columnName) default String
getPgJsonb
(int columnIndex) default String
getPgJsonb
(String columnName) getPgJsonbList
(int columnIndex) getPgJsonbList
(String columnName) getString
(int columnIndex) getStringList
(int columnIndex) getStringList
(String columnName) getStructList
(int columnIndex) 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) getType()
default Value
getValue
(int columnIndex) default Value
boolean
isNull
(int columnIndex) boolean
-
Method Details
-
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
- 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
- Parameters:
columnIndex
- index of the column- Returns:
- the type of a column.
-
getColumnType
- 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
- 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
- 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
- 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
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.float64()
.
-
getBigDecimal
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.numeric()
.
-
getBigDecimal
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.numeric()
.
-
getString
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.string()
.
-
getString
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.string()
.
-
getJson
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.json()
.
-
getJson
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.json()
.
-
getPgJsonb
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a non-
NULL
column with typeType.pgJsonb()
.
-
getPgJsonb
- 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
- 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
- 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
- Parameters:
columnName
- name of the column- Returns:
- the value of a non-
NULL
column with typeType.date()
.
-
getValue
- Parameters:
columnIndex
- index of the column- Returns:
- the value of a nullable column as a
Value
.
-
getValue
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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.
-