mymarilyn / clickhouse-driver

ClickHouse Python Driver with native interface support
https://clickhouse-driver.readthedocs.io
Other
1.21k stars 213 forks source link

Exception when inserting into a Dynamic type #450

Open benedetto73 opened 2 months ago

benedetto73 commented 2 months ago

Describe the bug I get this error when trying to insert data into a a table with a dynamic type. Actually a map with Dynamic values. Insertions without dynamic types work fine.

Schema of the table:

# ColumnName DataType
1 EventReceivedTime DateTime64(3)
2 Name LowCardinality(String)
3 Type LowCardinality(String)
4 data Map(LowCardinality(String), Dynamic)

Error I get:

Traceback (most recent call last):
  File "C:\Users\bened\AppData\Local\Programs\Python\Python311\Lib\site-packages\clickhouse_driver\columns\service.py", line 139, in get_column_by_spec
    cls = column_by_type[spec]
          ~~~~~~~~~~~~~~^^^^^^
KeyError: 'Dynamic'

To Reproduce

        record = (
                EventReceivedTime,
                Name,
                Type
                ,
                json.dumps({
                    'clientID': clientID,
                    'message' : message
                })
         )
        records.append(record)

        query = f'INSERT INTO {table_name} (EventReceivedTime,Name,Type,data) VALUES'
        client.execute(query, records)

Expected behavior I would expect the code to work unless Dynamc types aren't explicitly supported.

Versions

xzkostyan commented 2 months ago

Hi.

How do you expect this should work if driver doesn't know anything about Dynamic type?

benedetto73 commented 2 months ago

How would I know that the driver doesn't know about the Dynamic type? I would expect the driver to support all ClickHouse features.

xzkostyan commented 2 months ago

Feel free to make a PR if you want it asap.

xzkostyan commented 2 months ago

You can see all the supported types in the driver docs: https://clickhouse-driver.readthedocs.io/en/latest/types.html