30-influxdb-line.mdx 3.7 KB
Newer Older
1 2
---
title: InfluxDB Line Protocol
D
danielclow 已提交
3 4
sidebar_label: InfluxDB Line Protocol
description: This document describes how to insert data into TDengine using the InfluxDB Line Protocol.
5 6 7 8 9 10 11 12 13 14 15 16 17 18
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import JavaLine from "./_java_line.mdx";
import PyLine from "./_py_line.mdx";
import GoLine from "./_go_line.mdx";
import RustLine from "./_rust_line.mdx";
import NodeLine from "./_js_line.mdx";
import CsLine from "./_cs_line.mdx";
import CLine from "./_c_line.mdx";

## Introduction

19
In the InfluxDB Line protocol format, a single line of text is used to represent one row of data. Each line contains 4 parts as shown below.
20 21 22 23 24

```
measurement,tag_set field_set timestamp
```

25 26 27
- `measurement` will be used as the name of the STable Enter a comma (,) between `measurement` and `tag_set`.
- `tag_set` will be used as tags, with format like `<tag_key>=<tag_value>,<tag_key>=<tag_value>` Enter a space between `tag_set` and `field_set`.
- `field_set`will be used as data columns, with format like `<field_key>=<field_value>,<field_key>=<field_value>` Enter a space between `field_set` and `timestamp`.
28
- `timestamp` is the primary key timestamp corresponding to this row of data
29 30 31 32

For example:

```
33
meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611249500
34 35 36 37
```

:::note

38 39 40 41
- All the data in `tag_set` will be converted to NCHAR type automatically
- Each data in `field_set` must be self-descriptive for its data type. For example 1.2f32 means a value 1.2 of float type. Without the "f" type suffix, it will be treated as type double
- Multiple kinds of precision can be used for the `timestamp` field. Time precision can be from nanosecond (ns) to hour (h)
- The child table name is created automatically in a rule to guarantee its uniqueness. But you can configure `smlChildTableName` in taos.cfg to specify a tag value as the table names if the tag value is unique globally. For example, if a tag is called `tname` and you set `smlChildTableName=tname` in taos.cfg, when you insert `st,tname=cpu1,t1=4 c1=3 1626006833639000000`, the child table `cpu1` will be created automatically. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored
wmmhello's avatar
wmmhello 已提交
42
- It is assumed that the order of field_set in a supertable is consistent, meaning that the first record contains all fields and subsequent records store fields in the same order. If the order is not consistent, set smlDataFormat in taos.cfg to false. Otherwise, data will be written out of order and a database error will occur.(smlDataFormat in taos.cfg default to false after version of 3.0.1.3, smlDataFormat is discarded since 3.0.3.0)
43 44
- Due to the fact that SQL table names do not support point(.), schemaless has also processed point(.) and automatically replaced them with underscores(_)

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
45
:::
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

For more details please refer to [InfluxDB Line Protocol](https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/) and [TDengine Schemaless](/reference/schemaless/#Schemaless-Line-Protocol)

## Examples

<Tabs defaultValue="java" groupId="lang">
  <TabItem label="Java" value="java">
    <JavaLine />
  </TabItem>
  <TabItem label="Python" value="Python">
    <PyLine />
  </TabItem>
  <TabItem label="Go" value="go">
    <GoLine />
  </TabItem>
  <TabItem label="Node.js" value="nodejs">
    <NodeLine />
  </TabItem>
  <TabItem label="C#" value="csharp">
    <CsLine />
  </TabItem>
  <TabItem label="C" value="c">
    <CLine />
  </TabItem>
</Tabs>
wmmhello's avatar
wmmhello 已提交
71 72

## Query Examples
73

74
If you want query the data of `location=California.LosAngeles,groupid=2`, here is the query SQL:
75 76 77 78

```sql
SELECT * FROM meters WHERE location = "California.LosAngeles" AND groupid = 2;
```