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

Types: Add support for BINARY columns and improve support for FLOATs #12

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amotl
Copy link
Member

@amotl amotl commented Dec 23, 2023

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.

Backlog

  • Documentation
  • Software tests

@amotl amotl changed the title Types: Add support for BINARY columns and improve support for FLOATs [TYPES] Add support for BINARY columns and improve support for FLOATs Dec 23, 2023
Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that CrateDB also supports BitString type, but I don't think that's what we want here, right?

@amotl
Copy link
Member Author

amotl commented Dec 24, 2023

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 BIT type will be nice to have for the sake of completeness. So far, I didn't need it, but I am sure others will.

Comment on lines +17 to +30
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
Copy link
Member Author

@amotl amotl Dec 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self, or others who want to pick this up:

Review that detail about returning a DBAPIBinary, or not.

Comment on lines +32 to +44
# 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
Copy link
Member Author

@amotl amotl Dec 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@amotl amotl changed the base branch from amo/postgresql-async to amo/fix-inspector January 15, 2024 21:34
@amotl amotl force-pushed the amo/more-types branch 2 times, most recently from 9941c5d to 2a34862 Compare January 15, 2024 21:36
@amotl amotl force-pushed the amo/fix-inspector branch from 2f08b2a to 43c45fb Compare January 15, 2024 21:50
@amotl amotl changed the title [TYPES] Add support for BINARY columns and improve support for FLOATs Types: Add support for BINARY columns and improve support for FLOATs Jan 15, 2024
@amotl amotl force-pushed the amo/fix-inspector branch 5 times, most recently from 6ac0a22 to d2c7613 Compare June 13, 2024 14:33
Base automatically changed from amo/fix-inspector to main June 13, 2024 14:38
@amotl amotl force-pushed the amo/more-types branch 2 times, most recently from bde4bcb to 8f01308 Compare June 24, 2024 14:34
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 this pull request may close these issues.

2 participants