edit-icon download-icon

Incremental data operations

Last Updated: Feb 26, 2018

Table Store provides the ListStream and DescribeStream operations for streams and GetShardIterator and GetStreamRecord operations for shards.

ListStream

ListStream is used to list all streams enabled for a table on the current instance.

Example

List information about all streams enabled for a table.

  1. private static void listStream(SyncClient client, String tableName) {
  2. ListStreamRequest listStreamRequest = new ListStreamRequest(tableName);
  3. ListStreamResponse result = client.listStream(listStreamRequest);
  4. }

DescribeStream

DescribeStream is used to query creationTime, expirationTime, status, shards, and the ID of the next start shard (if shards are not returned) of a stream.

Example 1

Obtain information about all shards of the current stream.

  1. private static void describeStream(SyncClient client, String streamId) {
  2. DescribeStreamRequest desRequest = new DescribeStreamRequest(streamId);
  3. DescribeStreamResponse desStream = client.describeStream(desRequest);
  4. }

Example 2

Set InclusiveStartShardId and the maximum number of shards returned each time.

  1. private static void describeStream(SyncClient client, String streamId) {
  2. DescribeStreamRequest dsRequest = new DescribeStreamRequest(streamId);
  3. dsRequest.setInclusiveStartShardId(startShardId);
  4. dsRequest.setShardLimit(10);
  5. DescribeStreamResponse dscStream = client.describeStream(dsRequest);
  6. }

GetShardIterator

GetShardIterator is used to obtain the start iterator for reading a shard.

Example

Obtain the start iterator for reading a shard.

  1. private static void getShardIterator(SyncClient client, String streamId, String shardId) {
  2. GetShardIteratorRequest getShardIteratorRequest = new GetShardIteratorRequest(streamId, shardId);
  3. GetShardIteratorResponse shardIterator = client.getShardIterator(getShardIteratorRequest);
  4. }

GetStreamRecord

GetStreamRecord is used to obtain each update record of a shard.

Example

Obtain the first 100 update records of a shard.

  1. private static void getShardIterator(SyncClient client, String shardIterator) {
  2. GetStreamRecordRequest streamRecordRequest = new GetStreamRecordRequest(shardIterator);
  3. streamRecordRequest.setLimit(100);
  4. GetStreamRecordResponse streamRecordResponse = client.getStreamRecord(streamRecordRequest);
  5. List<StreamRecord> records = streamRecordResponse.getRecords();
  6. for(int k=0;k<records.size();k++){
  7. System.out.println("record info:" + records.get(k).toString());
  8. }
  9. System.out.println("next iterator:" + streamRecordResponse.getNextShardIterator());
  10. }
Thank you! We've received your feedback.