edit-icon download-icon

Read wide rows

Last Updated: Dec 07, 2018

Table Store supports functions such as reading a row with numerous columns and massive data, reading a row multiple times if the whole row cannot be read in one time, and can be optimized for better performance when you only need to read specified parts of a wide row.

Wide row and wide-row stream reading function

In Table Store, each row of a table consists of primary key columns and attribute columns. One primary key column forms a primary key in sequence, and is the unique identifier that determines a row. When reading or writing a row, you must specify the primary key of this row and then read or write attribute columns of this row.

The names and types of primary key columns are part of TableMeta and are determined during table creation. You do not need to specify the names and quantity of the attribute columns. When writing a row, you can set any names for the attribute columns of this row to better identify the data.

In a traditional database, a wide row generally refers to a row with many columns being written to it and containing large amounts of data. This can result in a performance bottleneck when attempting to read large amounts of data in one row. To address this issue, Table Store, in combination with support for unrestricted amounts of attribute columns and unrestricted row sizes, also supports the wide-stream reading function (Java SDK of version 4.0.0 or later is required). The wide-stream reading function reads parts of the column in one row, then reads the remaining columns multiple times.

Methods of reading a wide row

A wide row can be read in the following ways:

  • Use startColumn and endColumn to read the attribute columns within a certain range.

    In the GetRow parameter, you can use startColumn and endColumn to specify the start range and end range of the attribute columns for query (in lexicographical order). In this way, you can read the columns within the specified range of column names in a wide row.

    1. // Read a row.
    2. SingleRowQueryCriteria criteria = new SingleRowQueryCriteria(TABLE_NAME, primaryKey);
    3. // Set the range of columns to be read.
    4. criteria.setStartColumn("Col00000");
    5. criteria.setEndColumn("Col10000");
    6. // Set the latest version to be read.
    7. criteria.setMaxVersions(1);
    8. GetRowResponse getRowResponse = client.getRow(new GetRowRequest(criteria));
    9. Row row = getRowResponse.getRow();
  • Use ColumnPaginationFilter in conjunction with the startColumn parameter.

    ColumnPaginationFilter has two parameters: limit and offset. When ColumnPaginationFilter is used, the attribute columns whose quantity is equal to the value of offset parameter are skipped, and a number of attribute columns whose quantity is equal to the value of limit parameter are read. When the combination of ColumnPaginationFilter and startColumn is used, reading starts from the startColumn. In this case, the attribute columns whose quantity is equal to the value of offset parameter are skipped, and the attribute columns whose quantity is equal to the value of limit parameter are read. This method is suitable for scenarios where attribute columns are read page by page.

    1. // Read a row.
    2. SingleRowQueryCriteria criteria = new SingleRowQueryCriteria(TABLE_NAME, primaryKey);
    3. // Set the parameter so that reading starts from "ColumnX".
    4. criteria.setStartColumn("ColumnX");
    5. // Use ColumnPaginationFilter to set the number of columns for each read operation, namely, limit = 10, and offset = 0.
    6. criteria.setFilter(new ColumnPaginationFilter(10, 0));
    7. // Set the latest version to be read.
    8. criteria.setMaxVersions(1);
    9. GetRowResponse getRowResponse = client.getRow(new GetRowRequest(criteria));
    10. Row row = getRowResponse.getRow();
  • Use WideColumnIterator.

    Use WideColumnIterator in the SDK to read all the attribute columns in a row.

    1. SingleRowQueryCriteria criteria = new SingleRowQueryCriteria(TABLE_NAME, primaryKey);
    2. // Set the latest version to be read.
    3. criteria.setMaxVersions(1);
    4. WideColumnIterator wideColumnIterator = syncClient.createWideColumnIterator(new GetRowRequest(criteria));
    5. System.out.println(wideColumnIterator.getPrimaryKey());
    6. while (wideColumnIterator.hasNextColumn()) {
    7. System.out.println(wideColumnIterator.nextColumn());
    8. }

Conclusion

Table Store supports wide rows and free name and quantity for the attribute columns. This provides high flexibility for designing the table structure. When a table has wide rows, these rows cannot be read in common reading mode. In this case, you can use any of the preceding methods to read the wide rows. In addition, if wide rows are required during the design of the table structure, you must evaluate whether to convert the wide rows to multiple narrow rows to avoid the issues of reading the wide rows.

Thank you! We've received your feedback.