Connect to and use the time series engine using Lindorm-cli

更新时间:
复制 MD 格式

Lindorm-cli is a lightweight command line interface provided by Lindorm for connecting to and managing Lindorm databases. You can use Lindorm-cli to perform basic SQL operations such as creating tables, querying data, and writing data. This topic describes how to connect to and use the Lindorm time series engine.

Prerequisites

Add your client IP address to the Lindorm whitelist. For more information, see Set a whitelist.

Step 1: Install Lindorm-cli

  1. Download the Lindorm-cli installation package for your operating system. The download links are listed in the following table.

    Note

    The SHA256 checksums in the table verify the integrity and authenticity of the downloaded Lindorm-cli packages.

    Operating system

    Download link

    SHA256 checksum

    Linux

    lindorm-cli for linux

    To download from the command line:

    wget https://tsdbtools.oss-cn-hangzhou.aliyuncs.com/lindorm-cli-linux-latest.tar.gz

    3a9ee33e24769cf47b3a90c3a1bba29d26f8aede7a64dbc13ea1f4f5426f04e4

    Linux-arm64

    lindorm-cli for linux-arm64

    To download from the command line:

    wget https://tsdbtools.oss-cn-hangzhou.aliyuncs.com/lindorm-cli-linux-arm64-latest.tar.gz

    bc723d4a3a14a85c973c7082a56bb4934a40d2b9cccd72b5767352b8c334ce19

    Mac (Intel chip)

    lindorm-cli for mac

    34efd3f43a700e1fea72ee5e5933b9df3cf624569bcf59a2f8a6752dc7faab6c

    Mac (Apple silicon)

    lindorm-cli for mac

    0be9b346404a37d953714377b59f06b6492ff9c4e46dba4d5bf07c390ee284ad

    Windows

    lindorm-cli for windows-x64

    0be9b346404a37d953714377b59f06b6492ff9c4e46dba4d5bf07c390ee284ad

  2. Extract the installation package.

    For Linux, run the following command to extract the package:

    tar zxvf lindorm-cli-linux-latest.tar.gz

    After extraction, the lindorm-cli-linux-latest folder contains the lindorm-cli file.

Step 2: Connect to the Lindorm time series engine

Client deployed on Linux or Mac

  1. Go to the directory that contains the lindorm-cli file.

    cd <lindorm-cli directory>
  2. Run the following command to connect to the time series engine:

    ./lindorm-cli -url <Lindorm time series SQL endpoint> -username <username> -password <password> -database <target database name>

    Connection example

    ./lindorm-cli -url jdbc:lindorm:tsdb:url=http://ld-4xo90g5i370cu****-proxy-tsdb.lindorm.rds.aliyuncs.com:8242 -username user -password test -database default

    Parameter description

    Parameter

    Required

    Description

    Lindorm time series SQL endpoint

    Yes

    The time series SQL endpoint of the Lindorm time series engine. Example: jdbc:lindorm:tsdb:url=http://ld-bp12pc23yfb3*****-proxy-tsdb-pub.lindorm.rds.aliyuncs.com:8242.

    Note

    The Lindorm-cli connection method also supports the time series HTTP endpoint.

    Username

    No

    The username for connecting to the Lindorm time series engine.

    If user authentication and permission verification are disabled for the time series engine, you do not need to specify a username or password. For more information, see User and permission management.

    Password

    No

    The password for connecting to the Lindorm time series engine. If you forget your password, reset it in the cluster management system of the Lindorm wide-table engine. For more information, see Change user passwords.

    Target database name

    No

    The database to connect to using Lindorm-cli. The default database is default. During the session, switch to another database by running use <target database name>.

    A successful connection returns the following output:

    lindorm-cli version: 1.0.xx

    Here, 1.0.xx is the Lindorm-cli version number.

Client deployed on Windows

Method 1

  1. Open Command Prompt (CMD) and go to the directory that contains lindorm-cli.exe.

    cd <lindorm-cli.exe directory>
  2. In CMD, run the following command to connect to the time series engine:

    lindorm-cli -url <Lindorm time series SQL endpoint> -username <username> -password <password> -database <target database name>

    A successful connection returns the following output:

    Connected to jdbc:lindorm:tsdb:url=http://****-proxy-tsdb-pub.lindorm.rds.aliyuncs.com:8242
    lindorm-cli version: 1.0.xx

    Here, 1.0.xx is the Lindorm-cli version number.

Method 2

Double-click Lindorm-cli.exe to open the program and run the following command:

connect <Lindorm time series SQL endpoint> <username> <password> -database <target database name>

A successful connection returns no output.

Step 3: Use the Lindorm time series engine

Create a table

  1. Create a time series table.

    CREATE TABLE sensor (
        device_id VARCHAR NOT NULL,
        region VARCHAR NOT NULL,
        time TIMESTAMP NOT NULL,
        temperature DOUBLE,
        humidity BIGINT,
        PRIMARY KEY(device_id, region, time)
    );
    Note
    • When creating a time series table, specify a primary key (PRIMARY KEY). The Basic Edition does not support PRIMARY KEY. Typically, use a unique identifier from your data source as the PRIMARY KEY. Examples include device ID in Internet of Things scenarios, vehicle ID in Internet of vehicles scenarios, application ID in monitoring scenarios, or ip:port.

    • The column name for the timestamp must be time, which represents the data timestamp in milliseconds (ms).

  2. Verify that the table sensor was created successfully.

    SHOW TABLES;

    The query result is as follows:

    +-------------------+
    | Tables_In_default |
    +-------------------+
    | sensor            |
    +-------------------+
  3. View the columns of the time series table.

    DESCRIBE TABLE sensor;

    The query result is as follows:

    +-------------+-----------+------------+------------+--------------+
    | columnName  | typeName  | columnKind | primaryKey | partitionTag |
    +-------------+-----------+------------+------------+--------------+
    | device_id   | VARCHAR   | TAG        | true       | true         |
    | region      | VARCHAR   | TAG        | true       | true         |
    | time        | TIMESTAMP | TIMESTAMP  | true       | false        |
    | temperature | DOUBLE    | FIELD      | false      | false        |
    | humidity    | BIGINT    | FIELD      | false      | false        |
    +-------------+-----------+------------+------------+--------------+

Write data

Note

If two data points have identical tag values and timestamps, they are considered the same data point. The later write overwrites the earlier one.

  • Write data one row at a time.

    INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1260','north-cn','2021-04-22 15:33:00',12.1,45);
    INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1260','north-cn','2021-04-22 15:33:10',13.2,47);
    INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1260','north-cn','2021-04-22 15:33:20',10.6,46);
    INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1261','south-cn','2021-04-22 15:33:00',18.1,44);
    INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1261','south-cn','2021-04-22 15:33:10',19.7,44);
  • Write data in batches.

    INSERT INTO sensor (device_id, region, time, temperature, humidity) 
    VALUES ('F07A1260','north-cn','2021-04-22 15:33:00',12.1,45),
           ('F07A1260','north-cn','2021-04-22 15:33:10',13.2,47),
           ('F07A1260','north-cn','2021-04-22 15:33:20',10.6,46),
           ('F07A1261','south-cn','2021-04-22 15:33:00',18.1,44),
           ('F07A1261','south-cn','2021-04-22 15:33:10',19.7,44);

Query data

Conditional query

Query data for device F07A1260 between 2021-04-22 15:33:00 and 2021-04-22 15:33:20:

SELECT device_id,region,time,temperature,humidity FROM sensor WHERE device_id = 'F07A1260' AND time >= '2021-04-22 15:33:00' AND time <= '2021-04-22 15:33:20';

The query result is as follows:

+-----------+----------+---------------------------+-------------+----------+
| device_id |  region  |           time            | temperature | humidity |
+-----------+----------+---------------------------+-------------+----------+
| F07A1260  | north-cn | 2021-04-22T15:33:00+08:00 | 12.1        | 45       |
| F07A1260  | north-cn | 2021-04-22T15:33:10+08:00 | 13.2        | 47       |
| F07A1260  | north-cn | 2021-04-22T15:33:20+08:00 | 10.6        | 46       |
+-----------+----------+---------------------------+-------------+----------+

Downsampling query

A downsampling query reduces the sample rate of time series data to decrease the number of data points in the result set.

The following example queries the temperature for device F07A1260 between 2021-04-22 15:33:00 and 2021-04-22 15:33:20, downsamples the data every 20 seconds, and returns the maximum value:

SELECT device_id,region,time,max(temperature) AS max_temperature FROM sensor WHERE device_id = 'F07A1260' AND time >= '2021-04-22 15:33:00' AND time <= '2021-04-22 15:33:20' SAMPLE BY 20s;

The query result is as follows:

+-----------+----------+---------------------------+-----------------+
| device_id |  region  |           time            | max_temperature |
+-----------+----------+---------------------------+-----------------+
| F07A1260  | north-cn | 2021-04-22T15:33:00+08:00 | 13.2            |
| F07A1260  | north-cn | 2021-04-22T15:33:20+08:00 | 10.6            |
+-----------+----------+---------------------------+-----------------+

Aggregate query

Calculate the maximum temperature across all regions:

SELECT region,max(temperature) AS max_temperature FROM sensor WHERE time >= '2021-04-22 15:33:00' AND time <= '2021-04-22 15:33:20' GROUP BY region;

The query result is as follows:

+----------+-----------------+
|  region  | max_temperature |
+----------+-----------------+
| north-cn | 13.2            |
| south-cn | 19.7            |
+----------+-----------------+

Common Lindorm-cli commands

  • help: View help.

  • connect: Connect to a server.

  • precision: Set the time display format. Supported formats: rfc3339, h, m, s, ms, u, or ns.

  • exit or quit: Exit the current connection to the Lindorm time series engine.

FAQ

Why is the query result empty after successful data insertion?

If a query returns no data after a successful write, check whether the database has a time-to-live (TTL) setting by running DESCRIBE DATABASE <database name>. Data older than the TTL is automatically deleted and cannot be queried.

Can Lindorm-cli import or export time series data?

  • For small data volumes, you can use Lindorm-cli to quickly import or export CSV files. Contact Lindorm technical support (DingTalk ID: s0s3eg3) if needed.

  • For large data volumes, import data using DataX. Exporting large-scale data is not supported.