-
Notifications
You must be signed in to change notification settings - Fork 440
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
feat(python): add capability to read unity catalog (uc://) uris #3113
Open
omkar-foss
wants to merge
1
commit into
delta-io:main
Choose a base branch
from
omkar-foss:feat-uc-python
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+130
−13
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -78,6 +78,7 @@ use crate::merge::PyMergeBuilder; | |||||||||
use crate::query::PyQueryBuilder; | ||||||||||
use crate::schema::{schema_to_pyobject, Field}; | ||||||||||
use crate::utils::rt; | ||||||||||
use deltalake_catalog_unity::{CatalogFactory, UnityCatalogBuilder, UnityCatalogFactory}; | ||||||||||
|
||||||||||
#[cfg(all(target_family = "unix", not(target_os = "emscripten")))] | ||||||||||
use jemallocator::Jemalloc; | ||||||||||
|
@@ -170,6 +171,29 @@ impl RawDeltaTable { | |||||||||
original.state = state; | ||||||||||
Ok(()) | ||||||||||
} | ||||||||||
|
||||||||||
fn get_builder( | ||||||||||
table_uri: &str, | ||||||||||
storage_options: Option<HashMap<String, String>>, | ||||||||||
) -> (DeltaTableBuilder, String, HashMap<String, String>) { | ||||||||||
let (table_path, temp_creds) = if UnityCatalogBuilder::is_unity_catalog_uri(table_uri) { | ||||||||||
rt().block_on(UnityCatalogFactory::with_table_uri(table_uri)) | ||||||||||
.unwrap() | ||||||||||
} else { | ||||||||||
(table_uri.to_string(), HashMap::new()) | ||||||||||
}; | ||||||||||
let mut options = storage_options.clone().unwrap_or_default(); | ||||||||||
if !temp_creds.is_empty() { | ||||||||||
options.extend(temp_creds); | ||||||||||
} | ||||||||||
let mut builder = deltalake::DeltaTableBuilder::from_uri(&table_path) | ||||||||||
.with_io_runtime(IORuntime::default()); | ||||||||||
if !options.is_empty() { | ||||||||||
builder = builder.with_storage_options(options.clone()); | ||||||||||
} | ||||||||||
|
||||||||||
(builder, table_path, options) | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
#[pymethods] | ||||||||||
|
@@ -185,12 +209,8 @@ impl RawDeltaTable { | |||||||||
log_buffer_size: Option<usize>, | ||||||||||
) -> PyResult<Self> { | ||||||||||
py.allow_threads(|| { | ||||||||||
let mut builder = deltalake::DeltaTableBuilder::from_uri(table_uri) | ||||||||||
.with_io_runtime(IORuntime::default()); | ||||||||||
let options = storage_options.clone().unwrap_or_default(); | ||||||||||
if let Some(storage_options) = storage_options { | ||||||||||
builder = builder.with_storage_options(storage_options) | ||||||||||
} | ||||||||||
let (mut builder, table_path, options) = | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking more in the lines of this, then you don't have to modify any of the python/lib code delta-rs/crates/azure/src/lib.rs Lines 83 to 86 in 9dc8f32
|
||||||||||
RawDeltaTable::get_builder(table_uri, storage_options); | ||||||||||
if let Some(version) = version { | ||||||||||
builder = builder.with_version(version) | ||||||||||
} | ||||||||||
|
@@ -207,7 +227,7 @@ impl RawDeltaTable { | |||||||||
Ok(RawDeltaTable { | ||||||||||
_table: Arc::new(Mutex::new(table)), | ||||||||||
_config: FsConfig { | ||||||||||
root_url: table_uri.into(), | ||||||||||
root_url: table_path, | ||||||||||
options, | ||||||||||
}, | ||||||||||
}) | ||||||||||
|
@@ -220,10 +240,7 @@ impl RawDeltaTable { | |||||||||
table_uri: &str, | ||||||||||
storage_options: Option<HashMap<String, String>>, | ||||||||||
) -> PyResult<bool> { | ||||||||||
let mut builder = deltalake::DeltaTableBuilder::from_uri(table_uri); | ||||||||||
if let Some(storage_options) = storage_options { | ||||||||||
builder = builder.with_storage_options(storage_options) | ||||||||||
} | ||||||||||
let (builder, _, _) = RawDeltaTable::get_builder(table_uri, storage_options); | ||||||||||
Ok(rt() | ||||||||||
.block_on(async { | ||||||||||
match builder.build() { | ||||||||||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows users to work with a local (non-https) Unity Catalog REST API with
delta-rs
.