Class SpannerReadOperation
- All Implemented Interfaces:
Serializable
SpannerReadOperation.query(Statement.of("SELECT id, name FROM singers"));
SpannerReadOperation.read("singers", KeySet.all(), Arrays.asList("id", "name"));
SpannerReadOperation.readUsingIndex(
"singers", "singers_by_name", KeySet.all(), Arrays.asList("id", "name"));
The two shapes are exclusive because Spanner's own API makes them so — partitionQuery
takes a statement and partitionRead takes a table — and holding them in one value object
is what lets the builder take a single option rather than five that only make sense in two
combinations.
Lineage reports the configured base table for explicit reads, including index reads. An index is only an access path. Query dependencies are unknown: the source neither parses SQL nor submits it to discover lineage, and returns an empty dataset list for a query.
Not every query can be read this way. Spanner partitions a query only when its
execution plan begins with a distributed union — in practice a scan of one table, with predicates
and projections but no aggregate, no ORDER BY and no LIMIT. A query that is not
root-partitionable is refused by the service when the source plans, with a message naming the
reason, and the source fails rather than silently reading it on one subtask.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the columns to return, when this is a table read.getIndex()Returns the index to read through.com.google.cloud.spanner.KeySetgetKeys()Returns the keys to read, when this is a table read.com.google.cloud.spanner.StatementReturns the query, when this is one.getTable()Returns the table to read, when this is a table read.inthashCode()booleanisQuery()Returns whether this is a query rather than a table read.static SpannerReadOperationquery(com.google.cloud.spanner.Statement statement) Reads the rows a query returns.static SpannerReadOperationReads columns of a table over a key set.static SpannerReadOperationreadUsingIndex(String table, String index, com.google.cloud.spanner.KeySet keys, List<String> columns) Reads columns of a table over a key set, through a secondary index.toString()
-
Method Details
-
query
Reads the rows a query returns.- Parameters:
statement- the query, with its parameter bindings if it has any- Returns:
- the read operation
-
read
public static SpannerReadOperation read(String table, com.google.cloud.spanner.KeySet keys, List<String> columns) Reads columns of a table over a key set.- Parameters:
table- the table namekeys- the keys and key ranges to read;KeySet.all()for the whole tablecolumns- the columns to return, at least one- Returns:
- the read operation
-
readUsingIndex
public static SpannerReadOperation readUsingIndex(String table, String index, com.google.cloud.spanner.KeySet keys, List<String> columns) Reads columns of a table over a key set, through a secondary index.The key set is interpreted in the index's key space, not the table's, and a read can return only index key columns, base-table primary-key columns, and columns included with
STORINGorINCLUDE.- Parameters:
table- the table nameindex- the index namekeys- the keys and key ranges to read, in the index's key spacecolumns- the columns to return, at least one- Returns:
- the read operation
-
isQuery
public boolean isQuery()Returns whether this is a query rather than a table read.- Returns:
- whether this operation is a query
-
getStatement
@Nullable public com.google.cloud.spanner.Statement getStatement()Returns the query, when this is one.- Returns:
- the query, or
nullwhen this is a table read
-
getTable
Returns the table to read, when this is a table read.- Returns:
- the table name, or
nullwhen this is a query
-
getIndex
Returns the index to read through.- Returns:
- the index name, or
nullfor a read of the table itself or for a query
-
getKeys
@Nullable public com.google.cloud.spanner.KeySet getKeys()Returns the keys to read, when this is a table read.- Returns:
- the key set, or
nullwhen this is a query
-
getColumns
Returns the columns to return, when this is a table read.- Returns:
- the columns, or
nullwhen this is a query
-
equals
-
hashCode
public int hashCode() -
toString
-