3030import java .util .concurrent .TimeUnit ;
3131import org .apache .iceberg .BaseTable ;
3232import org .apache .iceberg .HasTableOperations ;
33+ import org .apache .iceberg .PartitionStatisticsFile ;
3334import org .apache .iceberg .RewriteTablePathUtil ;
3435import org .apache .iceberg .RewriteTablePathUtil .RewriteResult ;
3536import org .apache .iceberg .Snapshot ;
@@ -144,8 +145,9 @@ private void validateInputs() {
144145 "Source prefix cannot be the same as target prefix (%s)" , sourcePrefix ));
145146 }
146147
147- validateAndSetEndVersion ();
148- validateAndSetStartVersion ();
148+ TableMetadata tableMetadata = ((HasTableOperations ) table ).operations ().current ();
149+ validateAndSetEndVersion (tableMetadata );
150+ validateAndSetStartVersion (tableMetadata );
149151
150152 if (stagingDir == null ) {
151153 stagingDir =
@@ -158,9 +160,7 @@ private void validateInputs() {
158160 }
159161 }
160162
161- private void validateAndSetEndVersion () {
162- TableMetadata tableMetadata = ((HasTableOperations ) table ).operations ().current ();
163-
163+ private void validateAndSetEndVersion (TableMetadata tableMetadata ) {
164164 if (endVersionName == null ) {
165165 Objects .requireNonNull (
166166 tableMetadata .metadataFileLocation (), "Metadata file location should not be null" );
@@ -170,9 +170,7 @@ private void validateAndSetEndVersion() {
170170 }
171171 }
172172
173- private void validateAndSetStartVersion () {
174- TableMetadata tableMetadata = ((HasTableOperations ) table ).operations ().current ();
175-
173+ private void validateAndSetStartVersion (TableMetadata tableMetadata ) {
176174 if (startVersionName != null ) {
177175 this .startVersionName = validateVersion (tableMetadata , startVersionName );
178176 }
@@ -184,9 +182,12 @@ private String validateVersion(TableMetadata tableMetadata, String versionFileNa
184182 versionFile = tableMetadata .metadataFileLocation ();
185183 }
186184
187- for (MetadataLogEntry log : tableMetadata .previousFiles ()) {
188- if (versionInFilePath (log .file (), versionFileName )) {
189- versionFile = log .file ();
185+ if (versionFile == null ) {
186+ for (MetadataLogEntry log : tableMetadata .previousFiles ()) {
187+ if (versionInFilePath (log .file (), versionFileName )) {
188+ versionFile = log .file ();
189+ break ;
190+ }
190191 }
191192 }
192193
@@ -216,8 +217,8 @@ private String rebuildMetadata() {
216217 TableMetadata endMetadata =
217218 ((HasTableOperations ) newStaticTable (endVersionName , table .io ())).operations ().current ();
218219
219- if ( endMetadata .partitionStatisticsFiles () != null
220- && !endMetadata . partitionStatisticsFiles () .isEmpty ()) {
220+ List < PartitionStatisticsFile > partitionStats = endMetadata .partitionStatisticsFiles ();
221+ if ( partitionStats != null && !partitionStats .isEmpty ()) {
221222 throw new IllegalArgumentException ("Partition statistics files are not supported yet." );
222223 }
223224
@@ -301,7 +302,7 @@ private Set<Pair<String, String>> statsFileCopyPlan(List<StatisticsFile> beforeS
301302 StatisticsFile before = beforeStats .get (i );
302303 StatisticsFile after = afterStats .get (i );
303304 if (before .fileSizeInBytes () != after .fileSizeInBytes ()) {
304- throw new IllegalArgumentException ("Before and after path rewrite, statistic files count should be same" );
305+ throw new IllegalArgumentException ("Before and after path rewrite, statistic files size should be same" );
305306 }
306307 result .add (Pair .of (before .path (), after .path ()));
307308 }
0 commit comments