-
Notifications
You must be signed in to change notification settings - Fork 34
Fix Register converter for DataType.BIT #828
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
Changes from all commits
3442051
80c62fa
a5442a5
b289e81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26,13 +26,16 @@ | |||||
|
|
||||||
| import datetime as dt | ||||||
| import ipaddress | ||||||
| import re | ||||||
| from copy import deepcopy | ||||||
| from enum import Enum | ||||||
| from typing import Any, Callable, Dict, List, Optional, Union | ||||||
|
|
||||||
| ConverterFunction = Callable[[Optional[Any]], Optional[Any]] | ||||||
| ColTypesDefinition = Union[int, List[Union[int, "ColTypesDefinition"]]] | ||||||
|
|
||||||
| _BIT_LITERAL = re.compile(r"B'([01]*)'") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think empty bitstrings are not possible? But please double check
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey, I checked, they work: and unrelated to this ticket:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both will be fixed in 6.4.5 with crate/crate#20155 and crate/crate#20156 |
||||||
|
|
||||||
|
|
||||||
| def _to_ipaddress( | ||||||
| value: Optional[str], | ||||||
|
|
@@ -72,6 +75,20 @@ def _to_time(value: Optional[list]) -> Optional[dt.time]: | |||||
| return t.replace(tzinfo=tz) | ||||||
|
|
||||||
|
|
||||||
| def _to_bit_string(value: Optional[str]) -> Optional[str]: | ||||||
| """ | ||||||
| Convert a CrateDB BIT wire value to a plain string of ``0``/``1`` digits. | ||||||
|
|
||||||
| https://cratedb.com/docs/crate/reference/en/latest/general/ddl/data-types.html#bit-strings | ||||||
| """ | ||||||
| if value is None: | ||||||
| return None | ||||||
| match = _BIT_LITERAL.fullmatch(value) | ||||||
| if match is None: | ||||||
| return value | ||||||
| return match.group(1) | ||||||
|
|
||||||
|
|
||||||
| def _to_default(value: Optional[Any]) -> Optional[Any]: | ||||||
| return value | ||||||
|
|
||||||
|
|
@@ -117,6 +134,7 @@ class DataType(Enum): | |||||
| DataType.TIMESTAMP_WITH_TZ: _to_datetime, | ||||||
| DataType.TIMESTAMP_WITHOUT_TZ: _to_datetime, | ||||||
| DataType.TIME: _to_time, | ||||||
| DataType.BIT: _to_bit_string, | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks rather odd as documentation - especially the
cursor.execute('')will likely be rather confusing. Can we hide theset_next_responseand have acursor.execute("select b'0110'")instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, you are right. I changed it to
cursor.execute("select b'0110'"). I didn't understand what you meant "hide theset_next_response"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hide:directives like we use in the CrateDB docs. E.g.:https://github.com/crate/crate/blob/8900fd40976c994d14a2097daff59ea32af3bff8/docs/general/information-schema.rst?plain=1#L50-L50
This way it won't show up in the rendered documentation.