Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ case class OptimizeMetadataOnlyQuery(catalog: SessionCatalog) extends Rule[Logic
case a: AttributeReference =>
a.withName(relation.output.find(_.semanticEquals(a)).get.name)
}
}
Copy link
Member

@maropu maropu May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you filter out this unsupported case outside replaceTableScanWithPartitionMetadata(I think this filtering is not related to normalization)? e.g., in https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/OptimizeMetadataOnlyQuery.scala#L53-L55

}.filterNot(SubqueryExpression.hasSubquery)

child transform {
case plan if plan eq relation =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ class OptimizeMetadataOnlyQuerySuite extends QueryTest with SharedSparkSession {
"select partcol2, min(partcol1) from srcpart where partcol1 = 0 group by partcol2",
"select max(c1) from (select partcol1 + 1 as c1 from srcpart where partcol1 = 0) t")

testMetadataOnly(
"SPARK-31590 Metadata-only queries should not include subquery in partition filters",
"""
|SELECT partcol1, MAX(partcol2) AS partcol2
|FROM srcpart
|WHERE partcol1 = (
| SELECT MAX(partcol1)
| FROM srcpart
|)
|AND partcol2 = 'even'
|GROUP BY partcol1
|""".stripMargin
)

testNotMetadataOnly(
"Don't optimize metadata only query for non-partition columns",
"select col1 from srcpart group by col1",
Expand Down