Search code examples
questdb

How can I send IPv4 data type using QuestDB Java Sender?


I am trying to use QuestDB Sender from Java, one of my columns is IP address. How can I send it, there seems to be no option for IPv4, there is no choice for IPv4, only doubleColumn, symbol, longColumn methods.

sender.table("weather_sensor")
                        .symbol("id", "dubai2" + i%100)
                        .longColumn("temperature", 41)
                        .doubleColumn("humidity", 0.34)
                        .atNow();

Can I send IPv4 column types?


Solution

  • You can send IPv4 as String.

    The longer answer is that QuestDB client sends the data using Influx Line Protocol. Influx line protocol is has limited types, e.g.

    • String
    • Tag (symbol)
    • Integer
    • Floating Point
    • Boolean
    • Timestamp

    QuestDB supports more types. In order to for example send IPv4 one should create table with IPv4 first connecting via web console or Postgres protocol:

    CREATE TABLE weather_sensor (ip IPV4, ts timestamp) timestamp(ts) partition by DAY WAL;
    

    and then it's possible to send STRING values into ip column using Sender:

    sender.table("weather_sensor")
       .stringColumn("ip", "127.0.0.1")
       .atNow();
    

    Here is the type compatibility list:

    • String values can be accepted by: STRING, SYMBOL, VARCHAR, IPv4, UUID, TIMESTAMP
    • Long ILP values can be accepted by: BYTE, SHORT, INTEGER, LONG, TIMESTAMP, DATE
    • Double ILP values can be accepted by: FLOAT, DOUBLE
    • Tag ILP values can be accepted by: SYMBOL, STRING, VARCHAR