@@ -145,7 +145,14 @@ where
145145
146146impl From < protobuf:: ColumnRelation > for TableReference {
147147 fn from ( rel : protobuf:: ColumnRelation ) -> Self {
148- Self :: parse_str_normalized ( rel. relation . as_str ( ) , true )
148+ match rel. parts . as_slice ( ) {
149+ [ table] => Self :: bare ( table. as_str ( ) ) ,
150+ [ schema, table] => Self :: partial ( schema. as_str ( ) , table. as_str ( ) ) ,
151+ [ catalog, schema, table] => {
152+ Self :: full ( catalog. as_str ( ) , schema. as_str ( ) , table. as_str ( ) )
153+ }
154+ _ => Self :: parse_str_normalized ( rel. relation . as_str ( ) , true ) ,
155+ }
149156 }
150157}
151158
@@ -1386,6 +1393,7 @@ pub(crate) fn csv_writer_options_from_proto(
13861393
13871394#[ cfg( test) ]
13881395mod tests {
1396+ use datafusion_common:: TableReference ;
13891397 use datafusion_common:: config:: {
13901398 MaxRowGroupBytes , ParquetCdcOptions , ParquetOptions , TableParquetOptions ,
13911399 } ;
@@ -1405,6 +1413,82 @@ mod tests {
14051413 ) ;
14061414 }
14071415
1416+ #[ test]
1417+ fn column_relation_round_trip_preserves_dotted_bare_table ( ) {
1418+ let column = datafusion_common:: Column :: new (
1419+ Some ( TableReference :: bare ( "has.dot" ) ) ,
1420+ "column" ,
1421+ ) ;
1422+
1423+ let proto: crate :: protobuf_common:: Column = ( & column) . into ( ) ;
1424+ let relation = proto. relation . expect ( "relation should be present" ) ;
1425+
1426+ assert_eq ! ( relation. relation, "has.dot" ) ;
1427+ assert_eq ! ( relation. parts, vec![ "has.dot" . to_string( ) ] ) ;
1428+
1429+ let recovered = TableReference :: from ( relation) ;
1430+ assert_eq ! ( recovered, TableReference :: bare( "has.dot" ) ) ;
1431+ }
1432+
1433+ #[ test]
1434+ fn column_relation_round_trip_preserves_dotted_partial_reference ( ) {
1435+ let column = datafusion_common:: Column :: new (
1436+ Some ( TableReference :: partial ( "my.schema" , "table" ) ) ,
1437+ "column" ,
1438+ ) ;
1439+
1440+ let proto: crate :: protobuf_common:: Column = ( & column) . into ( ) ;
1441+ let relation = proto. relation . expect ( "relation should be present" ) ;
1442+
1443+ assert_eq ! ( relation. relation, "my.schema.table" ) ;
1444+ assert_eq ! (
1445+ relation. parts,
1446+ vec![ "my.schema" . to_string( ) , "table" . to_string( ) ]
1447+ ) ;
1448+
1449+ let recovered = TableReference :: from ( relation) ;
1450+ assert_eq ! ( recovered, TableReference :: partial( "my.schema" , "table" ) ) ;
1451+ }
1452+
1453+ #[ test]
1454+ fn column_relation_round_trip_preserves_dotted_full_reference ( ) {
1455+ let column = datafusion_common:: Column :: new (
1456+ Some ( TableReference :: full ( "catalog" , "my.schema" , "table" ) ) ,
1457+ "column" ,
1458+ ) ;
1459+
1460+ let proto: crate :: protobuf_common:: Column = ( & column) . into ( ) ;
1461+ let relation = proto. relation . expect ( "relation should be present" ) ;
1462+
1463+ assert_eq ! ( relation. relation, "catalog.my.schema.table" ) ;
1464+ assert_eq ! (
1465+ relation. parts,
1466+ vec![
1467+ "catalog" . to_string( ) ,
1468+ "my.schema" . to_string( ) ,
1469+ "table" . to_string( )
1470+ ]
1471+ ) ;
1472+
1473+ let recovered = TableReference :: from ( relation) ;
1474+ assert_eq ! (
1475+ recovered,
1476+ TableReference :: full( "catalog" , "my.schema" , "table" )
1477+ ) ;
1478+ }
1479+
1480+ #[ test]
1481+ fn column_relation_decodes_legacy_relation ( ) {
1482+ let proto = crate :: protobuf_common:: ColumnRelation {
1483+ relation : "schema.table" . to_string ( ) ,
1484+ parts : vec ! [ ] ,
1485+ } ;
1486+
1487+ let recovered = TableReference :: from ( proto) ;
1488+
1489+ assert_eq ! ( recovered, TableReference :: partial( "schema" , "table" ) ) ;
1490+ }
1491+
14081492 #[ test]
14091493 fn table_parquet_options_defaults_missing_global ( ) {
14101494 let recovered = TableParquetOptions :: try_from (
0 commit comments