Add object_store parameter to register/read file methods for thread-safe credentials#1625
Open
qzyu999 wants to merge 1 commit into
Open
Add object_store parameter to register/read file methods for thread-safe credentials#1625qzyu999 wants to merge 1 commit into
qzyu999 wants to merge 1 commit into
Conversation
Add an optional object_store parameter to register_parquet, read_parquet, register_csv, read_csv, register_json, read_json, register_avro, read_avro, register_arrow, and read_arrow methods. When provided, the store is automatically registered for the URL scheme and host parsed from the path, removing the need to manually call register_object_store separately. This enables thread-safe cloud credential handling without os.environ mutation. Includes unit tests (mock-based) for URL parsing logic and integration tests using LocalFileSystem for end-to-end validation. Closes apache#1624
Author
|
Hi @timsaucer, this PR would help improve the efficiency of some operations related apache/iceberg-python#3554, PTAL and LMK if you have any questions, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #1624.
Rationale for this change
When using datafusion-python as a compute backend from multi-threaded Python applications (e.g., PyIceberg), cloud credentials must currently be set via
os.environbefore callingregister_parquet(). Sinceos.environis process-global, concurrent threads mutating it causes credential cross-contamination, requiring a global lock that serializes all I/O operations and negates any parallelism benefit.The existing
register_object_store()method already solves thread-safety, but requires callers to manually parse bucket names from paths, determine the correct URL scheme, and make a separate call beforeregister_parquet. This PR adds a convenienceobject_storeparameter that handles all of this internally.What changes are included in this PR?
New private helper
_register_object_store_for_path(path, store)parses a URL path viaurllib.parse.urlparseto extract scheme and host, then callsregister_object_store()internally.New
object_storeparameter added to all file-based register/read methods:register_parquet/read_parquetregister_csv/read_csvregister_json/read_jsonregister_avro/read_avroregister_arrow/read_arrowTest suite (
python/tests/test_object_store_param.py) with 23 tests:register_object_storeLocalFileSystemwith real Parquet filesAll changes are purely in the Python layer no Rust code modified.
Are there any user-facing changes?
Yes. All file-based
register_*andread_*methods onSessionContextnow accept an optionalobject_storekeyword argument. When provided with a pre-configured store instance (e.g.,AmazonS3,GoogleCloud,MicrosoftAzure), the store is automatically registered for the URL parsed from the path.Example usage:
This is a backward-compatible addition (the parameter defaults to
Noneand existing call sites are unaffected).