Skip to content

Commit

Permalink
fix: OpenDAL is_exist => exists
Browse files Browse the repository at this point in the history
* change usage of deprecated OpenDAL `is_exist` method to its replacement, `exists`
* perform similar change to `FileIO::exists`

Fixes: #679
  • Loading branch information
sdd committed Oct 24, 2024
1 parent 6f392e3 commit d8468bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ log = "0.4"
mockito = "1"
murmur3 = "0.5.2"
once_cell = "1"
opendal = "0.50"
opendal = "0.50.1"
ordered-float = "4"
parquet = "53"
paste = "1"
Expand Down
30 changes: 12 additions & 18 deletions crates/iceberg/src/io/file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ impl FileIO {
/// # Arguments
///
/// * path: It should be *absolute* path starting with scheme string used to construct [`FileIO`].
pub async fn is_exist(&self, path: impl AsRef<str>) -> Result<bool> {
pub async fn exists(&self, path: impl AsRef<str>) -> Result<bool> {
let (op, relative_path) = self.inner.create_operator(&path)?;
Ok(op.is_exist(relative_path).await?)
Ok(op.exists(relative_path).await?)
}

/// Creates input file.
Expand Down Expand Up @@ -241,10 +241,7 @@ impl InputFile {

/// Check if file exists.
pub async fn exists(&self) -> crate::Result<bool> {
Ok(self
.op
.is_exist(&self.path[self.relative_path_pos..])
.await?)
Ok(self.op.exists(&self.path[self.relative_path_pos..]).await?)
}

/// Fetch and returns metadata of file.
Expand Down Expand Up @@ -323,10 +320,7 @@ impl OutputFile {

/// Checks if file exists.
pub async fn exists(&self) -> crate::Result<bool> {
Ok(self
.op
.is_exist(&self.path[self.relative_path_pos..])
.await?)
Ok(self.op.exists(&self.path[self.relative_path_pos..]).await?)
}

/// Converts into [`InputFile`].
Expand Down Expand Up @@ -426,15 +420,15 @@ mod tests {
write_to_file("Iceberg loves rust.", &c_path);

let file_io = create_local_file_io();
assert!(file_io.is_exist(&a_path).await.unwrap());
assert!(file_io.exists(&a_path).await.unwrap());

file_io.remove_all(&sub_dir_path).await.unwrap();
assert!(!file_io.is_exist(&b_path).await.unwrap());
assert!(!file_io.is_exist(&c_path).await.unwrap());
assert!(file_io.is_exist(&a_path).await.unwrap());
assert!(!file_io.exists(&b_path).await.unwrap());
assert!(!file_io.exists(&c_path).await.unwrap());
assert!(file_io.exists(&a_path).await.unwrap());

file_io.delete(&a_path).await.unwrap();
assert!(!file_io.is_exist(&a_path).await.unwrap());
assert!(!file_io.exists(&a_path).await.unwrap());
}

#[tokio::test]
Expand All @@ -445,7 +439,7 @@ mod tests {
let full_path = format!("{}/{}", tmp_dir.path().to_str().unwrap(), file_name);

let file_io = create_local_file_io();
assert!(!file_io.is_exist(&full_path).await.unwrap());
assert!(!file_io.exists(&full_path).await.unwrap());
assert!(file_io.delete(&full_path).await.is_ok());
assert!(file_io.remove_all(&full_path).await.is_ok());
}
Expand Down Expand Up @@ -501,12 +495,12 @@ mod tests {
let output_file = io.new_output(&path).unwrap();
output_file.write("test".into()).await.unwrap();

assert!(io.is_exist(&path.clone()).await.unwrap());
assert!(io.exists(&path.clone()).await.unwrap());
let input_file = io.new_input(&path).unwrap();
let content = input_file.read().await.unwrap();
assert_eq!(content, Bytes::from("test"));

io.delete(&path).await.unwrap();
assert!(!io.is_exist(&path).await.unwrap());
assert!(!io.exists(&path).await.unwrap());
}
}
9 changes: 3 additions & 6 deletions crates/iceberg/tests/file_io_gcs_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ mod tests {
#[tokio::test]
async fn gcs_exists() {
let file_io = get_file_io_gcs().await;
assert!(file_io
.is_exist(format!("{}/", get_gs_path()))
.await
.unwrap());
assert!(file_io.exists(format!("{}/", get_gs_path())).await.unwrap());
}

#[tokio::test]
Expand All @@ -108,7 +105,7 @@ mod tests {
.write(bytes::Bytes::from_static(b"iceberg-gcs!"))
.await
.expect("Write to test output file");
assert!(file_io.is_exist(gs_file).await.unwrap())
assert!(file_io.exists(gs_file).await.unwrap())
}

#[tokio::test]
Expand All @@ -120,7 +117,7 @@ mod tests {
.write(bytes::Bytes::from_static(b"iceberg!"))
.await
.expect("Write to test output file");
assert!(file_io.is_exist(&gs_file).await.unwrap());
assert!(file_io.exists(&gs_file).await.unwrap());

let input = file_io.new_input(gs_file).unwrap();
assert_eq!(input.read().await.unwrap(), Bytes::from_static(b"iceberg!"));
Expand Down
10 changes: 5 additions & 5 deletions crates/iceberg/tests/file_io_s3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ mod tests {
}

#[tokio::test]
async fn test_file_io_s3_is_exist() {
async fn test_file_io_s3_exists() {
let file_io = get_file_io().await;
assert!(!file_io.is_exist("s3://bucket2/any").await.unwrap());
assert!(file_io.is_exist("s3://bucket1/").await.unwrap());
assert!(!file_io.exists("s3://bucket2/any").await.unwrap());
assert!(file_io.exists("s3://bucket1/").await.unwrap());
}

#[tokio::test]
async fn test_file_io_s3_output() {
let file_io = get_file_io().await;
assert!(!file_io.is_exist("s3://bucket1/test_output").await.unwrap());
assert!(!file_io.exists("s3://bucket1/test_output").await.unwrap());
let output_file = file_io.new_output("s3://bucket1/test_output").unwrap();
{
output_file.write("123".into()).await.unwrap();
}
assert!(file_io.is_exist("s3://bucket1/test_output").await.unwrap());
assert!(file_io.exists("s3://bucket1/test_output").await.unwrap());
}

#[tokio::test]
Expand Down

0 comments on commit d8468bd

Please sign in to comment.