Class ChangeStreamResultSet
- java.lang.Object
-
- org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.ChangeStreamResultSet
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class ChangeStreamResultSet extends java.lang.Object implements java.lang.AutoCloseableDecorator class over aResultSetthat 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the current change streamResultSet.com.google.cloud.spanner.StructgetCurrentRowAsStruct()Returns the record at the current pointer as aStruct.ChangeStreamResultSetMetadatagetMetadata()Returns the gathered metadata for the change stream query so far.java.lang.StringgetPgJsonb(int index)Returns the record at the current pointer asJsonB.com.google.spanner.v1.ChangeStreamRecordgetProtoChangeStreamRecord()Returns the only change stream record proto at the current pointer of the result set.booleanisProtoChangeRecord()Returns true if the result set at the current pointer contain only one proto change record.booleannext()Moves the pointer to the next record in theResultSetif there is one.
-
-
-
Method Detail
-
next
public boolean next()
Moves the pointer to the next record in theResultSetif 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 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
Structor 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
public java.lang.String getPgJsonb(int index)
Returns the record at the current pointer asJsonB. 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
Structor null
-
getMetadata
public ChangeStreamResultSetMetadata getMetadata()
Returns the gathered metadata for the change stream query so far.- Returns:
- a
ChangeStreamResultSetMetadatacontained 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:
closein interfacejava.lang.AutoCloseable
-
-