Add a Tablestore data source

更新时间:
复制 MD 格式

Add a Tablestore data source to DataV and use it to query table data with the getRow or getRange operation.

Prerequisites

You have a Tablestore data source available.

Add a Tablestore data source

  1. Log on to the DataV console.

  2. On the My Data tab, select Data Source Management and click Add Data.

  3. From the Type list, select TableStore.

  4. Configure the following Tablestore parameters.

    Parameter

    Description

    Name

    The display name of the data source. You can enter any name.

    AK ID

    The AccessKey ID of the account that can access Tablestore.

    AK Secret

    The AccessKey secret of the account that can access Tablestore.

    Public network

    The endpoint of your Tablestore instance. Enter the endpoint based on the Tablestore instance that you want to access. Endpoints.

  5. Click OK.

    The data source appears in the data source list.

Use a Tablestore data source

  1. Log on to the DataV console.

  2. On the My Visualization page, hover the pointer over the visualization application that you want to edit, and then click Edit.

    Important

    If no visualization applications exist on the My Visualization page, create one. Create a PC visualization application using a template.

  3. On the canvas editor page, click a widget on the canvas.

    If the canvas has no widgets, add one. Add an asset.

  4. In the right-side configuration panel, click the Data tab, and then click Configure Data Source.

  5. On the Set Data Source page, set Data Source Type to TableStore.

  6. From the Select Existing Data Source list, select your Tablestore data source.

  7. From the Select Operation list, select an operation.

    Supported operations:

  8. In the Select Operation box, enter a query statement in JSON format.

    • The query parameter must be a JSON object.

    • If you select getRow, you can read a single row by primary key.

      Parameter format:

      {
          "table_name": "test",
          "rows": {
              "id": "1"
          },
          "columns": [
              "id",
              "test"
          ]
      }

      Parameter

      Description

      table_name

      The Tablestore table to query.

      rows

      The primary key of the row to read.

      Important

      If the table has multiple primary key columns, the number and data types of the columns that you set must match those of the table.

      columns

      The columns to return.

    • If you select getRange, you can read data within a specified primary key range. Parameter format:

      {
          "table_name": "test",
          "direction": "FORWARD",
          "columns": [
              "id",
              "test"
          ],
          "range": {
              "limit": 4,
              "start": {
                  "id": "InfMin"
              },
              "end": {
                  "id": "3"
              }
          }
      }

      Parameter

      Description

      table_name

      The Tablestore table to query.

      direction

      The read direction.

      • FORWARD: The start primary key must be smaller than the end primary key. Rows are returned in ascending order.

      • BACKWARD: The start primary key must be larger than the end primary key. Rows are returned in descending order.

      Example: A table has two primary keys A and B where A < B. A FORWARD read of [A, B) returns rows with primary keys >= A and < B, sorted from A to B. A BACKWARD read of [B, A) returns rows with primary keys > A and <= B, sorted from B to A.

      columns

      The columns to read. Can be primary key columns or attribute columns.

      If not specified, all columns are returned.

      Rows within the range that do not contain the specified columns are excluded from the result.

      limit

      The maximum number of rows to return. Must be greater than 0.

      The operation stops after returning this many rows, even if more data exists in the range.

      start

      The start and end primary keys for the range read. Both must be valid primary keys or virtual points of InfMin and InfMax types. The number of columns must match the table schema.

      InfMin represents negative infinity and is smaller than any other value. InfMax represents positive infinity and is larger than any other value.

      Important

      The number and data types of primary key columns must match the table schema.

      • start: The start primary key (inclusive).

      • end: The end primary key (exclusive).

      end

  9. Click Preview Data Source Response to verify the query result.

Example

  1. Prepare the Tablestore data.

    1. Log on to the Tablestore console.

    2. Create a Tablestore instance and a data table. Create an instance and Create a data table.

      The following example uses an instance named test with a data table containing three rows. Each row has two columns: id (primary key, integer) and test (string).Tablestore data

  2. Configure the data source.

  3. Query parameter

    • Query data using the getRow method.Query data by using the getRow method

      Data response:getRow query response

    • Query data using the getRange method.Query data by using the getRange method

      Data response:getRange query response

    Note

    When you use getRange with start set to id:InfMin and end set to id:3, two records are returned with id values 1 and 2. The row where id is 3 is excluded because the getRange end key specified by end is exclusive.