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

[Python] Add command-line program to work with the CrateDB BLOB store #86

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

Conversation

amotl
Copy link
Member

@amotl amotl commented Sep 20, 2023

About

The guideline at the Python client documentation about working with the CrateDB BLOB store is sweet, but a runnable program is even better.

Synopsis

# Define the HTTP URL to your CrateDB instance.
export CRATEDB_HTTP_URL=https://username:[email protected]:4200/

# Define the BLOB container name.
export CRATEDB_BLOB_CONTAINER=testdrive

# Upload an item to the BLOB store.
python blob.py upload /path/to/file
418a0143404fb2da8a1464ab721f6d5fb50c3b96

# Download an item from the BLOB store.
python blob.py download 418a0143404fb2da8a1464ab721f6d5fb50c3b96

Backlog

  • Hasn't been verified with CrateDB Cloud yet.
  • Wasn't used with larger amounts of data yet.
  • In order to be used within own programs and libraries of CrateDB users,
    we may want to think about shipping it in one way or another,
    because it is a good building block.

/cc @andnig, @hlcianfagna, @hammerhead, @karynzv, @marijaselakovic, @proddata

@amotl amotl requested review from seut and matriv September 20, 2023 00:28
Comment on lines +179 to +184
actions = parser.add_subparsers(
dest="action",
title="action",
description="valid subcommands",
help="additional help",
)
Copy link
Member Author

Choose a reason for hiding this comment

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

Nit: Define title, description, and help better.

Copy link
Member

Choose a reason for hiding this comment

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

do it? ;)

Comment on lines +133 to +135
"""
What the function name says.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Meaningless function doc?

Suggested change
"""
What the function name says.
"""


def truncate(value: bytes) -> bytes:
"""
Truncate long string.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Truncate long string.
Truncate long string to be used for logging purpose.


# Define arbitrary content for testing purposes.
content = "An example payload.".encode("utf-8")
# content = b"\xde\xad\xbe\xef" * 256
Copy link
Member

Choose a reason for hiding this comment

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

remove?

Comment on lines +179 to +184
actions = parser.add_subparsers(
dest="action",
title="action",
description="valid subcommands",
help="additional help",
)
Copy link
Member

Choose a reason for hiding this comment

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

do it? ;)

Comment on lines +112 to +116
def refresh(self):
"""
Optionally synchronize data after write operations.
"""
self.run_sql(f'REFRESH TABLE "{self.name}";')
Copy link
Member

Choose a reason for hiding this comment

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

looks unused, remove it?
Otherwise I think it would have to use the blob schema, such as REFRESH TABLE blob."{self.name}";

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I also recognized this detail yesterday. Thank you. So, effectively, there is no way to run a BLOB table in a different schema? It is always blob?

Copy link
Member

Choose a reason for hiding this comment

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

Yes it's always blob, see also https://cratedb.com/docs/crate/reference/en/5.4/sql/statements/create-blob-table.html (syntax does not support to define a schema name).

@amotl
Copy link
Member Author

amotl commented Oct 2, 2023

FYI: I've just reused that basic implementation over at crate/mlflow-cratedb#33, adding more features to implement an object store.

@amotl amotl changed the title Python: Add command-line program to work with the CrateDB BLOB store [Python] Add command-line program to work with the CrateDB BLOB store Oct 29, 2023
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