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

Insert UUID column parse error if value is None #387

Open
gistart opened this issue Aug 11, 2023 · 3 comments
Open

Insert UUID column parse error if value is None #387

gistart opened this issue Aug 11, 2023 · 3 comments

Comments

@gistart
Copy link

gistart commented Aug 11, 2023

Describe the bug
If value of uuid column is null on insert, TypeError is raised instead of errors.CannotParseUuidError

...
File "/usr/local/lib/python3.11/site-packages/clickhouse_driver/columns/base.py", line 148, in _write_data
    prepared = self.prepare_items(items)
File "/usr/local/lib/python3.11/site-packages/clickhouse_driver/columns/base.py", line 137, in prepare_items
    self.before_write_items(items, nulls_map=nulls_map)
File "/usr/local/lib/python3.11/site-packages/clickhouse_driver/columns/uuidcolumn.py", line 57, in before_write_items
    item = UUID(item)
File "/usr/local/lib/python3.11/uuid.py", line 172, in __init__
    raise TypeError('one of the hex, bytes, bytes_le, fields, '
TypeError: one of the hex, bytes, bytes_le, fields, or int arguments must be given

To Reproduce

clickhouse_client.execute('insert into tbl (uuid_field) values ', [{None}])

Expected behavior
To simplify error handling, it would be nice to raise errors.CannotParseUuidError or send null if field is nullable

Versions

  • Version of package with the problem: 0.2.6
  • ClickHouse server version: 23.3.7.5
  • Python version: 3.11.4
@V4kodin
Copy link

V4kodin commented Jul 16, 2024

Same.
@gistart did you solve it?
I can't insert "NULL", I can't insert None. So how should I insert null type into db?

@xzkostyan
Copy link
Member

Please add full steps to reproduce the issue.

@tonal
Copy link

tonal commented Sep 6, 2024

client = Client(..., settings={'use_numpy': True})
print(client.execute('SELECT version()'))
client.execute('CREATE TABLE IF NOT EXISTS tbl (id int, uuid_field UUID NULL) ENGINE = MergeTree PRIMARY KEY id')
df = pd.DataFrame({'id': [1], 'uuid_field': np.nan})
client.insert_dataframe('insert into tbl (id, uuid_field) values ', df)

Out traceback:

Traceback (most recent call last):
  File "/home/tonal/lang/projects/promsoft/mygig/heatmap_etl/hm_make_view.py", line 80, in ya_write_test
    client.insert_dataframe('insert into tbl (id, uuid_field) values ', df)
  File "/home/tonal/.pyenv/versions/mygig-heatmap_etl/lib/python3.12/site-packages/clickhouse_driver/client.py", line 546, in insert_dataframe
    rv = self.send_data(sample_block, data, columnar=True)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tonal/.pyenv/versions/mygig-heatmap_etl/lib/python3.12/site-packages/clickhouse_driver/client.py", line 660, in send_data
    self.connection.send_data(block)
  File "/home/tonal/.pyenv/versions/mygig-heatmap_etl/lib/python3.12/site-packages/clickhouse_driver/connection.py", line 688, in send_data
    self.block_out.write(block)
  File "/home/tonal/.pyenv/versions/mygig-heatmap_etl/lib/python3.12/site-packages/clickhouse_driver/streams/native.py", line 48, in write
    write_column(self.context, col_name, col_type, items,
  File "/home/tonal/.pyenv/versions/mygig-heatmap_etl/lib/python3.12/site-packages/clickhouse_driver/columns/service.py", line 167, in write_column
    column.write_data(items, buf)
  File "/home/tonal/.pyenv/versions/mygig-heatmap_etl/lib/python3.12/site-packages/clickhouse_driver/columns/base.py", line 145, in write_data
    self._write_data(items, buf)
  File "/home/tonal/.pyenv/versions/mygig-heatmap_etl/lib/python3.12/site-packages/clickhouse_driver/columns/base.py", line 148, in _write_data
    prepared = self.prepare_items(items)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tonal/.pyenv/versions/mygig-heatmap_etl/lib/python3.12/site-packages/clickhouse_driver/columns/base.py", line 137, in prepare_items
    self.before_write_items(items, nulls_map=nulls_map)
  File "/home/tonal/.pyenv/versions/mygig-heatmap_etl/lib/python3.12/site-packages/clickhouse_driver/columns/uuidcolumn.py", line 57, in before_write_items
    item = UUID(int=item) if item is null_value else UUID(item)
                                                     ^^^^^^^^^^
  File "/home/tonal/.pyenv/versions/3.12.5/lib/python3.12/uuid.py", line 175, in __init__
    hex = hex.replace('urn:', '').replace('uuid:', '')
          ^^^^^^^^^^^
AttributeError: 'numpy.float64' object has no attribute 'replace'

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

No branches or pull requests

4 participants