Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ trait PredicateHelper extends AliasHelper with Logging {
def findExpressionAndTrackLineageDown(
exp: Expression,
plan: LogicalPlan): Option[(Expression, LogicalPlan)] = {
if (exp.references.isEmpty) return None

plan match {
case p: Project =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,34 @@ abstract class DynamicPartitionPruningSuiteBase
}
}
}

test("SPARK-38570: Fix incorrect DynamicPartitionPruning caused by Literal") {
withSQLConf(SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key -> "true") {
val df = sql(
"""
|SELECT f.store_id,
| f.date_id,
| s.state_province
|FROM (SELECT 4 AS store_id,
| date_id,
| product_id
| FROM fact_sk
| WHERE date_id >= 1300
| UNION ALL
| SELECT 5 AS store_id,
| date_id,
| product_id
| FROM fact_stats
| WHERE date_id <= 1000) f
|JOIN dim_store s
|ON f.store_id = s.store_id
|WHERE s.country = 'US'
|""".stripMargin)

checkPartitionPruningPredicate(df, false, withBroadcast = false)
checkAnswer(df, Row(4, 1300, "California") :: Row(5, 1000, "Texas") :: Nil)
}
}
}

abstract class DynamicPartitionPruningDataSourceSuiteBase
Expand Down