Types: Add support for BINARY columns#12
Conversation
There was a problem hiding this comment.
Keep in mind that CrateDB also supports BitString type, but I don't think that's what we want here, right?
Right. Here, it is about providing an emulation for a BLOB-type column. However, expanding type support to include the |
| def bind_processor(self, dialect): | ||
| if dialect.dbapi is None: | ||
| return None | ||
|
|
||
| # TODO: DBAPIBinary = dialect.dbapi.Binary | ||
|
|
||
| def process(value): | ||
| if value is not None: | ||
| # TODO: return DBAPIBinary(value) | ||
| return base64.b64encode(value).decode() | ||
| else: | ||
| return None | ||
|
|
||
| return process |
There was a problem hiding this comment.
Note to self, or others who want to pick this up:
Review that detail about returning a DBAPIBinary, or not.
There was a problem hiding this comment.
No. I just staged the patch directly from its origin, where the code is in use and works well. However, it can still be wrong from a generic perspective.
Let's toggle this patch back into draft mode: Better safe than sorry, thanks! The other commit 465b55b has been removed here and diverged to a separate patch.
| # Python 3 has native bytes() type | ||
| # both sqlite3 and pg8000 seem to return it, | ||
| # psycopg2 as of 2.5 returns 'memoryview' | ||
| def result_processor(self, dialect, coltype): | ||
| if dialect.returns_native_bytes: | ||
| return None | ||
|
|
||
| def process(value): | ||
| if value is not None: | ||
| return base64.b64decode(value) | ||
| return value | ||
|
|
||
| return process |
There was a problem hiding this comment.
Note to self, or others who want to pick this up:
Review that detail about dialect.returns_native_bytes: Should it be handled differently, because, well, base64.b64decode actually returns native bytes already?
9941c5d to
2a34862
Compare
2f08b2a to
43c45fb
Compare
6ac0a22 to
d2c7613
Compare
8f01308 to
73bfe8e
Compare
2707929 to
de288ab
Compare
09c55fc to
9d1fc10
Compare
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| if dialect.dbapi is None: | ||
| return None | ||
|
|
||
| # TODO: DBAPIBinary = dialect.dbapi.Binary |
There was a problem hiding this comment.
... or activated, to be more standards-compliant. Let's investigate within another iteration before getting things wrong. Thanks!
| class LargeBinary(sa.String): | ||
| """A type for large binary byte data. | ||
|
|
||
| The :class:`.LargeBinary` type corresponds to a large and/or unlengthed |
There was a problem hiding this comment.
I suggest that we also mention CrateDB' BLOB type here
There was a problem hiding this comment.
CrateDB does not provide a BLOB type, does it?
| def bind_processor(self, dialect): | ||
| if dialect.dbapi is None: | ||
| return None | ||
|
|
||
| # TODO: DBAPIBinary = dialect.dbapi.Binary | ||
|
|
||
| def process(value): | ||
| if value is not None: | ||
| # TODO: return DBAPIBinary(value) | ||
| return base64.b64encode(value).decode() | ||
| else: | ||
| return None | ||
|
|
||
| return process |
| # Python 3 has native bytes() type | ||
| # both sqlite3 and pg8000 seem to return it, | ||
| # psycopg2 as of 2.5 returns 'memoryview' | ||
| def result_processor(self, dialect, coltype): | ||
| if dialect.returns_native_bytes: | ||
| return None | ||
|
|
||
| def process(value): | ||
| if value is not None: | ||
| return base64.b64decode(value) | ||
| return value | ||
|
|
||
| return process |
About
Improvements to be mainlined from https://github.com/pyveci/supertask/blob/19316e2/supertask/store/cratedb.py. The support for binary data types is being emulated by serializing them to STRING using base64. In that way, pickled data can be stored and retrieved without further ado.