Class ChangeStreamResultSet
java.lang.Object
org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.ChangeStreamResultSet
- All Implemented Interfaces:
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 TypeMethodDescriptionvoid
close()
Closes the current change streamResultSet
.Returns the record at the current pointer as aStruct
.Returns the gathered metadata for the change stream query so far.getPgJsonb
(int index) Returns the record at the current pointer asinvalid 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 proto change record.boolean
next()
Moves the pointer to the next record in theResultSet
if there is one.
-
Method Details
-
next
public boolean next()Moves the pointer to the next record in theResultSet
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
Returns the record at the current pointer as aStruct
. 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.- 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. -
getPgJsonb
Returns the record at the current pointer asinvalid reference
JsonB
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
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 streamResultSet
. 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 interfaceAutoCloseable
-