@@ -1048,20 +1048,35 @@ public static List<String> getIdentityPartitionColumns(Table table) {
10481048 return getIdentityPartitionColumns (table , false , false );
10491049 }
10501050
1051+ public static List <String > getIdentityPartitionColumns (Table table , Schema scanSchema ) {
1052+ return getIdentityPartitionColumns (table , scanSchema , false , false );
1053+ }
1054+
10511055 public static List <String > getIdentityPartitionColumns (Table table ,
10521056 boolean enableMappingVarbinary , boolean enableMappingTimestampTz ) {
1057+ return getIdentityPartitionColumns (
1058+ table , table .schema (), enableMappingVarbinary , enableMappingTimestampTz );
1059+ }
1060+
1061+ /**
1062+ * Resolve identity partition names against the schema that owns this scan, rather than the
1063+ * table's latest schema. A pinned snapshot can expose a renamed field whose case-sensitive
1064+ * name must match the scan slots in {@code scanSchema}.
1065+ */
1066+ public static List <String > getIdentityPartitionColumns (Table table , Schema scanSchema ,
1067+ boolean enableMappingVarbinary , boolean enableMappingTimestampTz ) {
10531068 LinkedHashSet <String > partitionColumns = new LinkedHashSet <>();
10541069 for (PartitionSpec spec : table .specs ().values ()) {
10551070 for (PartitionField partitionField : spec .fields ()) {
10561071 if (!partitionField .transform ().isIdentity ()) {
10571072 continue ;
10581073 }
1059- NestedField sourceField = table . schema () .findField (partitionField .sourceId ());
1074+ NestedField sourceField = scanSchema .findField (partitionField .sourceId ());
10601075 if (sourceField == null || !isSupportedPartitionValueType (
10611076 sourceField .type (), enableMappingVarbinary , enableMappingTimestampTz )) {
10621077 continue ;
10631078 }
1064- String columnName = table . schema (). findColumnName ( partitionField .sourceId ());
1079+ String columnName = topLevelSourceColumnName ( scanSchema , partitionField .sourceId ());
10651080 if (columnName != null ) {
10661081 partitionColumns .add (columnName );
10671082 }
@@ -1079,11 +1094,21 @@ public static List<String> getCommonIdentityPartitionColumns(Table table) {
10791094 return getCommonIdentityPartitionColumns (table , false , false );
10801095 }
10811096
1097+ public static List <String > getCommonIdentityPartitionColumns (Table table , Schema scanSchema ) {
1098+ return getCommonIdentityPartitionColumns (table , scanSchema , false , false );
1099+ }
1100+
10821101 public static List <String > getCommonIdentityPartitionColumns (Table table ,
10831102 boolean enableMappingVarbinary , boolean enableMappingTimestampTz ) {
1103+ return getCommonIdentityPartitionColumns (
1104+ table , table .schema (), enableMappingVarbinary , enableMappingTimestampTz );
1105+ }
1106+
1107+ public static List <String > getCommonIdentityPartitionColumns (Table table , Schema scanSchema ,
1108+ boolean enableMappingVarbinary , boolean enableMappingTimestampTz ) {
10841109 LinkedHashSet <Integer > commonSourceIds = new LinkedHashSet <>();
10851110 for (PartitionField field : table .spec ().fields ()) {
1086- NestedField sourceField = table . schema () .findField (field .sourceId ());
1111+ NestedField sourceField = scanSchema .findField (field .sourceId ());
10871112 if (field .transform ().isIdentity () && sourceField != null
10881113 && isSupportedPartitionValueType (
10891114 sourceField .type (), enableMappingVarbinary , enableMappingTimestampTz )) {
@@ -1098,19 +1123,35 @@ && isSupportedPartitionValueType(
10981123 commonSourceIds .retainAll (specIdentitySourceIds );
10991124 }
11001125 return commonSourceIds .stream ()
1101- .map (table . schema ():: findColumnName )
1126+ .map (sourceId -> topLevelSourceColumnName ( scanSchema , sourceId ) )
11021127 .filter (columnName -> columnName != null )
11031128 .collect (Collectors .toList ());
11041129 }
11051130
11061131 public static Map <String , String > getIdentityPartitionInfoMap (PartitionData partitionData ,
11071132 PartitionSpec partitionSpec , Table table , String timeZone ) {
1108- return getIdentityPartitionInfoMap (partitionData , partitionSpec , table , timeZone , false , false );
1133+ return getIdentityPartitionInfoMap (
1134+ partitionData , partitionSpec , table , timeZone , false , false );
1135+ }
1136+
1137+ public static Map <String , String > getIdentityPartitionInfoMap (
1138+ PartitionData partitionData , PartitionSpec partitionSpec , Schema scanSchema ,
1139+ String timeZone ) {
1140+ return getIdentityPartitionInfoMap (
1141+ partitionData , partitionSpec , scanSchema , timeZone , false , false );
11091142 }
11101143
11111144 public static Map <String , String > getIdentityPartitionInfoMap (PartitionData partitionData ,
11121145 PartitionSpec partitionSpec , Table table , String timeZone ,
11131146 boolean enableMappingVarbinary , boolean enableMappingTimestampTz ) {
1147+ return getIdentityPartitionInfoMap (
1148+ partitionData , partitionSpec , table .schema (), timeZone ,
1149+ enableMappingVarbinary , enableMappingTimestampTz );
1150+ }
1151+
1152+ public static Map <String , String > getIdentityPartitionInfoMap (PartitionData partitionData ,
1153+ PartitionSpec partitionSpec , Schema scanSchema , String timeZone ,
1154+ boolean enableMappingVarbinary , boolean enableMappingTimestampTz ) {
11141155 Map <String , String > partitionInfoMap = Maps .newLinkedHashMap ();
11151156 List <NestedField > fields = partitionData .getPartitionType ().asNestedType ().fields ();
11161157 List <PartitionField > partitionFields = partitionSpec .fields ();
@@ -1128,7 +1169,7 @@ public static Map<String, String> getIdentityPartitionInfoMap(PartitionData part
11281169 continue ;
11291170 }
11301171
1131- String columnName = table . schema (). findColumnName ( partitionField .sourceId ());
1172+ String columnName = topLevelSourceColumnName ( scanSchema , partitionField .sourceId ());
11321173 if (columnName == null ) {
11331174 continue ;
11341175 }
@@ -1143,6 +1184,11 @@ public static Map<String, String> getIdentityPartitionInfoMap(PartitionData part
11431184 return partitionInfoMap ;
11441185 }
11451186
1187+ private static String topLevelSourceColumnName (Schema schema , int sourceId ) {
1188+ NestedField field = schema .asStruct ().field (sourceId );
1189+ return field == null ? null : field .name ();
1190+ }
1191+
11461192 private static boolean isSupportedPartitionValueType (org .apache .iceberg .types .Type type ,
11471193 boolean enableMappingVarbinary , boolean enableMappingTimestampTz ) {
11481194 TypeID typeId = type .typeId ();
0 commit comments