Skip to content

Commit c2f3e4c

Browse files
authored
Merge pull request JanKaul#184 from JanKaul/s3tables-error
make get_table_metadata_location_error transparent
2 parents 035d7a7 + db5901a commit c2f3e4c

File tree

7 files changed

+44
-14
lines changed

7 files changed

+44
-14
lines changed

catalogs/iceberg-glue-catalog/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub mod schema;
5555
mod utils;
5656

5757
impl GlueCatalog {
58+
#[allow(clippy::result_large_err)]
5859
pub fn new(
5960
config: &SdkConfig,
6061
name: &str,

catalogs/iceberg-s3tables-catalog/src/error.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use aws_sdk_s3tables::{
44
operation::{
55
create_namespace::CreateNamespaceError, create_table::CreateTableError,
66
delete_table::DeleteTableError, get_table::GetTableError,
7+
get_table_metadata_location::GetTableMetadataLocationError,
78
list_namespaces::ListNamespacesError, list_tables::ListTablesError,
89
update_table_metadata_location::UpdateTableMetadataLocationError,
910
},
@@ -26,7 +27,11 @@ pub enum Error {
2627
#[error(transparent)]
2728
GetTable(#[from] SdkError<GetTableError, HttpResponse>),
2829
#[error(transparent)]
29-
DeletaTable(#[from] SdkError<DeleteTableError, HttpResponse>),
30+
DeleteTable(#[from] SdkError<DeleteTableError, HttpResponse>),
31+
#[error(transparent)]
32+
SdkError(#[from] SdkError<GetTableMetadataLocationError, HttpResponse>),
33+
#[error(transparent)]
34+
GetTableMetadataLocation(#[from] GetTableMetadataLocationError),
3035
#[error(transparent)]
3136
CreateTable(#[from] SdkError<CreateTableError, HttpResponse>),
3237
#[error(transparent)]

catalogs/iceberg-s3tables-catalog/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::{
66
use async_trait::async_trait;
77
use aws_config::SdkConfig;
88

9-
use aws_sdk_s3tables::{types::OpenTableFormat, Client};
9+
use aws_sdk_s3tables::{
10+
error::SdkError, operation::get_table_metadata_location::GetTableMetadataLocationError,
11+
types::OpenTableFormat, Client,
12+
};
1013
use iceberg_rust::{
1114
catalog::{
1215
commit::{
@@ -50,6 +53,7 @@ pub struct S3TablesCatalog {
5053
pub mod error;
5154

5255
impl S3TablesCatalog {
56+
#[allow(clippy::result_large_err)]
5357
pub fn new(
5458
config: &SdkConfig,
5559
arn: &str,
@@ -236,7 +240,15 @@ impl Catalog for S3TablesCatalog {
236240
.name(identifier.name())
237241
.send()
238242
.await
239-
.map_err(|_| IcebergError::CatalogNotFound)?;
243+
.map_err(|err| match err {
244+
SdkError::ServiceError(err) => match err.into_err() {
245+
GetTableMetadataLocationError::NotFoundException(_) => {
246+
IcebergError::CatalogNotFound
247+
}
248+
x => Error::from(x).into(),
249+
},
250+
x => Error::from(x).into(),
251+
})?;
240252

241253
let metadata_location = table.metadata_location.ok_or(Error::Text(format!(
242254
"Table {} not found.",

iceberg-rust-spec/src/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub enum Error {
2727
NotSupported(String),
2828
/// Avro error
2929
#[error(transparent)]
30-
Avro(#[from] apache_avro::Error),
30+
Avro(Box<apache_avro::Error>),
3131
/// Serde json
3232
#[error(transparent)]
3333
JSONSerde(#[from] serde_json::Error),
@@ -80,3 +80,9 @@ pub enum Error {
8080
#[error(transparent)]
8181
PartitionSpec(#[from] crate::spec::partition::PartitionSpecBuilderError),
8282
}
83+
84+
impl From<apache_avro::Error> for Error {
85+
fn from(err: apache_avro::Error) -> Self {
86+
Error::Avro(Box::new(err))
87+
}
88+
}

iceberg-rust/src/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum Error {
4646
Parquet(#[from] parquet::errors::ParquetError),
4747
/// Avro error
4848
#[error(transparent)]
49-
Avro(#[from] apache_avro::Error),
49+
Avro(Box<apache_avro::Error>),
5050
/// Thrift error
5151
#[error(transparent)]
5252
Thrift(#[from] thrift::Error),
@@ -115,6 +115,12 @@ pub enum Error {
115115
),
116116
}
117117

118+
impl From<apache_avro::Error> for Error {
119+
fn from(err: apache_avro::Error) -> Self {
120+
Error::Avro(Box::new(err))
121+
}
122+
}
123+
118124
impl From<Error> for ArrowError {
119125
fn from(value: Error) -> Self {
120126
ArrowError::from_external_error(Box::new(value))

iceberg-rust/src/object_store/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ impl Bucket<'_> {
6464
#[derive(Debug, Clone)]
6565
pub enum ObjectStoreBuilder {
6666
/// AWS s3 builder
67-
S3(AmazonS3Builder),
67+
S3(Box<AmazonS3Builder>),
6868
/// Google Cloud Storage builder
69-
GCS(GoogleCloudStorageBuilder),
69+
GCS(Box<GoogleCloudStorageBuilder>),
7070
/// Filesystem builder
7171
Filesystem(Arc<LocalFileSystem>),
7272
/// In memory builder
@@ -99,11 +99,11 @@ impl FromStr for ConfigKey {
9999
impl ObjectStoreBuilder {
100100
/// Create new AWS S3 Object Store builder
101101
pub fn s3() -> Self {
102-
ObjectStoreBuilder::S3(AmazonS3Builder::from_env())
102+
ObjectStoreBuilder::S3(Box::new(AmazonS3Builder::from_env()))
103103
}
104104
/// Create new AWS S3 Object Store builder
105105
pub fn gcs() -> Self {
106-
ObjectStoreBuilder::GCS(GoogleCloudStorageBuilder::from_env())
106+
ObjectStoreBuilder::GCS(Box::new(GoogleCloudStorageBuilder::from_env()))
107107
}
108108
/// Create a new FileSystem ObjectStoreBuilder
109109
pub fn filesystem(prefix: impl AsRef<Path>) -> Self {
@@ -117,10 +117,10 @@ impl ObjectStoreBuilder {
117117
pub fn with_config(self, key: ConfigKey, value: impl Into<String>) -> Self {
118118
match (self, key) {
119119
(ObjectStoreBuilder::S3(aws), ConfigKey::AWS(key)) => {
120-
ObjectStoreBuilder::S3(aws.with_config(key, value))
120+
ObjectStoreBuilder::S3(Box::new(aws.with_config(key, value)))
121121
}
122122
(ObjectStoreBuilder::GCS(gcs), ConfigKey::GCS(key)) => {
123-
ObjectStoreBuilder::GCS(gcs.with_config(key, value))
123+
ObjectStoreBuilder::GCS(Box::new(gcs.with_config(key, value)))
124124
}
125125
(x, _) => x,
126126
}
@@ -129,15 +129,15 @@ impl ObjectStoreBuilder {
129129
pub fn build(&self, bucket: Bucket) -> Result<Arc<dyn ObjectStore>, Error> {
130130
match (bucket, self) {
131131
(Bucket::S3(bucket), Self::S3(builder)) => Ok::<_, Error>(Arc::new(
132-
builder
132+
(**builder)
133133
.clone()
134134
.with_bucket_name(bucket)
135135
.with_copy_if_not_exists(S3CopyIfNotExists::Multipart)
136136
.build()
137137
.map_err(Error::from)?,
138138
)),
139139
(Bucket::GCS(bucket), Self::GCS(builder)) => Ok::<_, Error>(Arc::new(
140-
builder
140+
(**builder)
141141
.clone()
142142
.with_bucket_name(bucket)
143143
.build()

iceberg-rust/src/sql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn find_relations(sql: &str) -> Result<Vec<String>, Error> {
1313
let statements = Parser::parse_sql(&GenericDialect, sql)?;
1414
let mut visited = Vec::new();
1515

16-
visit_relations(&statements, |relation| {
16+
let _ = visit_relations(&statements, |relation| {
1717
visited.push(relation.to_string());
1818
ControlFlow::<()>::Continue(())
1919
});

0 commit comments

Comments
 (0)