Skip to content

feat(catalog): Implement update_table for MemoryCatalog #1549

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

Merged
merged 23 commits into from
Jul 27, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/catalog/glue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ serde_json = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
typed-builder = { workspace = true }
uuid = { workspace = true }

[dev-dependencies]
ctor = { workspace = true }
Expand Down
10 changes: 5 additions & 5 deletions crates/catalog/glue/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ use iceberg::io::{
use iceberg::spec::{TableMetadata, TableMetadataBuilder};
use iceberg::table::Table;
use iceberg::{
Catalog, Error, ErrorKind, Namespace, NamespaceIdent, Result, TableCommit, TableCreation,
TableIdent,
Catalog, Error, ErrorKind, MetadataLocationParser, Namespace, NamespaceIdent, Result,
TableCommit, TableCreation, TableIdent,
};
use typed_builder::TypedBuilder;

use crate::error::{from_aws_build_error, from_aws_sdk_error};
use crate::utils::{
convert_to_database, convert_to_glue_table, convert_to_namespace, create_metadata_location,
create_sdk_config, get_default_table_location, get_metadata_location, validate_namespace,
convert_to_database, convert_to_glue_table, convert_to_namespace, create_sdk_config,
get_default_table_location, get_metadata_location, validate_namespace,
};
use crate::{
AWS_ACCESS_KEY_ID, AWS_REGION_NAME, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, with_catalog_id,
Expand Down Expand Up @@ -393,7 +393,7 @@ impl Catalog for GlueCatalog {
let metadata = TableMetadataBuilder::from_table_creation(creation)?
.build()?
.metadata;
let metadata_location = create_metadata_location(&location, 0)?;
let metadata_location = MetadataLocationParser::new_with_prefix(location).to_string();

metadata.write_to(&self.file_io, &metadata_location).await?;

Expand Down
54 changes: 9 additions & 45 deletions crates/catalog/glue/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use aws_sdk_glue::config::Credentials;
use aws_sdk_glue::types::{Database, DatabaseInput, StorageDescriptor, TableInput};
use iceberg::spec::TableMetadata;
use iceberg::{Error, ErrorKind, Namespace, NamespaceIdent, Result};
use uuid::Uuid;

use crate::error::from_aws_build_error;
use crate::schema::GlueSchemaBuilder;
Expand Down Expand Up @@ -228,30 +227,6 @@ pub(crate) fn get_default_table_location(
}
}

/// Create metadata location from `location` and `version`
pub(crate) fn create_metadata_location(location: impl AsRef<str>, version: i32) -> Result<String> {
if version < 0 {
return Err(Error::new(
ErrorKind::DataInvalid,
format!(
"Table metadata version: '{}' must be a non-negative integer",
version
),
));
};

let version = format!("{:0>5}", version);
let id = Uuid::new_v4();
let metadata_location = format!(
"{}/metadata/{}-{}.metadata.json",
location.as_ref(),
version,
id
);

Ok(metadata_location)
}

/// Get metadata location from `GlueTable` parameters
pub(crate) fn get_metadata_location(
parameters: &Option<HashMap<String, String>>,
Expand Down Expand Up @@ -288,7 +263,7 @@ mod tests {
use aws_sdk_glue::config::ProvideCredentials;
use aws_sdk_glue::types::Column;
use iceberg::spec::{NestedField, PrimitiveType, Schema, TableMetadataBuilder, Type};
use iceberg::{Namespace, Result, TableCreation};
use iceberg::{MetadataLocationParser, Namespace, Result, TableCreation};

use super::*;
use crate::schema::{ICEBERG_FIELD_CURRENT, ICEBERG_FIELD_ID, ICEBERG_FIELD_OPTIONAL};
Expand Down Expand Up @@ -332,7 +307,7 @@ mod tests {
fn test_convert_to_glue_table() -> Result<()> {
let table_name = "my_table".to_string();
let location = "s3a://warehouse/hive".to_string();
let metadata_location = create_metadata_location(location.clone(), 0)?;
let metadata_location = MetadataLocationParser::new_with_prefix(&location).to_string();
let properties = HashMap::new();
let schema = Schema::builder()
.with_schema_id(1)
Expand Down Expand Up @@ -362,8 +337,13 @@ mod tests {
.location(metadata.location())
.build();

let result =
convert_to_glue_table(&table_name, metadata_location, &metadata, &properties, None)?;
let result = convert_to_glue_table(
&table_name,
metadata_location.to_string(),
&metadata,
&properties,
None,
)?;

assert_eq!(result.name(), &table_name);
assert_eq!(result.description(), None);
Expand All @@ -372,22 +352,6 @@ mod tests {
Ok(())
}

#[test]
fn test_create_metadata_location() -> Result<()> {
let location = "my_base_location";
let valid_version = 0;
let invalid_version = -1;

let valid_result = create_metadata_location(location, valid_version)?;
let invalid_result = create_metadata_location(location, invalid_version);

assert!(valid_result.starts_with("my_base_location/metadata/00000-"));
assert!(valid_result.ends_with(".metadata.json"));
assert!(invalid_result.is_err());

Ok(())
}

#[test]
fn test_get_default_table_location() -> Result<()> {
let properties = HashMap::from([(LOCATION.to_string(), "db_location".to_string())]);
Expand Down
1 change: 0 additions & 1 deletion crates/catalog/hms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ serde_json = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
typed-builder = { workspace = true }
uuid = { workspace = true }
volo-thrift = { workspace = true }

# Transitive dependencies below
Expand Down
14 changes: 8 additions & 6 deletions crates/catalog/hms/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use iceberg::io::FileIO;
use iceberg::spec::{TableMetadata, TableMetadataBuilder};
use iceberg::table::Table;
use iceberg::{
Catalog, Error, ErrorKind, Namespace, NamespaceIdent, Result, TableCommit, TableCreation,
TableIdent,
Catalog, Error, ErrorKind, MetadataLocationParser, Namespace, NamespaceIdent, Result,
TableCommit, TableCreation, TableIdent,
};
use typed_builder::TypedBuilder;
use volo_thrift::MaybeException;
Expand Down Expand Up @@ -351,16 +351,18 @@ impl Catalog for HmsCatalog {
.build()?
.metadata;

let metadata_location = create_metadata_location(&location, 0)?;
let metadata_location = MetadataLocationParser::new_with_prefix(&location);

metadata.write_to(&self.file_io, &metadata_location).await?;
metadata
.write_to(&self.file_io, &metadata_location.to_string())
.await?;

let hive_table = convert_to_hive_table(
db_name.clone(),
metadata.current_schema(),
table_name.clone(),
location,
metadata_location.clone(),
metadata_location.to_string(),
metadata.properties(),
)?;

Expand All @@ -372,7 +374,7 @@ impl Catalog for HmsCatalog {

Table::builder()
.file_io(self.file_io())
.metadata_location(metadata_location)
.metadata_location(metadata_location.to_string())
.metadata(metadata)
.identifier(TableIdent::new(NamespaceIdent::new(db_name), table_name))
.build()
Expand Down
47 changes: 3 additions & 44 deletions crates/catalog/hms/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use hive_metastore::{Database, PrincipalType, SerDeInfo, StorageDescriptor};
use iceberg::spec::Schema;
use iceberg::{Error, ErrorKind, Namespace, NamespaceIdent, Result};
use pilota::{AHashMap, FastStr};
use uuid::Uuid;

use crate::schema::HiveSchemaBuilder;

Expand Down Expand Up @@ -249,30 +248,6 @@ pub(crate) fn get_default_table_location(
format!("{}/{}", location, table_name.as_ref())
}

/// Create metadata location from `location` and `version`
pub(crate) fn create_metadata_location(location: impl AsRef<str>, version: i32) -> Result<String> {
if version < 0 {
return Err(Error::new(
ErrorKind::DataInvalid,
format!(
"Table metadata version: '{}' must be a non-negative integer",
version
),
));
};

let version = format!("{:0>5}", version);
let id = Uuid::new_v4();
let metadata_location = format!(
"{}/metadata/{}-{}.metadata.json",
location.as_ref(),
version,
id
);

Ok(metadata_location)
}

/// Get metadata location from `HiveTable` parameters
pub(crate) fn get_metadata_location(
parameters: &Option<AHashMap<FastStr, FastStr>>,
Expand Down Expand Up @@ -339,7 +314,7 @@ fn get_current_time() -> Result<i32> {
#[cfg(test)]
mod tests {
use iceberg::spec::{NestedField, PrimitiveType, Type};
use iceberg::{Namespace, NamespaceIdent};
use iceberg::{MetadataLocationParser, Namespace, NamespaceIdent};

use super::*;

Expand Down Expand Up @@ -370,7 +345,7 @@ mod tests {
let db_name = "my_db".to_string();
let table_name = "my_table".to_string();
let location = "s3a://warehouse/hms".to_string();
let metadata_location = create_metadata_location(location.clone(), 0)?;
let metadata_location = MetadataLocationParser::new_with_prefix(location.clone());
let properties = HashMap::new();
let schema = Schema::builder()
.with_schema_id(1)
Expand All @@ -385,7 +360,7 @@ mod tests {
&schema,
table_name.clone(),
location.clone(),
metadata_location,
metadata_location.to_string(),
&properties,
)?;

Expand Down Expand Up @@ -414,22 +389,6 @@ mod tests {
Ok(())
}

#[test]
fn test_create_metadata_location() -> Result<()> {
let location = "my_base_location";
let valid_version = 0;
let invalid_version = -1;

let valid_result = create_metadata_location(location, valid_version)?;
let invalid_result = create_metadata_location(location, invalid_version);

assert!(valid_result.starts_with("my_base_location/metadata/00000-"));
assert!(valid_result.ends_with(".metadata.json"));
assert!(invalid_result.is_err());

Ok(())
}

#[test]
fn test_get_default_table_location() -> Result<()> {
let properties = HashMap::from([(LOCATION.to_string(), "db_location".to_string())]);
Expand Down
1 change: 0 additions & 1 deletion crates/catalog/s3tables/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ aws-config = { workspace = true }
aws-sdk-s3tables = "1.10.0"
iceberg = { workspace = true }
typed-builder = { workspace = true }
uuid = { workspace = true, features = ["v4"] }

[dev-dependencies]
iceberg_test_utils = { path = "../../test_utils", features = ["tests"] }
Expand Down
8 changes: 4 additions & 4 deletions crates/catalog/s3tables/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ use iceberg::io::{FileIO, FileIOBuilder};
use iceberg::spec::{TableMetadata, TableMetadataBuilder};
use iceberg::table::Table;
use iceberg::{
Catalog, Error, ErrorKind, Namespace, NamespaceIdent, Result, TableCommit, TableCreation,
TableIdent,
Catalog, Error, ErrorKind, MetadataLocationParser, Namespace, NamespaceIdent, Result,
TableCommit, TableCreation, TableIdent,
};
use typed_builder::TypedBuilder;

use crate::utils::{create_metadata_location, create_sdk_config};
use crate::utils::create_sdk_config;

/// S3Tables catalog configuration.
#[derive(Debug, TypedBuilder)]
Expand Down Expand Up @@ -325,7 +325,7 @@ impl Catalog for S3TablesCatalog {
.await
.map_err(from_aws_sdk_error)?;
let warehouse_location = get_resp.warehouse_location().to_string();
create_metadata_location(warehouse_location, 0)?
MetadataLocationParser::new_with_prefix(warehouse_location).to_string()
}
};

Expand Down
29 changes: 0 additions & 29 deletions crates/catalog/s3tables/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use std::collections::HashMap;

use aws_config::{BehaviorVersion, Region, SdkConfig};
use aws_sdk_s3tables::config::Credentials;
use iceberg::{Error, ErrorKind, Result};
use uuid::Uuid;

/// Property aws profile name
pub const AWS_PROFILE_NAME: &str = "profile_name";
Expand Down Expand Up @@ -71,30 +69,3 @@ pub(crate) async fn create_sdk_config(

config.load().await
}

/// Create metadata location from `location` and `version`
pub(crate) fn create_metadata_location(
warehouse_location: impl AsRef<str>,
version: i32,
) -> Result<String> {
if version < 0 {
return Err(Error::new(
ErrorKind::DataInvalid,
format!(
"Table metadata version: '{}' must be a non-negative integer",
version
),
));
};

let version = format!("{:0>5}", version);
let id = Uuid::new_v4();
let metadata_location = format!(
"{}/metadata/{}-{}.metadata.json",
warehouse_location.as_ref(),
version,
id
);

Ok(metadata_location)
}
1 change: 0 additions & 1 deletion crates/catalog/sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ async-trait = { workspace = true }
iceberg = { workspace = true }
sqlx = { version = "0.8.1", features = ["any"], default-features = false }
typed-builder = { workspace = true }
uuid = { workspace = true, features = ["v4"] }

[dev-dependencies]
iceberg_test_utils = { path = "../../test_utils", features = ["tests"] }
Expand Down
Loading
Loading