@@ -1824,6 +1824,69 @@ public void testSchemaCarrierKeepsDroppedEqualityFieldDefault() throws Exception
18241824 IcebergUtils .getSerializedInitialDefaults (fields , false ).get (7 ));
18251825 }
18261826
1827+ @ Test
1828+ public void testSplitKeepsOldSpecIdentityValuesAfterEvolvingToUnpartitioned () throws Exception {
1829+ // A file written under identity(p) keeps p=7 only in its manifest partition metadata. Gating on
1830+ // the CURRENT spec drops that value once the default spec evolves to unpartitioned, and keying
1831+ // the partition-key classification off the columns common to all specs leaves BE reading p from
1832+ // a file that does not store it, so the column comes back NULL in both cases.
1833+ Schema schema = new Schema (
1834+ Types .NestedField .required (1 , "id" , Types .IntegerType .get ()),
1835+ Types .NestedField .required (2 , "p" , Types .IntegerType .get ()));
1836+ PartitionSpec spec = PartitionSpec .builderFor (schema ).identity ("p" ).build ();
1837+ String location = temporaryFolder .newFolder ("identity_evolved_table" ).toURI ().toString ();
1838+ Table table = new HadoopTables (new Configuration ()).create (schema , spec , location );
1839+ table .newFastAppend ()
1840+ .appendFile (DataFiles .builder (table .spec ())
1841+ .withPath (location + "data/p=7/old.parquet" )
1842+ .withFileSizeInBytes (1024L )
1843+ .withRecordCount (2L )
1844+ .withFormat (FileFormat .PARQUET )
1845+ .withPartitionPath ("p=7" )
1846+ .build ())
1847+ .commit ();
1848+ table .updateSpec ().removeField ("p" ).commit ();
1849+ Assert .assertTrue (table .spec ().isUnpartitioned ());
1850+
1851+ SessionVariable sessionVariable = new SessionVariable ();
1852+ sessionVariable .enableFileScannerV2 = true ;
1853+ TestIcebergScanNode node = new TestIcebergScanNode (sessionVariable );
1854+ setIcebergTable (node , table );
1855+ setPrivateField (node , "formatVersion" , 2 );
1856+ setPrivateField (node , "storagePropertiesMap" , Collections .emptyMap ());
1857+ setPrivateField (node , "partitionMapInfos" , new HashMap <>());
1858+ // Exactly what doInitialize computes for this table.
1859+ setPrivateField (node , "isPartitionedTable" , table .spec ().isPartitioned ());
1860+ setPrivateField (node , "hasPartitionedSpec" , IcebergUtils .hasPartitionedSpec (table ));
1861+
1862+ // p must stay a partition key even though the current spec no longer mentions it; otherwise BE
1863+ // ignores the split value and reads the (absent) physical column.
1864+ Assert .assertEquals (ImmutableList .of ("p" ), orderedPathPartitionKeys (node ));
1865+
1866+ FileScanTask task ;
1867+ try (CloseableIterable <FileScanTask > tasks = table .newScan ().planFiles ()) {
1868+ Iterator <FileScanTask > iterator = tasks .iterator ();
1869+ Assert .assertTrue (iterator .hasNext ());
1870+ task = iterator .next ();
1871+ }
1872+
1873+ IcebergSplit split = createIcebergSplit (node , task );
1874+ Assert .assertEquals (ImmutableMap .of ("p" , "7" ), split .getIcebergPartitionValues ());
1875+ Assert .assertEquals (Integer .valueOf (0 ), split .getPartitionSpecId ());
1876+ // A plain read does not project the row ID, so no row-ID partition JSON is generated.
1877+ Assert .assertNull (split .getPartitionDataJson ());
1878+
1879+ // What BE actually receives: p=7 as a columns-from-path constant for this range.
1880+ TFileRangeDesc rangeDesc = new TFileRangeDesc ();
1881+ setIcebergParams (node , rangeDesc , split );
1882+ Assert .assertEquals (ImmutableList .of ("p" ), rangeDesc .getColumnsFromPathKeys ());
1883+ Assert .assertEquals (ImmutableList .of ("7" ), rangeDesc .getColumnsFromPath ());
1884+
1885+ // Display parity: the CURRENT spec is unpartitioned, so the table still reports no scanned
1886+ // partitions and the batch-mode estimate stays at the unpartitioned default.
1887+ Assert .assertEquals (1 , node .numApproximateSplits ());
1888+ }
1889+
18271890 @ Test
18281891 public void testBatchSplitCarriesDroppedEqualitySchemaThroughThrift () throws Exception {
18291892 Types .NestedField id = Types .NestedField .required (1 , "id" , Types .LongType .get ());
@@ -1958,6 +2021,7 @@ public void testReadSplitsSkipPartitionJson() throws Exception {
19582021 node .addSlot (0 , new Column ("record_key" , Type .INT ));
19592022 setIcebergTable (node , table );
19602023 setPrivateField (node , "isPartitionedTable" , keepPartitioned );
2024+ setPrivateField (node , "hasPartitionedSpec" , IcebergUtils .hasPartitionedSpec (table ));
19612025 setPrivateField (node , "storagePropertiesMap" , Collections .emptyMap ());
19622026 setPrivateField (node , "formatVersion" , 2 );
19632027 setPrivateField (node , "partitionMapInfos" , new HashMap <>());
@@ -2043,6 +2107,7 @@ private void assertSplitAfterDroppingPartitionSourceColumn(boolean keepPartition
20432107 TestIcebergScanNode node = new TestIcebergScanNode (new SessionVariable ());
20442108 setIcebergTable (node , table );
20452109 setPrivateField (node , "isPartitionedTable" , keepPartitioned );
2110+ setPrivateField (node , "hasPartitionedSpec" , IcebergUtils .hasPartitionedSpec (table ));
20462111 setPrivateField (node , "storagePropertiesMap" , Collections .emptyMap ());
20472112 setPrivateField (node , "formatVersion" , 2 );
20482113 setPrivateField (node , "partitionMapInfos" , new HashMap <>());
@@ -2181,6 +2246,7 @@ private void assertDeleteSplitPartitionMetadata(Table table, SessionVariable ses
21812246 node .addSlot (0 , IcebergRowId .createHiddenColumn ());
21822247 setIcebergTable (node , table );
21832248 setPrivateField (node , "isPartitionedTable" , table .spec ().isPartitioned ());
2249+ setPrivateField (node , "hasPartitionedSpec" , IcebergUtils .hasPartitionedSpec (table ));
21842250 setPrivateField (node , "storagePropertiesMap" , Collections .emptyMap ());
21852251 setPrivateField (node , "formatVersion" , 2 );
21862252 setPrivateField (node , "partitionMapInfos" , new HashMap <>());
@@ -4097,6 +4163,13 @@ private static FileScanTask fileScanTask(String path, DeleteFile deleteFile) {
40974163 return task ;
40984164 }
40994165
4166+ @ SuppressWarnings ("unchecked" )
4167+ private static List <String > orderedPathPartitionKeys (IcebergScanNode node ) throws Exception {
4168+ Method method = IcebergScanNode .class .getDeclaredMethod ("getOrderedPathPartitionKeys" );
4169+ method .setAccessible (true );
4170+ return (List <String >) method .invoke (node );
4171+ }
4172+
41004173 private static IcebergSplit createIcebergSplit (IcebergScanNode node , FileScanTask task )
41014174 throws Exception {
41024175 Method method = IcebergScanNode .class .getDeclaredMethod ("createIcebergSplit" , FileScanTask .class );
0 commit comments