titledescription
InfluxDB line protocol
This document describes how to write data into QuestDB using InfluxDB line protocol with details on the message format and hints for troubleshooting common issues

QuestDB exposes a reader for InfluxDB line protocol which allows using QuestDB as a drop-in replacement for InfluxDB and other systems which implement this protocol. This guide provides practical details of using InfluxDB line protocol to send data to QuestDB, with hints for formatting messages to ensure that QuestDB correctly parses incoming data as the desired data type.

For more details on configuring the QuestDB server with ingestion settings, refer to the InfluxDB API reference.

Message format

InfluxDB line protocol messages have the following syntax:

  1. table_name,tagset fieldset timestamp

The data of each row is serialized in a “pseudo-CSV” format where each line is composed of the following:

  • the table name followed by a comma
  • several comma-separated items of tags in the format <label>=<value> followed by a space
  • several comma-separated items of fields in the format <label>=<value> followed by a space
  • an optional timestamp for the record
  • a newline character \n

A single line of text in line protocol format represents one table row QuestDB. Consider the following InfluxDB line protocol message:

  1. sensors,location=london-1 temperature=22 1465839830100400200

This would create a new row in the sensors table with the following contents:

locationtemperaturetimestamp
london-1221465839830100400200

InfluxDB terminology

InfluxDB have the following description of the elements of line protocol:

  1. measurementName,tagKey=tagValue fieldKey="fieldValue" 1465839830100400200
  2. --------------- --------------- --------------------- -------------------
  3. | | | |
  4. Measurement Tags Fields Timestamp

In the context of QuestDB, it should be noted that the measurementName element equates to a table name.

Naming restrictions

Tag keys and field keys in InfluxDB line protocol messages equate to column names. In QuestDB, column names cannot contain the following characters, and as such, tag and field keys must not contain any of the following characters:

  1. [whitespace]
  2. .
  3. ?
  4. ,
  5. :
  6. \
  7. /
  8. \\
  9. \0
  10. )
  11. (
  12. _
  13. +
  14. *
  15. ~
  16. %

Differences with InfluxDB

In InfluxDB, table names, tag keys, and field keys cannot begin with an underscore _. This restriction is not enforced in QuestDB, and therefore the following InfluxDB line protocol message will produce a valid row in QuestDB:

  1. _sensor_data,_sensor=london_1 _value=12.4,string="sensor data, rev 1"

Note that spaces and commas do not require an escaping backslash in the field value for string.

Data types

Field values may be parsed by QuestDB as one of the following types:

  • double
  • long
  • boolean
  • string

All subsequent field values must match the type of the first row written to a given column.

:::info

For details on the available data types in QuestDB, see the data types reference.

:::

Strings

If field values are passed string types, the field values must be double-quoted. Special characters are supported without escaping:

  1. sensors,location=london temperature=22,software_version="A.B C-123"
  2. sensors,location=london temperature=22,software_version="SV .#_123"

For string types in QuestDB, the storage is allocated as 32+n*16 bits where n is the string length with a maximum value of 0x7fffffff.

Numeric

The default numerical type is a 64-bit double type. To store numeric values as integers, a trailing i must follow the value. The following line protocol message adds a long type integer column for temperature:

  1. sensors,location=london temperature=22,temp_int=22i

The sensors table would have the following row added:

columntypevalue
locationstringlondon
temperaturedouble22
temp_intlong integer22

QuestDB handles long types as a signed integer from 0x8000000000000000L to 0x7fffffffffffffffL.

Boolean

Boolean values can be passed in InfluxDB line protocol messages with any of the following:

TypeVariants
TRUEt, T, true, True
FALSEf, F, false, False

The following example adds a boolean type column called warning:

  1. sensors,location=london temperature=22,warning=false

Table schema

It is not necessary to create a table schema for messages passed via InfluxDB line protocol. A table will be dynamically created if one does not exist. If new columns are added as field or tag sets, the table is automatically updated to reflect the new structure and the new column will be back-propagated with null values.

When new tables are created by inserting records via InfluxDB line protocol, a default partitioning strategy by DAY is applied. This default can be overridden by means of passing server configuration for line.tcp.default.partition.by, i.e.

  1. line.tcp.default.partition.by=MONTH

For information describing how to pass server settings to QuestDB, see the configuration documentation page.

QuestDB listener configuration

QuestDB can ingest line protocol packets both over TCP and UDP with the following defaults:

  • InfluxDB TCP listener on port 9009 by default
  • InfluxDB UDP listener on port 9009 by default

For more details on configuring how QuestDB ingests InfluxDB line protocol messages, including setting alternative ports, refer to the following server configuration references:

Examples

The following basic Python example demonstrates how to stream InfluxDB line protocol messages to QuestDB over TCP. For more examples using different languages, see the insert data documentation.

  1. import time
  2. import socket
  3. # For UDP, change socket.SOCK_STREAM to socket.SOCK_DGRAM
  4. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  5. try:
  6. sock.connect(('localhost', 9009))
  7. # Single record insert
  8. sock.sendall(('trades,name=client_timestamp value=12.4 %d\n' %(time.time_ns())).encode())
  9. # Omitting the timestamp allows the server to assign one
  10. sock.sendall(('trades,name=server_timestamp value=12.4\n').encode())
  11. # Streams of readings must be newline-delimited
  12. sock.sendall(('trades,name=ilp_stream_1 value=12.4\ntrades,name=ilp_stream_2 value=11.4\n').encode())
  13. except socket.error as e:
  14. print("Got error: %s" % (e))
  15. sock.close()