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

Using clickhouse-driver to query for data of type FixedString(16) returns a problem #104

Closed
zengzhiying opened this issue Sep 3, 2019 · 3 comments

Comments

@zengzhiying
Copy link

zengzhiying commented Sep 3, 2019

Clickhouse version: 19.8.3.8
Clickhouse driver version: 0.1.0
Create table sql is:
create table example (date Date, info_id FixedString(16), create_time UInt32) ENGINE= MergeTree PARTITION BY date ORDER BY create_time SETTINGS index_granularity=8192
Then try to insert the data:
insert into example(date, info_id, create_time) values('2019-09-03', UUIDStringToNum('5d424f77-0c00-5789-848e-555969d0e7f1'), 1567498636)
insert into example(date, info_id, create_time) values('2019-09-03', UUIDStringToNum('2d124177-0c66-5789-848e-555969d0e7f1'), 1567498636)
insert into example(date, info_id, create_time) values('2019-09-03', UUIDStringToNum('2d124177-0c00-5789-848e-555969d0e7f1'), 1567498636)
The focus is on the info_id of the FixedString(16) type.
Query data is normal: select UUIDNumToString(info_id) as id from example
┌─id───────────────────────────────────┐
│ 5d424f77-0c00-5789-848e-555969d0e7f1 │
│ 2d124177-0c66-5789-848e-555969d0e7f1 │
│ 2d124177-0c00-5789-848e-555969d0e7f1 │
└──────────────────────────────────────┘
Use the python code to query as follows:
from clickhouse_driver import Client
c = Client('127.0.0.1', port=9000)
rows = c.execute('select * from default.example')
Rows are shown in ipython as follows:
[(datetime.date(2019, 9, 3),
b'-\x12Aw\x0cfW\x89\x84\x8eUYi\xd0\xe7\xf1',
1567498636),
(datetime.date(2019, 9, 3), '-\x12Aw\x0c', 1567498636),
(datetime.date(2019, 9, 3), ']BOw\x0c', 1567498636)]
The returned part of the id seems to be truncated.
It seems that this problem occurs when the id contains 0c00.
There is no such problem with the driver of version 0.0.19.
How to solve this? Thank you

@xzkostyan
Copy link
Member

Hi. It seems to be valid bug during string decoding in 0.1.0. Thanks.

You can cast column to string as workaround:

In [2]: c.execute('select info_id from example')                                                                                                                                
Out[2]: 
[(']BOw\x0c',),
 (b'-\x12Aw\x0cfW\x89\x84\x8eUYi\xd0\xe7\xf1',),
 ('-\x12Aw\x0c',)]

In [3]: c.execute('select CAST(info_id AS String) from example')                                                                                                                
Out[3]: 
[(b']BOw\x0c\x00W\x89\x84\x8eUYi\xd0\xe7\xf1',),
 (b'-\x12Aw\x0cfW\x89\x84\x8eUYi\xd0\xe7\xf1',),
 (b'-\x12Aw\x0c\x00W\x89\x84\x8eUYi\xd0\xe7\xf1',)]

Or you can disable strings encoding/decoding:

In [4]: from clickhouse_driver import Client 
   ...: c = Client('127.0.0.1', settings={'strings_as_bytes': True}) 
   ...: c.execute('select info_id from example')                                                                                                                                
Out[4]: 
[(b']BOw\x0c\x00W\x89\x84\x8eUYi\xd0\xe7\xf1',),
 (b'-\x12Aw\x0cfW\x89\x84\x8eUYi\xd0\xe7\xf1',),
 (b'-\x12Aw\x0c\x00W\x89\x84\x8eUYi\xd0\xe7\xf1',)]

Or you can downgrade to 0.0.20.

@zengzhiying
Copy link
Author

I understand,thank you very much!

@xzkostyan
Copy link
Member

Fix of this issue in latest master. You can install package from github

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

2 participants