Tablestore provides basic data operations to write, read, and delete data. This topic describes the methods that are available to perform basic data operations by using Tablestore SDK for Java and the scenarios of the methods.
Write data
You can use the following methods to write data to data tables: insert a single row of data, update a single row of data, and write multiple rows of data at the same time. When you write data, you can specify a custom data version number and use the conditional update feature to configure the conditions for writing data. For more information, see Write data.
Method | Description | Scenario |
Write a single row of data | You can call the PutRow operation to write a single row of data. | This method is suitable for scenarios in which you want to write a small amount of data. |
Update a single row of data | You can call the UpdateRow operation to update a single row of data. | This method is suitable for scenarios in which you want to update a small amount of data. |
Write multiple rows of data at the same time | You can call the BatchWriteRow operation to write multiple rows of data to one or more tables at the same time. | This method is suitable for scenarios in which you want to write, delete, or update a large amount of data and scenarios in which you want to write, delete, and update data at the same time. |
Read data
You can use the following methods to read data from data tables: read a single row of data, read multiple rows of data at the same time, read data whose primary key values are within a specific range, read data by using an iterator, and concurrently read data. When you read data, you can specify the columns that you want to return, use the filter feature to filter row data, and specify the version range or a specific version of data that you want to return. For more information, see Read data.
Method | Description | Scenario |
Read a single row of data | You can call the GetRow operation to read a single row of data. | This method is suitable for scenarios in which the values of all primary key columns of the row that you want to read can be determined and the number of rows that you want to read is small. |
Read multiple rows of data at the same time | You can call the BatchGetRow operation to read multiple rows of data from one or more tables at the same time. The BatchGetRow operation consists of multiple GetRow operations. When you call the BatchGetRow operation, the process of constructing each GetRow operation is the same as the process of constructing the GetRow operation when you call the GetRow operation. | This method is suitable for scenarios in which the values of all primary key columns of the rows that you want to read can be determined and the number of rows that you want to read is large or you want to read data from multiple tables. |
Read data whose primary key values are within a specific range | You can call the GetRange operation to read data whose primary key values are within a specific range. The GetRange operation allows you to read data whose primary key values are in the specified range in a forward or backward direction. You can also specify the number of rows to read. If the range is large and the number of scanned rows or the volume of scanned data exceeds the upper limit, the scan stops, and the rows that are read and information about the primary key of the next row are returned. You can initiate a request to start from where the last operation left off and read the remaining rows based on the information about the primary key of the next row returned by the previous operation. | This method is suitable for scenarios in which the range of primary key values or the prefix of primary key values of the rows that you want to read can be determined. |
Read data by using an iterator | You can read data from data tables by using an iterator. | This method is suitable for scenarios in which the range of primary key values or the prefix of primary key values of the rows that you want to read can be determined and you want to read a large amount of data. |
Concurrently read data | Tablestore SDK for Java provides the TableStoreReader class that encapsulates the BatchGetRow operation. You can use this class to concurrently query data of a data table. TableStoreReader also supports multi-table queries, statistics on query status, row-level callback, and custom configurations. | This method is suitable for scenarios in which the values of all primary key columns of the rows that you want to read can be determined and the number of rows that you want to read is large or you want to read data from multiple tables. |
Delete data
You can delete data from data tables by using the following methods: delete a single row of data and delete multiple rows of data at the same time. When you delete data, you can use the conditional update feature to configure the conditions for deleting data. For more information, see Delete data.
Method | Description | Scenario |
Delete a single row of data | You can call the DeleteRow operation to delete a single row of data. If the row that you want to delete does not exist, the data table remains unchanged. | This method is suitable for scenarios in which you want to delete a small amount of data. |
Delete multiple rows of data at the same time | After you obtain the primary key information of the rows that you want to delete, you can delete the rows at the same time based on the primary key information. | This method is suitable for scenarios in which you want to delete a large amount of data. |