marvinlanhenke commented on code in PR #314: URL: https://github.com/apache/iceberg-rust/pull/314#discussion_r1567403891
########## crates/catalog/glue/src/catalog.rs: ########## @@ -310,31 +327,282 @@ impl Catalog for GlueCatalog { Ok(table_list) } + /// Creates a new table within a specified namespace using the provided + /// table creation settings. + /// + /// # Returns + /// A `Result` wrapping a `Table` object representing the newly created + /// table. + /// + /// # Errors + /// This function may return an error in several cases, including invalid + /// namespace identifiers, failure to determine a default storage location, + /// issues generating or writing table metadata, and errors communicating + /// with the Glue Catalog. async fn create_table( &self, - _namespace: &NamespaceIdent, - _creation: TableCreation, + namespace: &NamespaceIdent, + creation: TableCreation, ) -> Result<Table> { - todo!() + let db_name = validate_namespace(namespace)?; + let table_name = creation.name.clone(); + + let location = match &creation.location { + Some(location) => location.clone(), + None => { + let ns = self.get_namespace(namespace).await?; + get_default_table_location(&ns, &table_name, &self.config.warehouse) + } + }; + + let metadata = TableMetadataBuilder::from_table_creation(creation)?.build()?; + let metadata_location = create_metadata_location(&location, 0)?; + + let mut file = self + .file_io + .new_output(&metadata_location)? + .writer() + .await?; + file.write_all(&serde_json::to_vec(&metadata)?).await?; + file.shutdown().await?; + + let glue_table = convert_to_glue_table( + &table_name, + metadata_location.clone(), + &metadata, + metadata.properties(), + None, + )?; + + let builder = self + .client + .0 + .create_table() + .database_name(&db_name) + .table_input(glue_table); + let builder = with_catalog_id!(builder, self.config); + + builder.send().await.map_err(from_aws_sdk_error)?; + + let table = Table::builder() + .file_io(self.file_io()) + .metadata_location(metadata_location) + .metadata(metadata) + .identifier(TableIdent::new(NamespaceIdent::new(db_name), table_name)) + .build(); + + Ok(table) } - async fn load_table(&self, _table: &TableIdent) -> Result<Table> { - todo!() + /// Loads a table from the Glue Catalog and constructs a `Table` object + /// based on its metadata. + /// + /// # Returns + /// A `Result` wrapping a `Table` object that represents the loaded table. + /// + /// # Errors + /// This function may return an error in several scenarios, including: + /// - Failure to validate the namespace. + /// - Failure to retrieve the table from the Glue Catalog. + /// - Absence of metadata location information in the table's properties. + /// - Issues reading or deserializing the table's metadata file. + async fn load_table(&self, table: &TableIdent) -> Result<Table> { + let db_name = validate_namespace(table.namespace())?; + let table_name = table.name(); + + let builder = self + .client + .0 + .get_table() + .database_name(&db_name) + .name(table_name); + let builder = with_catalog_id!(builder, self.config); + + let glue_table_output = builder.send().await.map_err(from_aws_sdk_error)?; + + match glue_table_output.table() { + None => Err(Error::new( + ErrorKind::Unexpected, + format!( + "'Table' object for database: {} and table: {} does not exist", Review Comment: Probably wanted to remove both single quotes here? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org