@@ -1010,10 +1010,14 @@ pub(super) mod _serde {
10101010 . collect ( ) ,
10111011 default_spec_id : v. default_spec . spec_id ( ) ,
10121012 last_partition_id : v. last_partition_id ,
1013- properties : Some ( v. properties ) ,
1014- current_snapshot_id : v. current_snapshot_id . or ( Some ( -1 ) ) ,
1013+ properties : if v. properties . is_empty ( ) {
1014+ None
1015+ } else {
1016+ Some ( v. properties )
1017+ } ,
1018+ current_snapshot_id : v. current_snapshot_id ,
10151019 snapshots : if v. snapshots . is_empty ( ) {
1016- Some ( vec ! [ ] )
1020+ None
10171021 } else {
10181022 Some (
10191023 v. snapshots
@@ -1091,7 +1095,7 @@ pub(super) mod _serde {
10911095 } else {
10921096 Some ( v. properties )
10931097 } ,
1094- current_snapshot_id : v. current_snapshot_id . or ( Some ( - 1 ) ) ,
1098+ current_snapshot_id : v. current_snapshot_id ,
10951099 snapshots : if v. snapshots . is_empty ( ) {
10961100 None
10971101 } else {
@@ -1279,6 +1283,7 @@ mod tests {
12791283 "timestamp-ms": 1515100
12801284 }
12811285 ],
1286+ "refs": {},
12821287 "sort-orders": [
12831288 {
12841289 "order-id": 0,
@@ -1349,7 +1354,11 @@ mod tests {
13491354 refs : HashMap :: new ( ) ,
13501355 } ;
13511356
1357+ let expected_json_value = serde_json:: to_value ( & expected) . unwrap ( ) ;
13521358 check_table_metadata_serde ( data, expected) ;
1359+
1360+ let json_value = serde_json:: from_str :: < serde_json:: Value > ( data) . unwrap ( ) ;
1361+ assert_eq ! ( json_value, expected_json_value) ;
13531362 }
13541363
13551364 #[ test]
@@ -1519,6 +1528,106 @@ mod tests {
15191528 check_table_metadata_serde ( data, expected) ;
15201529 }
15211530
1531+ #[ test]
1532+ fn test_table_data_v2_no_snapshots ( ) {
1533+ let data = r#"
1534+ {
1535+ "format-version" : 2,
1536+ "table-uuid": "fb072c92-a02b-11e9-ae9c-1bb7bc9eca94",
1537+ "location": "s3://b/wh/data.db/table",
1538+ "last-sequence-number" : 1,
1539+ "last-updated-ms": 1515100955770,
1540+ "last-column-id": 1,
1541+ "schemas": [
1542+ {
1543+ "schema-id" : 1,
1544+ "type" : "struct",
1545+ "fields" :[
1546+ {
1547+ "id": 1,
1548+ "name": "struct_name",
1549+ "required": true,
1550+ "type": "fixed[1]"
1551+ }
1552+ ]
1553+ }
1554+ ],
1555+ "current-schema-id" : 1,
1556+ "partition-specs": [
1557+ {
1558+ "spec-id": 0,
1559+ "fields": []
1560+ }
1561+ ],
1562+ "refs": {},
1563+ "default-spec-id": 0,
1564+ "last-partition-id": 1000,
1565+ "metadata-log": [
1566+ {
1567+ "metadata-file": "s3://bucket/.../v1.json",
1568+ "timestamp-ms": 1515100
1569+ }
1570+ ],
1571+ "sort-orders": [
1572+ {
1573+ "order-id": 0,
1574+ "fields": []
1575+ }
1576+ ],
1577+ "default-sort-order-id": 0
1578+ }
1579+ "# ;
1580+
1581+ let schema = Schema :: builder ( )
1582+ . with_schema_id ( 1 )
1583+ . with_fields ( vec ! [ Arc :: new( NestedField :: required(
1584+ 1 ,
1585+ "struct_name" ,
1586+ Type :: Primitive ( PrimitiveType :: Fixed ( 1 ) ) ,
1587+ ) ) ] )
1588+ . build ( )
1589+ . unwrap ( ) ;
1590+
1591+ let partition_spec = BoundPartitionSpec :: builder ( schema. clone ( ) )
1592+ . with_spec_id ( 0 )
1593+ . build ( )
1594+ . unwrap ( ) ;
1595+
1596+ let expected = TableMetadata {
1597+ format_version : FormatVersion :: V2 ,
1598+ table_uuid : Uuid :: parse_str ( "fb072c92-a02b-11e9-ae9c-1bb7bc9eca94" ) . unwrap ( ) ,
1599+ location : "s3://b/wh/data.db/table" . to_string ( ) ,
1600+ last_updated_ms : 1515100955770 ,
1601+ last_column_id : 1 ,
1602+ schemas : HashMap :: from_iter ( vec ! [ ( 1 , Arc :: new( schema) ) ] ) ,
1603+ current_schema_id : 1 ,
1604+ partition_specs : HashMap :: from_iter ( vec ! [ (
1605+ 0 ,
1606+ partition_spec. clone( ) . into_schemaless( ) . into( ) ,
1607+ ) ] ) ,
1608+ default_spec : partition_spec. into ( ) ,
1609+ last_partition_id : 1000 ,
1610+ default_sort_order_id : 0 ,
1611+ sort_orders : HashMap :: from_iter ( vec ! [ ( 0 , SortOrder :: unsorted_order( ) . into( ) ) ] ) ,
1612+ snapshots : HashMap :: default ( ) ,
1613+ current_snapshot_id : None ,
1614+ last_sequence_number : 1 ,
1615+ properties : HashMap :: new ( ) ,
1616+ snapshot_log : Vec :: new ( ) ,
1617+ metadata_log : vec ! [ MetadataLog {
1618+ metadata_file: "s3://bucket/.../v1.json" . to_string( ) ,
1619+ timestamp_ms: 1515100 ,
1620+ } ] ,
1621+ refs : HashMap :: new ( ) ,
1622+ } ;
1623+
1624+ let expected_json_value = serde_json:: to_value ( & expected) . unwrap ( ) ;
1625+ check_table_metadata_serde ( data, expected) ;
1626+
1627+ let json_value = serde_json:: from_str :: < serde_json:: Value > ( data) . unwrap ( ) ;
1628+ assert_eq ! ( json_value, expected_json_value) ;
1629+ }
1630+
15221631 #[ test]
15231632 fn test_current_snapshot_id_must_match_main_branch ( ) {
15241633 let data = r#"
0 commit comments