Class ChangeStreamResultSet

java.lang.Object
org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.ChangeStreamResultSet
All Implemented Interfaces:
AutoCloseable

public class ChangeStreamResultSet extends Object implements AutoCloseable
Decorator class over a ResultSet that provides telemetry for the streamed records. It will be returned for a change stream query. By using this class one can obtain the following metadata:
  • The timestamp at which the query first started.
  • The timestamp at which a record streaming started.
  • The timestamp at which a record streaming ended.
  • The timestamp at which a record was read by the caller.
  • The total time for streaming all records within the query.
  • The total number of records streamed within the query.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the current change stream ResultSet.
    com.google.spanner.v1.ChangeStreamRecord
    getBytes(int index)
    Returns the change stream record at the current pointer by parsing the bytes column.
    com.google.cloud.spanner.Struct
    Returns the record at the current pointer as a Struct.
    Returns the gathered metadata for the change stream query so far.
    getPgJsonb(int index)
    Returns the record at the current pointer as
    invalid reference
    JsonB
    .
    com.google.spanner.v1.ChangeStreamRecord
    Returns the only change stream record proto at the current pointer of the result set.
    boolean
    Returns true if the result set at the current pointer contain only one bytes change record.
    boolean
    Returns true if the result set at the current pointer contain only one proto change record.
    boolean
    Moves the pointer to the next record in the ResultSet if there is one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • next

      public boolean next()
      Moves the pointer to the next record in the ResultSet if there is one. It also gathers metrics for the next record, such as:
      • If this is the first record consumed, updates the time at which the query started.
      • The timestamp at which a record streaming started.
      • The timestamp at which a record streaming ended.
      • Increments the total time for streaming the all the records so far.
      • Increments the total number of all the records streamed so far.
      Returns:
      true if there is another record within the result set. Returns false otherwise.
    • getCurrentRowAsStruct

      public com.google.cloud.spanner.Struct getCurrentRowAsStruct()
      Returns the record at the current pointer as a Struct. It also updates the timestamp at which the record was read.

      If next() was not called or if it was called but there are no more records in the stream, null will be returned.

      Should only be used for GoogleSQL databases.

      Returns:
      a change stream record as a Struct or null
    • getProtoChangeStreamRecord

      public com.google.spanner.v1.ChangeStreamRecord getProtoChangeStreamRecord()
      Returns the only change stream record proto at the current pointer of the result set. It also updates the timestamp at which the record was read. This function enhances the getProtoMessage function but only focus on the ChangeStreamRecord type.

      Should only be used for GoogleSQL databases when the change stream record is delivered as proto.

      Returns:
      a change stream record as a proto or null
    • isProtoChangeRecord

      public boolean isProtoChangeRecord()
      Returns true if the result set at the current pointer contain only one proto change record.
    • getBytes

      public com.google.spanner.v1.ChangeStreamRecord getBytes(int index)
      Returns the change stream record at the current pointer by parsing the bytes column. It also updates the timestamp at which the record was read.

      Should only be used for PostgreSQL databases when the change stream record is delivered as proto bytes.

      Returns:
      a change stream record as a proto or null
    • isProtoBytesChangeRecord

      public boolean isProtoBytesChangeRecord()
      Returns true if the result set at the current pointer contain only one bytes change record.
    • getPgJsonb

      public String getPgJsonb(int index)
      Returns the record at the current pointer as
      invalid reference
      JsonB
      . It also updates the timestamp at which the record was read.

      If next() was not called or if it was called but there are no more records in the stream, null will be returned.

      Should only be used for PostgreSQL databases.

      Returns:
      a change stream record as a Struct or null
    • getMetadata

      public ChangeStreamResultSetMetadata getMetadata()
      Returns the gathered metadata for the change stream query so far.
      Returns:
      a ChangeStreamResultSetMetadata contained telemetry information for the query so far
    • close

      public void close()
      Closes the current change stream ResultSet. The stream will be terminated when this method is called.

      This method must always be called after the consumption of the result set or when an error occurs. This makes sure there are no Session leaks and all the underlying resources are released.

      Specified by:
      close in interface AutoCloseable