3535import org .apache .hudi .common .engine .HoodieLocalEngineContext ;
3636import org .apache .hudi .common .model .FileSlice ;
3737import org .apache .hudi .common .model .HoodieBaseFile ;
38+ import org .apache .hudi .common .model .HoodieLogFile ;
3839import org .apache .hudi .common .model .HoodieTableQueryType ;
3940import org .apache .hudi .common .table .HoodieTableConfig ;
4041import org .apache .hudi .common .table .HoodieTableMetaClient ;
@@ -253,6 +254,7 @@ private List<FileStatus> listStatusForSnapshotMode(JobConf job,
253254 partitionedFileSlices .values ()
254255 .stream ()
255256 .flatMap (Collection ::stream )
257+ .filter (fileSlice -> checkIfValidFileSlice (fileSlice ))
256258 .map (fileSlice -> createFileStatusUnchecked (fileSlice , fileIndex , virtualKeyInfoOpt ))
257259 .collect (Collectors .toList ())
258260 );
@@ -261,6 +263,20 @@ private List<FileStatus> listStatusForSnapshotMode(JobConf job,
261263 return targetFiles ;
262264 }
263265
266+ private boolean checkIfValidFileSlice (FileSlice fileSlice ) {
267+ Option <HoodieBaseFile > baseFileOpt = fileSlice .getBaseFile ();
268+ Option <HoodieLogFile > latestLogFileOpt = fileSlice .getLatestLogFile ();
269+
270+ if (baseFileOpt .isPresent ()) {
271+ return true ;
272+ } else if (latestLogFileOpt .isPresent ()) {
273+ // It happens when reading optimized query to mor.
274+ return false ;
275+ } else {
276+ throw new IllegalStateException ("Invalid state: base-file has to be present" );
277+ }
278+ }
279+
264280 private void validate (List <FileStatus > targetFiles , List <FileStatus > legacyFileStatuses ) {
265281 List <FileStatus > diff = CollectionUtils .diff (targetFiles , legacyFileStatuses );
266282 checkState (diff .isEmpty (), "Should be empty" );
0 commit comments