Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems while inserting into a table with a Tuple column #417

Open
michael-tsel opened this issue Feb 23, 2024 · 0 comments
Open

Problems while inserting into a table with a Tuple column #417

michael-tsel opened this issue Feb 23, 2024 · 0 comments

Comments

@michael-tsel
Copy link

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:

  1. client.query_dataframe("SELECT * FROM tt", settings={'use_numpy': False})
    which gives a dataframe of form:
         a
0 	(0.0, 0.0)
  1. 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant