liurenjie1024 commented on code in PR #1549:
URL: https://github.com/apache/iceberg-rust/pull/1549#discussion_r2228019613


##########
crates/iceberg/src/catalog/memory/catalog.rs:
##########
@@ -289,12 +293,31 @@ impl Catalog for MemoryCatalog {
             .build()
     }
 
-    /// Update a table to the catalog.
-    async fn update_table(&self, _commit: TableCommit) -> Result<Table> {
-        Err(Error::new(
-            ErrorKind::FeatureUnsupported,
-            "MemoryCatalog does not currently support updating tables.",
-        ))
+    /// Update a table in the catalog.
+    async fn update_table(&self, commit: TableCommit) -> Result<Table> {
+        let mut root_namespace_state = self.root_namespace_state.lock().await;
+
+        // Updates the current table version and writes a new metadata file.
+        let current_table = self
+            .load_table_from_locked_state(commit.identifier(), 
&root_namespace_state)
+            .await?;
+
+        // Apply TableCommit to get staged table
+        let staged_table = commit.apply(current_table)?;
+
+        // Write table metadata to the new location
+        staged_table
+            .metadata()
+            .write_to(
+                staged_table.file_io(),
+                staged_table.metadata_location().unwrap(),

Review Comment:
   We should not panic here. Also I think we should generate a new table 
metadata location?



##########
crates/iceberg/src/catalog/utils.rs:
##########
@@ -0,0 +1,239 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::fmt::Display;
+use std::str::FromStr;
+
+use uuid::Uuid;
+
+use crate::{Error, ErrorKind, Result};
+
+/// Helper for parsing a location of the format: 
`<prefix>/metadata/<version>-<uuid>.metadata.json`
+#[derive(Clone, Debug, PartialEq)]
+pub struct MetadataLocationParser {
+    prefix: String,

Review Comment:
   ```suggestion
       table_location: String,
   ```



##########
crates/iceberg/src/catalog/memory/namespace_state.rs:
##########
@@ -296,4 +297,22 @@ impl NamespaceState {
             Some(metadata_location) => Ok(metadata_location),
         }
     }
+
+    // Updates the metadata location of the given table or returns an error if 
it doesn't exist
+    pub(crate) fn commit_table_update(&mut self, staged_table: Table) -> 
Result<Table> {
+        let namespace = 
self.get_mut_namespace(staged_table.identifier().namespace())?;
+
+        let _ = namespace
+            .table_metadata_locations
+            .insert(
+                staged_table.identifier().name().to_string(),
+                staged_table.metadata_location().unwrap().to_string(),

Review Comment:
   We should not panic here. We could add an `metadata_location_result` method 
to `Table` to return `Result<&str>` for convenience.



##########
crates/iceberg/src/catalog/utils.rs:
##########


Review Comment:
   Also I would suggest to move this into a separate pr.



##########
crates/iceberg/src/catalog/utils.rs:
##########
@@ -0,0 +1,239 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::fmt::Display;
+use std::str::FromStr;
+
+use uuid::Uuid;
+
+use crate::{Error, ErrorKind, Result};
+
+/// Helper for parsing a location of the format: 
`<prefix>/metadata/<version>-<uuid>.metadata.json`
+#[derive(Clone, Debug, PartialEq)]
+pub struct MetadataLocationParser {

Review Comment:
   ```suggestion
   pub struct MetadataLocation {
   ```
   
   How about just rename it to `MetadataLocation`? I think it's a useful struct 
which could be used for both parsing and generating name.



##########
crates/iceberg/src/catalog/utils.rs:
##########


Review Comment:
   The mod name `utils` is too generic. We should rename it to 
`metadata_location` or sth more meaningful.



-- 
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

Reply via email to