Skip to content

Commit

Permalink
fix create_table
Browse files Browse the repository at this point in the history
  • Loading branch information
flaneur2020 committed Dec 20, 2024
1 parent dab8e51 commit 6e1e958
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
39 changes: 29 additions & 10 deletions crates/catalog/s3tables/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,49 @@ impl Catalog for S3TablesCatalog {
) -> Result<Table> {
let table_ident = TableIdent::new(namespace.clone(), creation.name.clone());

// create table
let create_resp: CreateTableOutput = self
.s3tables_client
.create_table()
.table_bucket_arn(self.config.table_bucket_arn.clone())
.namespace(namespace.to_url_string())
.name(table_ident.name())
.send()
.await
.map_err(from_aws_sdk_error)?;

// get warehouse location
let get_resp: GetTableOutput = self
.s3tables_client
.get_table()
.table_bucket_arn(self.config.table_bucket_arn.clone())
.namespace(namespace.to_url_string())
.name(table_ident.name())
.send()
.await
.map_err(from_aws_sdk_error)?;

// write metadata to file
let metadata = TableMetadataBuilder::from_table_creation(creation)?
.build()?
.metadata;
let metadata_location =
create_metadata_location(namespace.to_url_string(), table_ident.name(), 0)?;
let metadata_location = create_metadata_location(
get_resp.warehouse_location(),
get_resp.version_token().parse::<i32>().unwrap(),
)?;
self.file_io
.new_output(&metadata_location)?
.write(serde_json::to_vec(&metadata)?.into())
.await?;

self.s3tables_client
.create_table()
.table_bucket_arn(self.config.table_bucket_arn.clone())
.namespace(namespace.to_url_string())
.name(table_ident.name())
.send()
.await
.map_err(from_aws_sdk_error)?;
// update metadata location
self.s3tables_client
.update_table_metadata_location()
.table_bucket_arn(self.config.table_bucket_arn.clone())
.namespace(namespace.to_url_string())
.name(table_ident.name())
.metadata_location(metadata_location.clone())
.version_token(create_resp.version_token())
.send()
.await
.map_err(from_aws_sdk_error)?;
Expand Down
8 changes: 3 additions & 5 deletions crates/catalog/s3tables/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ pub(crate) async fn create_sdk_config(

/// Create metadata location from `location` and `version`
pub(crate) fn create_metadata_location(
namespace: impl AsRef<str>,
table_name: impl AsRef<str>,
warehouse_location: impl AsRef<str>,
version: i32,
) -> Result<String> {
if version < 0 {
Expand All @@ -74,9 +73,8 @@ pub(crate) fn create_metadata_location(
let version = format!("{:0>5}", version);
let id = Uuid::new_v4();
let metadata_location = format!(
"{}/{}/metadata/{}-{}.metadata.json",
namespace.as_ref(),
table_name.as_ref(),
"{}/metadata/{}-{}.metadata.json",
warehouse_location.as_ref(),
version,
id
);
Expand Down

0 comments on commit 6e1e958

Please sign in to comment.