@@ -26,10 +26,9 @@ use iceberg::spec::{TableMetadata, TableMetadataBuilder};
2626use iceberg:: table:: Table ;
2727use iceberg:: {
2828 Catalog , Error , ErrorKind , Namespace , NamespaceIdent , Result , TableCommit , TableCreation ,
29- TableIdent , TableRequirement , TableUpdate ,
29+ TableIdent ,
3030} ;
3131use itertools:: Itertools ;
32- use regex:: Regex ;
3332use uuid:: Uuid ;
3433
3534use crate :: namespace_state:: NamespaceState ;
@@ -278,75 +277,50 @@ impl Catalog for MemoryCatalog {
278277 }
279278
280279 /// Update a table to the catalog.
281- async fn update_table ( & self , commit : TableCommit ) -> Result < Table > {
280+ async fn update_table ( & self , _commit : TableCommit ) -> Result < Table > {
282281 Err ( Error :: new (
283282 ErrorKind :: FeatureUnsupported ,
284283 "MemoryCatalog does not currently support updating tables." ,
285284 ) )
286285 }
287286
288- async fn commit_table ( & self , base : & Table , current : Table ) -> Result < Table > {
289- if base. metadata ( ) == current. metadata ( ) {
290- // no change
291- return Ok ( current) ;
292- }
293-
294- let mut root_namespace_state = self . root_namespace_state . lock ( ) . await ;
295- // TODO: caller needs to retry on the error below
296- let _ = root_namespace_state
297- . check_metadata_location ( base. identifier ( ) , base. metadata_location ( ) ) ?;
298-
299- let next_metadata_version = if let Some ( base_metadata_location) = base. metadata_location ( ) {
300- self . parse_metadata_version ( base_metadata_location) + 1
301- } else {
302- 0
303- } ;
304-
305- // write metadata
306- let metadata_location = format ! (
307- "{}/metadata/{}-{}.metadata.json" ,
308- current. metadata( ) . location( ) ,
309- next_metadata_version,
310- Uuid :: new_v4( )
311- ) ;
312-
313- // TODO instead of using current.metadata(), build a new metadata with some properties like last_updated_ms updated
314- self . file_io
315- . new_output ( & metadata_location) ?
316- . write ( serde_json:: to_vec ( current. metadata ( ) ) ?. into ( ) )
317- . await ?;
318-
319- root_namespace_state
320- . update_existing_table_location ( current. identifier ( ) , current. metadata_location ( ) ) ?;
321-
322- // TODO same here, need to update the metadata location
323- Ok ( current)
324- }
325- }
326-
327- // todo move this to metadata?
328- fn parse_metadata_version ( metadata_location : & str ) -> Result < i32 > {
329- let pattern = r"(\d+)-([\w-]{36})(?:\.\w+)?\.metadata\.json" ; // todo make this constant
330-
331- if let Some ( metadata_file_name) = metadata_location. split ( '/' ) . last ( ) {
332- let re = Regex :: new ( pattern) . expect ( "Failed to parse regex for metadata file!" ) ;
333- if let Some ( caps) = re. captures ( metadata_file_name) {
334- let metadata_version_str = & caps[ 1 ] ;
335- let uuid_str = & caps[ 2 ] ;
336-
337- let metadata_version = metadata_version_str
338- . parse ( )
339- . expect ( format ! ( "Invalid metadata version: {metadata_version_str}" ) . as_str ( ) ) ;
340- let uuid = Uuid :: parse_str ( uuid_str) ?;
341-
342- return Ok ( metadata_version) ;
343- }
344- }
345-
346- Err ( Error :: new (
347- ErrorKind :: Unexpected ,
348- format ! ( "Unrecognizable metadata location: {metadata_location}" ) ,
349- ) )
287+ // async fn commit_table(&self, base: &Table, current: Table) -> Result<Table> {
288+ // if base.metadata() == current.metadata() {
289+ // // no change
290+ // return Ok(current);
291+ // }
292+ //
293+ // let mut root_namespace_state = self.root_namespace_state.lock().await;
294+ // // TODO: caller needs to retry on the error below
295+ // let _ = root_namespace_state
296+ // .check_metadata_location(base.identifier(), base.metadata_location())?;
297+ //
298+ // let next_metadata_version = if let Some(base_metadata_location) = base.metadata_location() {
299+ // self.parse_metadata_version(base_metadata_location) + 1
300+ // } else {
301+ // 0
302+ // };
303+ //
304+ // // write metadata
305+ // let metadata_location = format!(
306+ // "{}/metadata/{}-{}.metadata.json",
307+ // current.metadata().location(),
308+ // next_metadata_version,
309+ // Uuid::new_v4()
310+ // );
311+ //
312+ // // TODO instead of using current.metadata(), build a new metadata with some properties like last_updated_ms updated
313+ // self.file_io
314+ // .new_output(&metadata_location)?
315+ // .write(serde_json::to_vec(current.metadata())?.into())
316+ // .await?;
317+ //
318+ // root_namespace_state
319+ // .update_existing_table_location(current.identifier(), current.metadata_location())?;
320+ //
321+ // // TODO same here, need to update the metadata location
322+ // Ok(current)
323+ // }
350324}
351325
352326#[ cfg( test) ]
0 commit comments