-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] Azure and Iceberg read and write fixes (#2349)
In this PR: - `pyarrow.dataset.write_dataset` does not properly write Parquet metadata in version 12.0.0, set the requirements for it to be >=12.0.1 - Azure fsspec filesystem now initialized IOConfig values - Azure URIs that look like `PROTOCOL://account.dfs.core.windows.net/container/path-part/file` now properly parsed, URI parsing also cleaned up and unified - fixed small discrepancies for AzureConfig in `daft.pyi` - Added a public test Iceberg table on Azure, a SQLite catalog that points to the table, and a test for those tables. - More tests should be written - #2348 Should resolve #2005
- Loading branch information
1 parent
87f6706
commit f13554f
Showing
10 changed files
with
123 additions
and
57 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pytest==7.4.0 | ||
pytest-benchmark==4.0.0 | ||
pytest-memray==1.4.1 | ||
pyarrow==12.0.0 | ||
pyarrow==12.0.1 | ||
boto3==1.28.3 |
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
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ use common_io_config::AzureConfig; | |
const AZURE_DELIMITER: &str = "/"; | ||
const DEFAULT_GLOB_FANOUT_LIMIT: usize = 1024; | ||
const AZURE_STORAGE_RESOURCE: &str = "https://storage.azure.com"; | ||
const AZURE_STORE_SUFFIX: &str = ".dfs.core.windows.net"; | ||
|
||
#[derive(Debug, Snafu)] | ||
enum Error { | ||
|
@@ -64,6 +65,44 @@ enum Error { | |
NotAFile { path: String }, | ||
} | ||
|
||
/// Parse an Azure URI into its components. | ||
/// Returns (protocol, container if exists, key). | ||
fn parse_azure_uri(uri: &str) -> super::Result<(String, Option<(String, String)>)> { | ||
let uri = url::Url::parse(uri).with_context(|_| InvalidUrlSnafu { path: uri })?; | ||
|
||
// "Container" is Azure's name for Bucket. | ||
// | ||
// fsspec supports two URI formats; for compatibility, we will support both as well. | ||
// PROTOCOL://container/path-part/file | ||
// PROTOCOL://[email protected]/path-part/file | ||
// See https://github.com/fsspec/adlfs/ for more details | ||
// | ||
// It also supports PROTOCOL://account.dfs.core.windows.net/container/path-part/file | ||
// but it is not documented | ||
// https://github.com/fsspec/adlfs/blob/5c24b2e886fc8e068a313819ce3db9b7077c27e3/adlfs/spec.py#L364 | ||
let username = uri.username(); | ||
let container_and_key = if username.is_empty() { | ||
match uri.host_str() { | ||
Some(host) if host.ends_with(AZURE_STORE_SUFFIX) => uri | ||
.path() | ||
.split_once('/') | ||
.map(|(c, k)| (c.into(), k.into())), | ||
Some(host) => Some((host.into(), uri.path().into())), | ||
None => None, | ||
} | ||
} else { | ||
Some((username.into(), uri.path().into())) | ||
}; | ||
|
||
// fsspec supports multiple URI protocol strings for Azure: az:// and abfs://. | ||
// NB: It's unclear if there is a semantic difference between the protocols | ||
// or if there is a standard for the behaviour either; | ||
// here, we will treat them both the same, but persist whichever protocol string was used. | ||
let protocol = uri.scheme(); | ||
|
||
Ok((protocol.into(), container_and_key)) | ||
} | ||
|
||
impl From<Error> for super::Error { | ||
fn from(error: Error) -> Self { | ||
use Error::*; | ||
|
@@ -443,15 +482,11 @@ impl ObjectSource for AzureBlobSource { | |
range: Option<Range<usize>>, | ||
io_stats: Option<IOStatsRef>, | ||
) -> super::Result<GetResult> { | ||
let parsed = url::Url::parse(uri).with_context(|_| InvalidUrlSnafu { path: uri })?; | ||
let container = match parsed.host_str() { | ||
Some(s) => Ok(s), | ||
None => Err(Error::InvalidUrl { | ||
path: uri.into(), | ||
source: url::ParseError::EmptyHost, | ||
}), | ||
}?; | ||
let key = parsed.path(); | ||
let (_, container_and_key) = parse_azure_uri(uri)?; | ||
let (container, key) = container_and_key.ok_or_else(|| Error::InvalidUrl { | ||
path: uri.into(), | ||
source: url::ParseError::EmptyHost, | ||
})?; | ||
|
||
if key.is_empty() { | ||
return Err(Error::NotAFile { path: uri.into() }.into()); | ||
|
@@ -489,15 +524,11 @@ impl ObjectSource for AzureBlobSource { | |
} | ||
|
||
async fn get_size(&self, uri: &str, io_stats: Option<IOStatsRef>) -> super::Result<usize> { | ||
let parsed = url::Url::parse(uri).with_context(|_| InvalidUrlSnafu { path: uri })?; | ||
let container = match parsed.host_str() { | ||
Some(s) => Ok(s), | ||
None => Err(Error::InvalidUrl { | ||
path: uri.into(), | ||
source: url::ParseError::EmptyHost, | ||
}), | ||
}?; | ||
let key = parsed.path(); | ||
let (_, container_and_key) = parse_azure_uri(uri)?; | ||
let (container, key) = container_and_key.ok_or_else(|| Error::InvalidUrl { | ||
path: uri.into(), | ||
source: url::ParseError::EmptyHost, | ||
})?; | ||
|
||
if key.is_empty() { | ||
return Err(Error::NotAFile { path: uri.into() }.into()); | ||
|
@@ -547,39 +578,23 @@ impl ObjectSource for AzureBlobSource { | |
_page_size: Option<i32>, | ||
io_stats: Option<IOStatsRef>, | ||
) -> super::Result<BoxStream<super::Result<FileMetadata>>> { | ||
let uri = url::Url::parse(uri).with_context(|_| InvalidUrlSnafu { path: uri })?; | ||
|
||
// path can be root (buckets) or path prefix within a bucket. | ||
let container = { | ||
// "Container" is Azure's name for Bucket. | ||
// | ||
// fsspec supports two URI formats; for compatibility, we will support both as well. | ||
// PROTOCOL://container/path-part/file | ||
// PROTOCOL://[email protected]/path-part/file | ||
// See https://github.com/fsspec/adlfs/ for more details | ||
let username = uri.username(); | ||
match username { | ||
"" => uri.host_str(), | ||
_ => Some(username), | ||
} | ||
}; | ||
|
||
// fsspec supports multiple URI protocol strings for Azure: az:// and abfs://. | ||
// NB: It's unclear if there is a semantic difference between the protocols | ||
// or if there is a standard for the behaviour either; | ||
// here, we will treat them both the same, but persist whichever protocol string was used. | ||
let protocol = uri.scheme(); | ||
let (protocol, container_and_key) = parse_azure_uri(uri)?; | ||
|
||
match container { | ||
match container_and_key { | ||
// List containers. | ||
None => Ok(self.list_containers_stream(protocol, io_stats).await), | ||
None => Ok(self | ||
.list_containers_stream(protocol.as_str(), io_stats) | ||
.await), | ||
// List a path within a container. | ||
Some(container_name) => { | ||
let prefix = uri.path(); | ||
Ok(self | ||
.list_directory_stream(protocol, container_name, prefix, posix, io_stats) | ||
.await) | ||
} | ||
Some((container_name, key)) => Ok(self | ||
.list_directory_stream( | ||
protocol.as_str(), | ||
container_name.as_str(), | ||
key.as_str(), | ||
posix, | ||
io_stats, | ||
) | ||
.await), | ||
} | ||
} | ||
|
||
|
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
|
||
pyiceberg = pytest.importorskip("pyiceberg") | ||
|
||
import daft | ||
from tests.conftest import assert_df_equals | ||
|
||
|
||
@pytest.mark.integration | ||
def test_daft_iceberg_cloud_table_load(cloud_iceberg_table): | ||
df = daft.read_iceberg(cloud_iceberg_table) | ||
daft_pandas = df.to_pandas() | ||
iceberg_pandas = cloud_iceberg_table.scan().to_arrow().to_pandas() | ||
assert_df_equals(daft_pandas, iceberg_pandas, sort_key=[]) |