Skip to content

IoTDB Sink

The sink writes data into Apache IoTDB using the native Thrift RPC client. It supports both the tree model and the table model.

Compile the plugins

In eKuiper source code root path, run the below command:

shell
go build -trimpath --buildmode=plugin -o plugins/sinks/Iotdb.so extensions/sinks/iotdb/*.go

Properties

Connection properties:

Property nameOptionalDefault valueDescription
addrfalse127.0.0.1:6667IoTDB server address in host:port format.
usernametruerootThe username for authentication.
passwordtruerootThe password for authentication.
nodeUrlstrue[]Cluster node URLs. When set, it overrides the addr property.
timeouttrue5000Connection timeout in milliseconds.
poolSizetrue3The size of the connection pool.

Model selection:

Property nameOptionalDefault valueDescription
modelfalsetreeThe data model to use: tree or table.

Tree model properties (used when model=tree):

Property nameOptionalDefault valueDescription
devicetrue""The device path, e.g. root.sg1.dev1. Required for tree model.
isAlignedtruefalseWhether to use aligned time series.

Table model properties (used when model=table):

Property nameOptionalDefault valueDescription
databasetrue""The database name (without the root. prefix; it is automatically stripped). Required for table model.
tabletrue""The target table name. Required for table model.
columnCategoriestrue[]Column categories corresponding to measurements one-to-one: TAG, FIELD, or ATTRIBUTE. Required for table model.

Data mapping properties:

Property nameOptionalDefault valueDescription
measurementsfalse[]List of measurement / column names.
dataTypesfalse[]IoTDB data types corresponding to measurements one-to-one: INT32, INT64, FLOAT, DOUBLE, BOOLEAN, TEXT, STRING, TIMESTAMP.
tsFieldNametrue""The field name of the timestamp (in milliseconds). If not set, the current time will be used; when set, every row must contain this field.
batchSizetrue10The number of rows per tablet write.

Other common sink properties including batch settings are supported. Please refer to the sink common properties for more information.

Sample usage

Tree model example

Below is a sample rule for selecting temperature greater than 50 and writing into IoTDB using the tree model.

json
{
  "id": "iotdb_tree",
  "sql": "SELECT * from demo_stream where temperature > 50",
  "actions": [
    {
      "log": {},
      "iotdb": {
        "addr": "127.0.0.1:6667",
        "username": "root",
        "password": "root",
        "model": "tree",
        "device": "root.sg1.d1",
        "measurements": ["temperature", "humidity"],
        "dataTypes": ["FLOAT", "FLOAT"],
        "tsFieldName": "ts",
        "batchSize": 10
      }
    }
  ]
}

Table model example

Below is a sample rule for selecting temperature greater than 50 and writing into IoTDB using the table model.

json
{
  "id": "iotdb_table",
  "sql": "SELECT * from demo_stream where temperature > 50",
  "actions": [
    {
      "log": {},
      "iotdb": {
        "addr": "127.0.0.1:6667",
        "username": "root",
        "password": "root",
        "model": "table",
        "database": "iot_data",
        "table": "sensor_data",
        "measurements": ["device_id", "temperature", "humidity"],
        "dataTypes": ["STRING", "FLOAT", "FLOAT"],
        "columnCategories": ["TAG", "FIELD", "FIELD"],
        "tsFieldName": "ts",
        "batchSize": 10
      }
    }
  ]
}

Data Types

The following IoTDB data types are supported in the dataTypes property:

Data typeDescription
INT3232-bit signed integer
INT6464-bit signed integer
FLOATSingle-precision floating point
DOUBLEDouble-precision floating point
BOOLEANBoolean value (true / false)
TEXTText string (IoTDB legacy type)
STRINGString value
TIMESTAMPTimestamp value

Notes

  • IoTDB uses Thrift RPC protocol on port 6667 by default.
  • For table model, the database is automatically created if it does not exist.
  • The root. prefix in the database field is automatically stripped for table model.
  • Missing fields in the data will be written as null values to IoTDB.