Class SpannerReadOperation

java.lang.Object
io.github.flink.gcp.connector.spanner.source.SpannerReadOperation
All Implemented Interfaces:
Serializable

@Public public final class SpannerReadOperation extends Object implements Serializable
What the batch source reads: either a query, or a table with its columns and key set, optionally through an index.

 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.

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 Details

    • query

      public static SpannerReadOperation query(com.google.cloud.spanner.Statement statement)
      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 name
      keys - the keys and key ranges to read; KeySet.all() for the whole table
      columns - 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 STORING or INCLUDE.

      Parameters:
      table - the table name
      index - the index name
      keys - the keys and key ranges to read, in the index's key space
      columns - 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 null when this is a table read
    • getTable

      @Nullable public String getTable()
      Returns the table to read, when this is a table read.
      Returns:
      the table name, or null when this is a query
    • getIndex

      @Nullable public String getIndex()
      Returns the index to read through.
      Returns:
      the index name, or null for 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 null when this is a query
    • getColumns

      @Nullable public List<String> getColumns()
      Returns the columns to return, when this is a table read.
      Returns:
      the columns, or null when this is a query
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object