You can access Tablestore in the Tablestore console, in the Tablestore CLI, or by using Tablestore SDKs. You can get started with Tablestore in the Tablestore CLI. This topic describes how to manage the TimeSeries model in the Tablestore CLI.

Step 1: Download and start the Tablestore CLI

  1. Download the Tablestore CLI package based on your operating system.
    Operating systemDownload link
    WindowsWindows10
    Linux
    macOSmacOS
  2. Decompress the Tablestore CLI package that you downloaded. Go to the root directory of the Tablestore CLI and select a method that is used to start the Tablestore CLI based on your operating system.
    • For Windows, double-click the ts.exe file.
    • For Linux or macOS, run the ./ts command.
      Note If you do not have execute permissions to run the command in Linux or macOS, run the chmod 755 ts command to obtain permissions and start the Tablestore CLI.
    The following code shows a sample Tablestore startup interface:
    # Welcome to use Command Line Tool for Aliyun Tablestore. Current Version is '2021-11-11'.
    #    _______      _      _              _
    #   |__   __|    | |    | |            | |
    #      | |  __ _ | |__  | |  ___   ___ | |_   ___  _ __    ___
    #      | | / _' || '_ \ | | / _ \ / __|| __| / _ \ | '__| / _ \
    #      | || (_| || |_) || ||  __/ \__ \| |_ | (_) || |   |  __/
    #      |_| \__,_||_.__/ |_| \___| |___/ \__| \___/ |_|    \___|
    #
    # Please visit our product website: https://www.aliyun.com/product/ots
    # You can also join our DingTalk Chat Group (ID: 11789671 or 23307953) to discuss and ask Tablestore related questions.
    #
    tablestore>

Step 2: Activate Tablestore

If Tablestore is activated, skip this operation. You must activate Tablestore only once. You are not charged when you activate Tablestore.

  1. Run the config command to configure the AccessKey pair information.
    Important An AccessKey pair, which consists of the AccessKey ID and the AccessKey secret of an Alibaba Cloud account, is required. For information about how to obtain an AccessKey pair, see Obtain an AccessKey pair.
    config --id NTSVLeBHzgX2iZfcaXXPJ**** --key 7NR2DiotscDbauohSq9kSHX8BDp99bjs7eNpCR7o****
  2. Run the enable_service command to activate Tablestore.

Step 3: Create an instance for the TimeSeries model

For more information, see Create an instance for the TimeSeries model.

Step 4: Configure access information

Run the config command to configure access information.

The following sample code shows how to configure access information for the instance named myinstance:

config --endpoint https://myinstance.cn-hangzhou.ots.aliyuncs.com --instance myinstance --id NTSVLeBHzgX2iZfcaXXPJ**** --key 7NR2DiotscDbauohSq9kSHX8BDp99bjs7eNpCR7o****

Step 5: Create and use a time series table

After you create a time series table, you can perform operations on the table or on the data in the table.

  1. Run the following command to create a time series table named mytable:
    create -m timeseries -t mytable --ttl -1
  2. Run the use --ts -t mytable command to use the time series table named mytable.

Step 6: Perform operations on data

Perform operations on data based on your business requirements. You can write time series data, import time series data, query time series data, retrieve time series, scan time series, and update time series.

  • Write time series data

    Insert a row of time series data.

    putts --k '["cpu","localhost",["region=hangzhou","os=ubuntu"]]' --field '[{"c":"fieldname","v":"fieldvalue"},{"c":"bool_field","v":true},{"c":"double_field","v":1.1},{"c":"int_value","v":10,"isint":true}]' --time 1635162859000000
  • Import time series data

    Import the time series data from the import_timeseries.txt file to a time series table.

    import_timeseries --input /temp/import_timeseries.txt
    The following example shows the content of a configuration file:
    cpu,hostname=host_0,region=cn-hangzhou usage_user=58i,usage_system=2i,usage_idle=24i 1609459200000000000
    cpu,hostname=host_1,region=cn-hangzhou usage_user=58i,usage_system=2i,usage_idle=24i 1609459200000000000
  • Query time series data

    Query all time series data that is generated before 1667638230000000 in the time series whose metric name is cpu, data source is localhost, and tags are "region=hangzhou" and "os=ubuntu".

    getts --k '["cpu","localhost",["region=hangzhou","os=ubuntu"]]' --time_start 0 --time_end 1667638230000000 --limit 100
  • Retrieve time series
    Retrieve the time series whose metric name is cpu and data source is localhost.
    query_ts_meta --measurement cpu --datasource localhost --limit 10
  • Scan time series
    query_ts_meta --limit 10
  • Update time series

    Modify the properties of the specified time series to "city=nanjing" and "region=jiangning".

    update_ts_meta --k '["cpu","localhost",["city=hangzhou","region=xihu"]]' --attrs '["city=nanjing","region=jiangning"]' 

Step 7: Use SQL to query data

To use SQL statements to quickly query data in a table, perform the following steps:

  1. Run the sql command to enter the SQL mode.
  2. Run the following command to query all data in the table named mytable:
    SELECT * FROM mytable;

If you want to exit the SQL mode, run the exit; command.