简体中文 | English
The TDengineWriter plugin enables writing data to the target table of the TDengine database. At the bottom level, TDengineWriter connects TDengine through JDBC, executes insert statement /schemaless statement according to TDengine SQL syntax, and writes data to TDengine.
TDengineWriter can be used as a data migration tool for DBAs to import data from other databases into TDengine.
TDengineWriter obtains the protocol data generated by Reader through DataX framework, connects to TDengine through JDBC Driver, executes insert statement /schemaless statement, and writes the data to TDengine.
In TDengine, table can be divided into super table, sub-table and ordinary table. Super table and sub-table include Column and Tag. The value of tag column of sub-table is fixed value. (details please refer to: data model)
The TDengineWriter can write data to super tables, sub-tables, and ordinary tables using the following methods based on the type of the table and whether the column parameter contains TBName:
Table is a super table and column specifies tbname: use the automatic insert statement to create the table and use tbname as the name of the sub-table.
Table is a super table and column does not contain tbname: use schemaless to write the table. TDengine will auto-create a tbname based on the super table name and tag value.
Table is a sub-table: Use insert statement to write, ignoreTagUnmatched parameter is true, ignore data in record whose tag value is inconsistent with that of table.
Table is a common table: use insert statement to write data.
Configure a job to write to TDengine
Create a supertable on TDengine:
create database if not exists test;
create table test.weather (ts timestamp, temperature int, humidity double) tags(is_normal bool, device_id binary(100), address nchar(100));
Write data to TDengine using the following Job configuration:
{
"job": {
"content": [
{
"reader": {
"name": "streamreader",
"parameter": {
"column": [
{
"type": "string",
"value": "tb1"
},
{
"type": "date",
"value": "2022-02-20 12:00:01"
},
{
"type": "long",
"random": "0, 10"
},
{
"type": "double",
"random": "0, 10"
},
{
"type": "bool",
"random": "0, 50"
},
{
"type": "bytes",
"value": "abcABC123"
},
{
"type": "string",
"value": "北京朝阳望京"
}
],
"sliceRecordCount": 1
}
},
"writer": {
"name": "tdenginewriter",
"parameter": {
"username": "root",
"password": "taosdata",
"column": [
"tbname",
"ts",
"temperature",
"humidity",
"is_normal",
"device_id",
"address"
],
"connection": [
{
"table": [
"weather"
],
"jdbcUrl": "jdbc:TAOS-RS://192.168.56.105:6041/test"
}
],
"batchSize": 100,
"ignoreTagsUnmatched": true
}
}
}
],
"setting": {
"speed": {
"channel": 1
}
}
}
}
username
password
table
column
batchSize
ignoreTagsUnmatched
Data types in datax that can be mapped to data types in TDengine
DataX Type | TDengine Type |
---|---|
INT | TINYINT, SMALLINT, INT |
LONG | TIMESTAMP, TINYINT, SMALLINT, INT, BIGINT |
DOUBLE | FLOAT, DOUBLE |
STRING | TIMESTAMP, BINARY, NCHAR |
BOOL | BOOL |
DATE | TIMESTAMP |
BYTES | BINARY |
Here are some examples of data sources migrating to TDengine
Sample | Configuration |
---|---|
TDengine to TDengine | super table to super table with tbname |
TDengine to TDengine | super table to super table without tbname |
TDengine to TDengine | super table to sub-table |
TDengine to TDengine | table to table |
RDBMS to TDengine | table to super table with tbname |
RDBMS to TDengine | table to super table without tbname |
RDBMS to TDengine | table to sub-table |
RDBMS to TDengine | table to table |
OpenTSDB to TDengine | metric to table |
Yes, TDengineWriter parses the data from the Datax in the order of the fields in the column.