Interface StructReader
- All Known Subinterfaces:
AsyncResultSet,PartitionedQueryResultSet,ProtobufResultSet,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) booleangetBoolean(int columnIndex) booleangetBoolean(String columnName) boolean[]getBooleanArray(int columnIndex) boolean[]getBooleanArray(String columnName) getBooleanList(int columnIndex) getBooleanList(String columnName) com.google.cloud.ByteArraygetBytes(int columnIndex) com.google.cloud.ByteArrayList<com.google.cloud.ByteArray>getBytesList(int columnIndex) List<com.google.cloud.ByteArray>getBytesList(String columnName) intintgetColumnIndex(String columnName) getColumnType(int columnIndex) getColumnType(String columnName) com.google.cloud.DategetDate(int columnIndex) com.google.cloud.DateList<com.google.cloud.Date>getDateList(int columnIndex) List<com.google.cloud.Date>getDateList(String columnName) doublegetDouble(int columnIndex) doubledouble[]getDoubleArray(int columnIndex) double[]getDoubleArray(String columnName) getDoubleList(int columnIndex) getDoubleList(String columnName) default floatgetFloat(int columnIndex) default floatdefault float[]getFloatArray(int columnIndex) default float[]getFloatArray(String columnName) getFloatList(int columnIndex) getFloatList(String columnName) default StringgetJson(int columnIndex) default StringgetJsonList(int columnIndex) getJsonList(String columnName) longgetLong(int columnIndex) longlong[]getLongArray(int columnIndex) long[]getLongArray(String columnName) getLongList(int columnIndex) getLongList(String columnName) default StringgetPgJsonb(int columnIndex) default StringgetPgJsonb(String columnName) getPgJsonbList(int columnIndex) getPgJsonbList(String columnName) default <T extends com.google.protobuf.ProtocolMessageEnum>
TgetProtoEnum(int columnIndex, Function<Integer, com.google.protobuf.ProtocolMessageEnum> method) To get the proto enum of typeTfrom Struct.default <T extends com.google.protobuf.ProtocolMessageEnum>
TgetProtoEnum(String columnName, Function<Integer, com.google.protobuf.ProtocolMessageEnum> method) To get the proto enum of typeTfrom Struct.default <T extends com.google.protobuf.ProtocolMessageEnum>
List<T>getProtoEnumList(int columnIndex, Function<Integer, com.google.protobuf.ProtocolMessageEnum> method) To get the proto enum of typeTfrom Struct.default <T extends com.google.protobuf.ProtocolMessageEnum>
List<T>getProtoEnumList(String columnName, Function<Integer, com.google.protobuf.ProtocolMessageEnum> method) To get the proto enum list of typeTfrom Struct.default <T extends com.google.protobuf.AbstractMessage>
TgetProtoMessage(int columnIndex, T message) To get the proto message of generic typeTfrom Struct.default <T extends com.google.protobuf.AbstractMessage>
TgetProtoMessage(String columnName, T message) To get the proto message of typeTfrom Struct.default <T extends com.google.protobuf.AbstractMessage>
List<T>getProtoMessageList(int columnIndex, T message) To get the proto message of generic typeTfrom Struct.default <T extends com.google.protobuf.AbstractMessage>
List<T>getProtoMessageList(String columnName, T message) To get the proto message of typeTfrom Struct.getString(int columnIndex) getStringList(int columnIndex) getStringList(String columnName) getStructList(int columnIndex) getStructList(String columnName) com.google.cloud.TimestampgetTimestamp(int columnIndex) com.google.cloud.TimestampgetTimestamp(String columnName) List<com.google.cloud.Timestamp>getTimestampList(int columnIndex) List<com.google.cloud.Timestamp>getTimestampList(String columnName) getType()default ValuegetValue(int columnIndex) default ValuebooleanisNull(int columnIndex) boolean
-
Method Details
-
getType
Type getType()- Returns:
- the type of the underlying data. This will always be a
STRUCTtype, 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
NULLvalues.
-
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:
trueif a column contains aNULLvalue.
-
isNull
- Parameters:
columnName- name of the column- Returns:
trueif a column contains aNULLvalue.
-
getBoolean
boolean getBoolean(int columnIndex) - Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.bool().
-
getBoolean
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.bool().
-
getLong
long getLong(int columnIndex) - Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.int64().
-
getLong
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.int64().
-
getFloat
default float getFloat(int columnIndex) - Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.float32().
-
getFloat
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.float32().
-
getDouble
double getDouble(int columnIndex) - Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.float64().
-
getDouble
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.float64().
-
getBigDecimal
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.numeric().
-
getBigDecimal
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.numeric().
-
getString
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.string().
-
getString
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.string().
-
getJson
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.json().
-
getJson
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.json().
-
getPgJsonb
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.pgJsonb().
-
getPgJsonb
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.pgJsonb().
-
getProtoMessage
default <T extends com.google.protobuf.AbstractMessage> T getProtoMessage(int columnIndex, T message) To get the proto message of generic typeTfrom Struct.- Parameters:
columnIndex- Index of the column.message- Proto message object. Message can't be null as it's internally used to find the type of proto. Use @code{MyProtoClass.getDefaultInstance()}. @see getDefaultInstance()- Returns:
- The value of a non-
NULLcolumn with typeType.proto(String)()}.
-
getProtoMessage
default <T extends com.google.protobuf.AbstractMessage> T getProtoMessage(String columnName, T message) To get the proto message of typeTfrom Struct.- Parameters:
columnName- Name of the column.message- Proto message object. Message can't be null as it's internally used to find the type of proto. Use @code{MyProtoClass.getDefaultInstance()}. @see getDefaultInstance()- Returns:
- The value of a non-
NULLcolumn with typeType.proto(String)()}.
-
getProtoEnum
default <T extends com.google.protobuf.ProtocolMessageEnum> T getProtoEnum(int columnIndex, Function<Integer, com.google.protobuf.ProtocolMessageEnum> method) To get the proto enum of typeTfrom Struct.- Parameters:
columnIndex- Index of the column.method- A function that takes enum integer constant as argument and returns the enum. Use method @code{forNumber} from generated enum class (eg: MyProtoEnum::forNumber). @see forNumber- Returns:
- The value of a non-
NULLcolumn with typeType.protoEnum(String)()}.
-
getProtoEnum
default <T extends com.google.protobuf.ProtocolMessageEnum> T getProtoEnum(String columnName, Function<Integer, com.google.protobuf.ProtocolMessageEnum> method) To get the proto enum of typeTfrom Struct.- Parameters:
columnName- Name of the column.method- A function that takes enum integer constant as argument and returns the enum. Use method @code{forNumber} from generated enum class (eg: MyProtoEnum::forNumber). @see forNumber- Returns:
- The value of a non-
NULLcolumn with typeType.protoEnum(String)()}.
-
getBytes
com.google.cloud.ByteArray getBytes(int columnIndex) - Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.bytes().
-
getBytes
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.bytes().
-
getTimestamp
com.google.cloud.Timestamp getTimestamp(int columnIndex) - Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.timestamp().
-
getTimestamp
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.timestamp().
-
getDate
com.google.cloud.Date getDate(int columnIndex) - Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.date().
-
getDate
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn 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-
NULLcolumn with typeType.array(Type.bool()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetBooleanList(int)instead.
-
getBooleanArray
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.bool()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetBooleanList(String)instead.
-
getBooleanList
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn with typeType.array(Type.int64()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetLongList(int)instead.
-
getLongArray
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.int64()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetLongList(String)instead.
-
getLongList
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn 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-
NULLcolumn 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.
-
getFloatArray
default float[] getFloatArray(int columnIndex) - Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.float32()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetFloatList(int)instead.
-
getFloatArray
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.float32()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetFloatList(String)instead.
-
getFloatList
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.float32())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.
-
getFloatList
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.float32())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-
NULLcolumn with typeType.array(Type.float64()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetDoubleList(int)instead.
-
getDoubleArray
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.float64()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetDoubleList(String)instead.
-
getDoubleList
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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.
-
getProtoMessageList
default <T extends com.google.protobuf.AbstractMessage> List<T> getProtoMessageList(int columnIndex, T message) To get the proto message of generic typeTfrom Struct.- Parameters:
columnIndex- Index of the column.message- Proto message object. Message can't be null as it's internally used to find the type of proto. Use @code{MyProtoClass.getDefaultInstance()}. @see getDefaultInstance()- Returns:
- The value of a non-
NULLcolumn with typeType.array(Type.proto(String)).
-
getProtoMessageList
default <T extends com.google.protobuf.AbstractMessage> List<T> getProtoMessageList(String columnName, T message) To get the proto message of typeTfrom Struct.- Parameters:
columnName- Name of the column.message- Proto message object. Message can't be null as it's internally used to find the type of proto. Use @code{MyProtoClass.getDefaultInstance()}. @see getDefaultInstance()- Returns:
- The value of a non-
NULLcolumn with typeType.array(Type.proto(String)).
-
getProtoEnumList
default <T extends com.google.protobuf.ProtocolMessageEnum> List<T> getProtoEnumList(int columnIndex, Function<Integer, com.google.protobuf.ProtocolMessageEnum> method) To get the proto enum of typeTfrom Struct.- Parameters:
columnIndex- Index of the column.method- A function that takes enum integer constant as argument and returns the enum. Use method @code{forNumber} from generated enum class (eg: MyProtoEnum::forNumber). @see forNumber- Returns:
- The value of a non-
NULLcolumn with typeType.array(Type.protoEnum(String)).
-
getProtoEnumList
default <T extends com.google.protobuf.ProtocolMessageEnum> List<T> getProtoEnumList(String columnName, Function<Integer, com.google.protobuf.ProtocolMessageEnum> method) To get the proto enum list of typeTfrom Struct.- Parameters:
columnName- Name of the column.method- A function that takes enum integer constant as argument and returns the enum. Use method @code{forNumber} from generated enum class (eg: MyProtoEnum::forNumber). @see forNumber- Returns:
- The value of a non-
NULLcolumn with typeType.array(Type.protoEnum(String)).
-
getBytesList
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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-
NULLcolumn 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.
-