diff --git a/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/SparkHoodieTableFileIndex.scala b/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/SparkHoodieTableFileIndex.scala index 677d5d270763c..e99cc72adae9f 100644 --- a/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/SparkHoodieTableFileIndex.scala +++ b/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/SparkHoodieTableFileIndex.scala @@ -299,7 +299,9 @@ class SparkHoodieTableFileIndex(spark: SparkSession, // prefix to try to reduce the scope of the required file-listing val relativePartitionPathPrefix = composeRelativePartitionPath(staticPartitionColumnNameValuePairs) - if (staticPartitionColumnNameValuePairs.length == partitionColumnNames.length) { + if (!metaClient.getFs.exists(new Path(getBasePath, relativePartitionPathPrefix))) { + Seq() + } else if (staticPartitionColumnNameValuePairs.length == partitionColumnNames.length) { // In case composed partition path is complete, we can return it directly avoiding extra listing operation Seq(new PartitionPath(relativePartitionPathPrefix, staticPartitionColumnNameValuePairs.map(_._2.asInstanceOf[AnyRef]).toArray)) } else { diff --git a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala index e69819fb6f4e5..ed73940186d5f 100644 --- a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala +++ b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala @@ -519,7 +519,12 @@ class TestHoodieFileIndex extends HoodieSparkClientTestBase with ScalaAssertionS EqualTo(attribute("region_code"), literal("1"))), "dt = '2023/01/01' and region_code = '1'", enablePartitionPathPrefixAnalysis, - Seq(("1", "2023/01/01"))) + Seq(("1", "2023/01/01"))), + // no partition matched + (Seq(EqualTo(attribute("region_code"), literal("0"))), + "region_code = '0'", + enablePartitionPathPrefixAnalysis, + Seq()) ) testCases.foreach(testCase => {