questdb / py-questdb-client

Python client for QuestDB InfluxDB Line Protocol
https://py-questdb-client.readthedocs.io
Apache License 2.0
55 stars 10 forks source link

Line Protocols UInteger doesn't seam to be supported #8

Closed LLukas22 closed 2 years ago

LLukas22 commented 2 years ago

Can't find a way to insert unsigned integers as described here into my database.

When i try to provide the column value as an np.int64 or a ctypes.c_uint64 i get an unsupported type error. e.g.

    buffer.row(
        "interval",
        symbols={
            "foo":"bar",
            },
        columns={
            "volume": ctypes.c_uint64(1)
        },
        at=TimestampNanos(12345)
    )

throws

Unsupported type: <class 'ctypes.c_ulonglong'>. Must be one of: bool, int, float, str, TimestampMicros, datetime.datetime

When i provide the value as a python integer its always commited as a line protocol integer which leads to problems when dealing with huge numbers.

Is there a workaround for this behaviour or is this the intended behaviour?

amunra commented 2 years ago

The type is indeed not supported (by design). The way to do this is to cast it to the appropriate Python type: In this case int.

From a ctypes.c_uint64, call .value:

>>> import ctypes
>>> c_num = ctypes.c_uint64(42)
>>> type(c_num)
<class 'ctypes.c_ulong'>
>>> num = c_num.value
>>> type(num)
<class 'int'>

From a np.int64, pass it as arg to the int(..) builtin:

>>> import numpy as np
>>> np_num = np.int64(42)
>>> type(np_num)
<class 'numpy.int64'>
>>> num = int(np_num)
>>> type(num)
<class 'int'>

QuestDB itself does not support unsigned integers. All integers are signed.

See: https://questdb.io/docs/reference/sql/datatypes