diff --git a/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/MergeOnReadIncrementalRelationV2.scala b/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/MergeOnReadIncrementalRelationV2.scala index c79f95ccda8bb..6222cd217f935 100644 --- a/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/MergeOnReadIncrementalRelationV2.scala +++ b/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/MergeOnReadIncrementalRelationV2.scala @@ -205,7 +205,15 @@ trait HoodieIncrementalRelationV2Trait extends HoodieBaseRelation { .analyze() protected lazy val includedCommits: immutable.Seq[HoodieInstant] = queryContext.getInstants.asScala.toList - protected lazy val commitsMetadata = includedCommits.map(getCommitMetadata(_, super.timeline)).asJava + + protected lazy val commitsMetadata = includedCommits.map( + i => { + if (queryContext.getArchivedInstants.contains(i)) { + getCommitMetadata(i, queryContext.getArchivedTimeline) + } else { + getCommitMetadata(i, queryContext.getActiveTimeline) + } + }).asJava protected lazy val affectedFilesInCommits: java.util.List[StoragePathInfo] = { listAffectedFilesForCommits(conf, metaClient.getBasePath, commitsMetadata)