clickhouse-driver
clickhouse-driver copied to clipboard
Problems while inserting into a table with a Tuple column
Describe the bug
client.insert_dataframe() method throws if the table contains tuple column
To Reproduce Suppose I have the following table:
CREATE TABLE IF NOT EXISTS tt
(
a Tuple(x Float32, y Float32),
)
ENGINE = Memory;
INSERT INTO tt VALUES ((0.0, 0.0))
I can query this table in different ways:
client.query_dataframe("SELECT * FROM tt", settings={'use_numpy': False})which gives a dataframe of form:
a
0 (0.0, 0.0)
client.query_dataframe("SELECT * FROM tt", settings={'use_numpy': False, 'namedtuple_as_json': True, 'allow_experimental_object_type': 1})which gives a dataframe of form:
a
0 {'x': 0.0, 'y': 0.0}
However, I'm struggling with inserting new data. Both
df = pd.DataFrame([{'a': (0.1, 0.1),},])
db.client.insert_dataframe(f"INSERT INTO tt VALUES", df)
and
df = pd.DataFrame([{'a': {'x': 0.1, 'y': 0.1},},])
client.insert_dataframe(f"INSERT INTO tt VALUES", df)
throw this exception:
TypeError: 'NoneType' object is not iterable
The same but with settings={'use_numpy': False} throws:
TypeError: Unsupported column type: <class 'numpy.ndarray'>. list or tuple is expected.
So the only way I can insert new data at the moment is:
df = pd.DataFrame([{'a': (0.0, 0.1),},])
client.execute(f"INSERT INTO tt VALUES", df.values.tolist(), settings={'use_numpy': False})
The same with df = pd.DataFrame([{'a': {'x': 0.1, 'y': 0.1},},]) throws:
TypeMismatchError: Code: 53. Type mismatch in VALUES section. Repeat query with types_check=True for detailed info. Column a: required argument is not a float
Expected behavior
I expected at least one of client.insert_dataframe() above to work
Versions
- clickhouse-driver 0.2.7
- ClickHouse server 24.1.2.5
- Python 3.11.6.