Skip to content

Commit a30ddea

Browse files
committed
add test
1 parent d1559f2 commit a30ddea

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

crates/catalog/sql/src/catalog.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,4 +2338,56 @@ mod tests {
23382338
assert_eq!(table.identifier(), expected_table.identifier());
23392339
assert_eq!(table.metadata_location(), Some(metadata_location.as_str()));
23402340
}
2341+
2342+
#[tokio::test]
2343+
async fn test_update_table() {
2344+
let warehouse_loc = temp_path();
2345+
let catalog = new_sql_catalog(warehouse_loc).await;
2346+
2347+
// Create a test namespace and table
2348+
let namespace_ident = NamespaceIdent::new("ns1".into());
2349+
create_namespace(&catalog, &namespace_ident).await;
2350+
let table_ident = TableIdent::new(namespace_ident.clone(), "tbl1".into());
2351+
create_table(&catalog, &table_ident).await;
2352+
2353+
let table = catalog.load_table(&table_ident).await.unwrap();
2354+
2355+
// Store the original metadata location for comparison
2356+
let original_metadata_location = table.metadata_location().unwrap().to_string();
2357+
2358+
// Create a transaction to update the table
2359+
let tx = Transaction::new(&table);
2360+
let tx = tx
2361+
.update_table_properties()
2362+
.set("test_property".to_string(), "test_value".to_string())
2363+
.apply(tx)
2364+
.unwrap();
2365+
2366+
// Commit the transaction to the catalog
2367+
let updated_table = tx.commit(&catalog).await.unwrap();
2368+
2369+
// Verify the update was successful
2370+
assert_eq!(
2371+
updated_table.metadata().properties().get("test_property"),
2372+
Some(&"test_value".to_string())
2373+
);
2374+
// Verify the metadata location has been updated
2375+
assert_ne!(
2376+
updated_table.metadata_location().unwrap(),
2377+
original_metadata_location.as_str()
2378+
);
2379+
2380+
// Load the table again from the catalog to verify changes were persisted
2381+
let reloaded = catalog.load_table(&table_ident).await.unwrap();
2382+
2383+
// Verify the reloaded table matches the updated table
2384+
assert_eq!(
2385+
reloaded.metadata().properties().get("test_property"),
2386+
Some(&"test_value".to_string())
2387+
);
2388+
assert_eq!(
2389+
reloaded.metadata_location(),
2390+
updated_table.metadata_location()
2391+
);
2392+
}
23412393
}

0 commit comments

Comments
 (0)