luoyuxia commented on code in PR #32:
URL: https://github.com/apache/fluss-rust/pull/32#discussion_r2435078097
##########
crates/fluss/tests/integration/admin.rs:
##########
@@ -126,6 +129,170 @@ mod admin_test {
#[tokio::test]
async fn test_create_table() {
- // todo
+ let cluster = get_fluss_cluster();
+ let connection = cluster.get_fluss_connection().await;
+ let admin = connection
+ .get_admin()
+ .await
+ .expect("Failed to get admin client");
+
+ let test_db_name = "test_create_table_db";
+ let db_descriptor = DatabaseDescriptorBuilder::default()
+ .comment("Database for test_create_table")
+ .build();
+
+ assert_eq!(admin.database_exists(test_db_name).await.unwrap(), false);
+ admin
+ .create_database(test_db_name, false, Some(&db_descriptor))
+ .await
+ .expect("Failed to create test database");
+
+ let test_table_name = "test_user_table";
+ let table_path = TablePath::new(test_db_name.to_string(),
test_table_name.to_string());
+
+ // build table schema
+ let table_schema = Schema::builder()
+ .column("id", DataTypes::int())
+ .column("name", DataTypes::string())
+ .column("age", DataTypes::int())
+ .with_comment("User's age (optional)")
+ .column("email", DataTypes::string())
+ .primary_key_named("PK_test_user_table", vec!["id".to_string()])
+ .build()
+ .expect("Failed to build table schema");
+
+ // build table descriptor
+ let table_descriptor = TableDescriptor::builder()
+ .schema(table_schema.clone())
+ .comment("Test table for user data (id, name, age, email)")
+ .distributed_by(Some(3), vec!["id".to_string()])
+ .property("table.replication.factor", "1")
+ .log_format(LogFormat::ARROW)
+ .kv_format(KvFormat::INDEXED)
+ .build()
+ .expect("Failed to build table descriptor");
+
+ // create test table
+ admin
+ .create_table(&table_path, &table_descriptor, false)
+ .await
+ .expect("Failed to create test table");
+
+ assert!(
+ admin.table_exists(&table_path).await.unwrap(),
+ "Table {:?} should exist after creation",
+ table_path
+ );
+
+ let tables = admin.list_tables(test_db_name).await.unwrap();
+ assert!(
+ tables.len() == 1,
+ "There should be exactly one table in the database"
+ );
+ assert!(
+ tables.contains(&test_table_name.to_string()),
+ "Table list should contain the created table"
+ );
+
+ let table_info = admin
+ .get_table(&table_path)
+ .await
+ .expect("Failed to get table info");
+
+ // verify table comment
+ assert_eq!(
+ table_info.get_comment(),
+ Some("Test table for user data (id, name, age, email)"),
+ "Table comment mismatch"
+ );
+
+ // verify schema columns
Review Comment:
Can be simpifiy to
```
let actual_schema = table_info.get_schema();
assert_eq!(actual_schema, table_descriptor.schema(), "Schema
mismatch");
// verify distribution and properties
assert_eq!(table_info.get_num_buckets(), 3, "Bucket count mismatch");
assert_eq!(
table_info.get_bucket_keys(),
&vec!["id".to_string()],
"Bucket keys mismatch"
);
assert_eq!(table_info.get_properties(),
table_descriptor.properties(), "Properties mismatch");
```
Add `#[derive(Eq)]` to `Schema`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]