This topic describes how to add a Tablestore data source in DataV. It also describes related parameters.

Prerequisites

The Tablestore data source that you want to add exists.

Add a Tablestore data source

  1. Log on to the DataV console.
  2. Click the Data Sources tab and then Add Source.
  3. Select TableStore from the Type drop-down list.
  4. Enter information about the Tablestore data source.
    Add Data Source
    Parameter Description
    Name The name of the data source you want to add. You can set this parameter to a custom name.
    AK ID The AccessKey ID of the account that has the permissions to access the Tablestore data source.
    AK Secret The AccessKey secret of the account that has the permissions to access the Tablestore data source.
    Internet The endpoint of the Tablestore data source that you want to add. For more information, see Endpoint.
  5. After you enter the information about the Tablestore data source, click OK.

    The added data source is displayed in the data source list.

Use a Tablestore data source

  1. Log on to the DataV console.
  2. On the Projects tab, move the pointer over the project that you want to edit and click Edit.
  3. In Canvas Editor, click a widget on the canvas.

    If no widget is added to the canvas, add a widget first. For more information, see Add a widget.

  4. In the right-side configuration panel, click the Data tab and then Set.
    Data tab
  5. In the Configure Data Source panel, select TableStore from the Data Source Type drop-down list.
  6. In the Select Data Source section, select the configured Tablestore data source.
  7. In the Select Action section, select the operation that you want to perform.
    The system supports the following operations:
    • getRow: indicates the GetRow operation of Tablestore. For more information, see GetRow.
    • getRange: indicates the GetRange operation of Tablestore. For more information, see GetRange.
  8. In the code editor of the Select Action section, enter query statements.
    • Query parameters must be JSON objects.
    • If you select the getRow operation, a single row of data is read based on the specified primary key.

      The parameters are in the following format:

      {
          "table_name": "test",
          "rows": {
              "id": "1"
          },
          "columns": [
              "id",
              "test"
          ]
      }
      Parameter Description
      table_name The name of the Tablestore table that you want to query.
      rows The primary keys of the rows.
      Notice The number and data types of primary key columns specified for each row must be the same as those of primary key columns in the table.
      columns The names of the columns that you want to return.
    • If you select the getRange operation, a single row of data is read based on the specified primary key. The parameters are in the following format:
      {
          "table_name": "test",
          "direction": "FORWARD",
          "columns": [
              "id",
              "test"
          ],
          "range": {
              "limit": 4,
              "start": {
                  "id": "InfMin"
              },
              "end": {
                  "id": "3"
              }
          }
      }
      Parameter Description
      table_name The name of the Tablestore table that you want to query.
      direction The direction to read data.
      • If this parameter is set to FORWARD, the value of the start primary key must be less than that of the end primary key. The returned rows are sorted in ascending order based on their primary key values.
      • If this parameter is set to BACKWARD, the value of the start primary key must be greater than that of the end primary key, and the returned rows are sorted in descending order based on their primary key values.

      For example, a table has two primary keys: A and B. The value of A is less than that of B. If you set direction to FORWARD, the rows whose primary key values are greater than or equal to the value of A and less than the value of B are returned in ascending order from A to B. If you set direction to BACKWARD, the rows whose primary key values are greater than the value of A and less than or equal to the value of B are returned in descending order from B to A.

      columns The columns to read. The column name can be the primary key column or attribute column.

      If you do not specify this parameter, all data in the row is returned.

      If a row is within the specified range of primary key values to read but does not contain the specified columns to return, the row of data is not returned.

      limit The maximum number of rows to return. The value of this parameter must be greater than 0.

      An operation stops when the maximum number of rows are returned in a forward or backward direction, even if a part of rows within the specified range are not returned.

      start The start and end primary keys of the range to read. The start and end primary keys must be valid primary keys or virtual points that consist of the InfMin and InfMax type data. The number of columns for each virtual point must be the same as that of each primary key.

      InfMin indicates an infinitely small value. All values of other types are greater than InfMin. InfMax indicates an infinitely great value. All values of other types are less than InfMax.

      Notice The number and data types of primary key columns specified for each row must be the same as those of primary key columns in the table.
      • start indicates the start primary key. If the row that contains the start primary key exists, the row of data is returned.
      • end indicates the end primary key. No matter whether the row that contains the end primary key exists, the row of data is not returned.
      end
  9. Click Preview Data Response to view the returned data.

Example

  1. Prepare Tablestore data.
    1. Log on to the Tablestore console.
    2. Create instances and tables in the Tablestore console. For more information, see Create instances and Create tables.
      The test instance is created. A table is created for this instance and contains three rows of data and two columns: id(Primary Key) and test. The id(Primary Key) column is of the INTEGER type. The test column is of the STRING type. The following figure shows the table details. Tablestore data
  2. Configure the Tablestore data source.
    Configure the Tablestore data source
  3. Query parameters.
    • Query data by using getRow. Query data by using getRow
      The following results are returned. Query results
    • Query data by using getRange. Query data by using getRange
      The following results are returned. Query results
    Note If you query data by using getRange, start is id: InfMin, and end is id: 3. Therefore, data of the row with id of 1 and the row with id of 2 is obtained. This is because getRange neither contains the end row nor the row with id of 3.