-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Fix null value on bytestring columns #65
Conversation
29 similar comments
6 similar comments
Hi @xzkostyan, thanks for your feedback! I've updated the PR with a couple of unit tests. |
This test fails with
Null characters are rstripped in FixedString columns, whereas they are not in ByteFixedString columns. I've tried to strip them in ByteFixedStrings too: diff --git i/clickhouse_driver/columns/stringcolumn.py w/clickhouse_driver/columns/stringcolumn.py
index ff13ffc..5e037d4 100644
--- i/clickhouse_driver/columns/stringcolumn.py
+++ w/clickhouse_driver/columns/stringcolumn.py
@@ -104,7 +104,8 @@ class ByteFixedString(FixedString):
buf_pos = 0
for i in compat.range(n_items):
- items[i] = items_buf_view[buf_pos:buf_pos + length].tobytes()
+ items[i] = items_buf_view[buf_pos:buf_pos + length].tobytes() \
+ .rstrip(b'\x00')
buf_pos += length
return items but then another test is broken:
|
Hi, @vivienm. Good job! Zero bytes are not stripped during inserted = self.client.execute(query)
self.assertEqual(inserted, [
(None, ),
(b'test\x00\x00\x00\x00\x00\x00', ),
(None, ),
(b'nullable\x00\x00',)
]) See example in test_not_decoded test. |
Hi @xzkostyan, thanks for your help! I've patched the test as indicated, it seems to work now. |
When client setting
strings_as_bytes
is set, the driver crashes when insertingNone
values into columns with typeNullable([Fixed]String)
:This is likely because the method
ByteString.prepare_null
is simplyString.prepare_null
, and returns the empty string''
instead the empty bytesb''
.I've been able to fix it with this PR, but I'm not familiar at all with this project so maybe it's not the right way to do it. Let me know if I can help :)