@@ -251,14 +251,18 @@ pub struct CreateTableRequest {
251251 /// Name of the table to create
252252 pub name : String ,
253253 /// Optional table location. If not provided, the server will choose a location.
254+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
254255 pub location : Option < String > ,
255256 /// Table schema
256257 pub schema : Schema ,
257258 /// Optional partition specification. If not provided, the table will be unpartitioned.
259+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
258260 pub partition_spec : Option < UnboundPartitionSpec > ,
259261 /// Optional sort order for the table
262+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
260263 pub write_order : Option < SortOrder > ,
261264 /// Whether to stage the create for a transaction (true) or create immediately (false)
265+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
262266 pub stage_create : Option < bool > ,
263267 /// Optional properties to set on the table
264268 #[ serde( default , skip_serializing_if = "HashMap::is_empty" ) ]
@@ -355,4 +359,117 @@ mod tests {
355359 json_no_props
356360 ) ;
357361 }
362+
363+ fn test_create_table_request_schema ( ) -> Schema {
364+ serde_json:: from_value ( serde_json:: json!( {
365+ "type" : "struct" ,
366+ "schema-id" : 1 ,
367+ "fields" : [
368+ {
369+ "id" : 1 ,
370+ "name" : "foo" ,
371+ "required" : false ,
372+ "type" : "string"
373+ } ,
374+ {
375+ "id" : 2 ,
376+ "name" : "bar" ,
377+ "required" : true ,
378+ "type" : "int"
379+ }
380+ ] ,
381+ "identifier-field-ids" : [ 2 ]
382+ } ) )
383+ . expect ( "Failed to deserialize test schema" )
384+ }
385+
386+ #[ test]
387+ fn test_create_table_request_minimal_serialization ( ) {
388+ let request = CreateTableRequest {
389+ name : "tbl1" . to_string ( ) ,
390+ location : None ,
391+ schema : test_create_table_request_schema ( ) ,
392+ partition_spec : None ,
393+ write_order : None ,
394+ stage_create : None ,
395+ properties : HashMap :: new ( ) ,
396+ } ;
397+
398+ let serialized = serde_json:: to_value ( & request) . expect ( "Serialization failed" ) ;
399+ let object = serialized. as_object ( ) . expect ( "Expected a JSON object" ) ;
400+ assert ! ( object. contains_key( "name" ) ) ;
401+ assert ! ( object. contains_key( "schema" ) ) ;
402+ assert ! ( !object. contains_key( "location" ) ) ;
403+ assert ! ( !object. contains_key( "partition-spec" ) ) ;
404+ assert ! ( !object. contains_key( "write-order" ) ) ;
405+ assert ! ( !object. contains_key( "stage-create" ) ) ;
406+ assert ! ( !object. contains_key( "properties" ) ) ;
407+ }
408+
409+ #[ test]
410+ fn test_create_table_request_full_serialization ( ) {
411+ let request: CreateTableRequest = serde_json:: from_value ( serde_json:: json!( {
412+ "name" : "tbl1" ,
413+ "location" : "s3://warehouse/tbl1" ,
414+ "schema" : test_create_table_request_schema( ) ,
415+ "partition-spec" : {
416+ "spec-id" : 1 ,
417+ "fields" : [
418+ {
419+ "source-id" : 2 ,
420+ "field-id" : 1000 ,
421+ "name" : "bar" ,
422+ "transform" : "identity"
423+ }
424+ ]
425+ } ,
426+ "write-order" : {
427+ "order-id" : 1 ,
428+ "fields" : [
429+ {
430+ "transform" : "identity" ,
431+ "source-id" : 2 ,
432+ "direction" : "asc" ,
433+ "null-order" : "nulls-first"
434+ }
435+ ]
436+ } ,
437+ "stage-create" : true ,
438+ "properties" : {
439+ "owner" : "test"
440+ }
441+ } ) )
442+ . expect ( "Deserialization failed" ) ;
443+
444+ let serialized = serde_json:: to_value ( & request) . expect ( "Serialization failed" ) ;
445+ let object = serialized. as_object ( ) . expect ( "Expected a JSON object" ) ;
446+ assert_eq ! (
447+ object. get( "location" ) ,
448+ Some ( & serde_json:: json!( "s3://warehouse/tbl1" ) )
449+ ) ;
450+ assert ! ( object. contains_key( "partition-spec" ) ) ;
451+ assert ! ( object. contains_key( "write-order" ) ) ;
452+ assert_eq ! ( object. get( "stage-create" ) , Some ( & serde_json:: json!( true ) ) ) ;
453+ assert ! ( object. contains_key( "properties" ) ) ;
454+ }
455+
456+ #[ test]
457+ fn test_create_table_request_deserialize_explicit_nulls ( ) {
458+ let request: CreateTableRequest = serde_json:: from_value ( serde_json:: json!( {
459+ "name" : "tbl1" ,
460+ "location" : null,
461+ "schema" : test_create_table_request_schema( ) ,
462+ "partition-spec" : null,
463+ "write-order" : null,
464+ "stage-create" : null
465+ } ) )
466+ . expect ( "Deserialization failed" ) ;
467+
468+ assert_eq ! ( request. name, "tbl1" ) ;
469+ assert_eq ! ( request. location, None ) ;
470+ assert_eq ! ( request. partition_spec, None ) ;
471+ assert_eq ! ( request. write_order, None ) ;
472+ assert_eq ! ( request. stage_create, None ) ;
473+ assert ! ( request. properties. is_empty( ) ) ;
474+ }
358475}
0 commit comments