Skip to content

feat: shard support prefix#23

Open
ramwin wants to merge 1 commit intodgilland:masterfrom
ramwin:shard_support_prefix
Open

feat: shard support prefix#23
ramwin wants to merge 1 commit intodgilland:masterfrom
ramwin:shard_support_prefix

Conversation

@ramwin
Copy link
Copy Markdown

@ramwin ramwin commented Oct 6, 2024

No description provided.

@ramwin
Copy link
Copy Markdown
Author

ramwin commented Oct 11, 2024

@dgilland could you review this pull request on your spare time?

def shard(digest, depth, width):
# This creates a list of `depth` number of tokens with width
# `width` from the first part of the id plus the remainder.
def shard(digest, depth, width, prefix="") -> List[str]:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This method is an internal utility that's not meant for direct usage outside the library. It's meant to be passed a hash's HEX digest which then generates a file path. So a prefix argument doesn't make sense within that context.

I don't see the new prefix argument being used anywhere within the library so curious what the desire is here? Are you using shard() directly or have some other usage in mind?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, I want to use shard only in my python code.
Here was the scenario. I have a export task run in backend. It will generate a file name export_0x<uuid>.csv.
In order to prevent create huge amounts of file in one single directory. I use shard to create the file path.

import uuid
from hashfs.utils import shard
target_destination = Path(shard(
    f"export_0x{uuid.uuid4().hex}.csv",
    prefix="export_0x",
    depth=2, width=2))

Now the directory already contains thousands of file, I want to distribute them into sub directorys.

for f in list(Path("").iterdir()):
    f.rename(shard(f.name, prefix="export_0x"))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

In that case, I'd suggest copy/pasting the function into your own code instead of relying on this library for it.

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