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 high precision floats into lower precision decimal column fails #289

Closed
joelynch opened this issue Feb 9, 2022 · 1 comment · Fixed by #295
Closed

INSERT high precision floats into lower precision decimal column fails #289

joelynch opened this issue Feb 9, 2022 · 1 comment · Fixed by #295

Comments

@joelynch
Copy link
Contributor

joelynch commented Feb 9, 2022

Since 0.2.3 get an error with the following code

>>> client.execute('''CREATE TABLE IF NOT EXISTS dec_test (id Integer, val Decimal(9, 4)) ENGINE = MergeTree order by id;''')
>>> client.execute('INSERT INTO dec_test VALUES', [(1, 3.14159265358979323846264338327)], types_check=True)
Traceback (most recent call last):
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/columns/service.py", line 130, in write_column
    column.write_data(items, buf)
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/columns/base.py", line 77, in write_data
    self._write_data(items, buf)
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/columns/decimalcolumn.py", line 74, in _write_data
    super(DecimalColumn, self)._write_data(items, buf)
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/columns/base.py", line 80, in _write_data
    prepared = self.prepare_items(items)
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/columns/base.py", line 64, in prepare_items
    check_item(x)
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/columns/decimalcolumn.py", line 27, in check_item
    raise ColumnTypeMismatchException(value)
clickhouse_driver.columns.exceptions.ColumnTypeMismatchException: 3.141592653589793

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/client.py", line 293, in execute
    columnar=columnar
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/client.py", line 510, in process_insert_query
    types_check=types_check, columnar=columnar)
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/client.py", line 562, in send_data
    self.connection.send_data(block)
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/connection.py", line 576, in send_data
    self.block_out.write(block)
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/streams/native.py", line 39, in write
    self.fout, types_check=block.types_check)
  File "/Users/joe.lynch/Library/Caches/pypoetry/virtualenvs/tern-kEo3BQPi-py3.7/lib/python3.7/site-packages/clickhouse_driver/columns/service.py", line 136, in write_column
    column_spec, type(e.args[0]), e.args[0], column_name
clickhouse_driver.errors.TypeMismatchError: Code: 53. Type mismatch in VALUES section. Expected Decimal(9, 4) got <class 'float'>: 3.141592653589793 for column "val".

Is this behaviour too strict? The previous behaviour where float precision was just truncated seemed fine to me.

@xzkostyan
Copy link
Member

Yes, this is too strict.

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.

2 participants