@@ -1690,6 +1690,7 @@ impl<'a> SchemaTransform<'a> for SchemaDepthChecker {
16901690
16911691#[ cfg( test) ]
16921692mod tests {
1693+ use crate :: table_features:: ColumnMappingMode ;
16931694 use crate :: utils:: test_utils:: assert_result_error_with_message;
16941695
16951696 use super :: * ;
@@ -2896,4 +2897,87 @@ mod tests {
28962897 ) ;
28972898 Ok ( ( ) )
28982899 }
2900+
2901+ #[ test]
2902+ fn test_physical_name_with_mode_none ( ) {
2903+ let field_json = r#"{
2904+ "name": "logical_name",
2905+ "type": "string",
2906+ "nullable": true,
2907+ "metadata": {
2908+ "delta.columnMapping.physicalName": "physical_name_col123"
2909+ }
2910+ }"# ;
2911+ let field: StructField = serde_json:: from_str ( field_json) . unwrap ( ) ;
2912+
2913+ // With ColumnMappingMode::None, should return logical name even though physical name exists
2914+ assert_eq ! ( field. physical_name( ColumnMappingMode :: None ) , "logical_name" ) ;
2915+ }
2916+
2917+ #[ test]
2918+ fn test_physical_name_with_mode_id ( ) {
2919+ let field_json = r#"{
2920+ "name": "logical_name",
2921+ "type": "string",
2922+ "nullable": true,
2923+ "metadata": {
2924+ "delta.columnMapping.id": 5,
2925+ "delta.columnMapping.physicalName": "physical_name_col123"
2926+ }
2927+ }"# ;
2928+ let field: StructField = serde_json:: from_str ( field_json) . unwrap ( ) ;
2929+
2930+ // With ColumnMappingMode::Id, should return physical name
2931+ assert_eq ! (
2932+ field. physical_name( ColumnMappingMode :: Id ) ,
2933+ "physical_name_col123"
2934+ ) ;
2935+ }
2936+
2937+ #[ test]
2938+ fn test_physical_name_with_mode_name ( ) {
2939+ let field_json = r#"{
2940+ "name": "logical_name",
2941+ "type": "string",
2942+ "nullable": true,
2943+ "metadata": {
2944+ "delta.columnMapping.physicalName": "physical_name_col456"
2945+ }
2946+ }"# ;
2947+ let field: StructField = serde_json:: from_str ( field_json) . unwrap ( ) ;
2948+
2949+ // With ColumnMappingMode::Name, should return physical name
2950+ assert_eq ! (
2951+ field. physical_name( ColumnMappingMode :: Name ) ,
2952+ "physical_name_col456"
2953+ ) ;
2954+ }
2955+
2956+ #[ test]
2957+ fn test_physical_name_fallback_id ( ) {
2958+ let field_json = r#"{
2959+ "name": "logical_name",
2960+ "type": "string",
2961+ "nullable": true,
2962+ "metadata": {}
2963+ }"# ;
2964+ let field: StructField = serde_json:: from_str ( field_json) . unwrap ( ) ;
2965+
2966+ // With ColumnMappingMode::Id but no physical name, should fallback to logical name
2967+ assert_eq ! ( field. physical_name( ColumnMappingMode :: Id ) , "logical_name" ) ;
2968+ }
2969+
2970+ #[ test]
2971+ fn test_physical_name_fallback_name ( ) {
2972+ let field_json = r#"{
2973+ "name": "logical_name",
2974+ "type": "string",
2975+ "nullable": true,
2976+ "metadata": {}
2977+ }"# ;
2978+ let field: StructField = serde_json:: from_str ( field_json) . unwrap ( ) ;
2979+
2980+ // With ColumnMappingMode::Name but no physical name, should fallback to logical name
2981+ assert_eq ! ( field. physical_name( ColumnMappingMode :: Name ) , "logical_name" ) ;
2982+ }
28992983}
0 commit comments