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.AutoCloseable
Decorator class over aResultSet
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the current change streamResultSet
.com.google.cloud.spanner.Struct
getCurrentRowAsStruct()
Returns the record at the current pointer as aStruct
.ChangeStreamResultSetMetadata
getMetadata()
Returns the gathered metadata for the change stream query so far.java.lang.String
getPgJsonb(int index)
Returns the record at the current pointer asJsonB
.boolean
next()
Moves the pointer to the next record in theResultSet
if there is one.
-
-
-
Method Detail
-
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
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
Struct
or null
-
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
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 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 interfacejava.lang.AutoCloseable
-
-