Skip to content

Commit

Permalink
Fix nested expression
Browse files Browse the repository at this point in the history
Signed-off-by: Karen Feng <karen.feng@databricks.com>
  • Loading branch information
karenfeng committed Feb 27, 2021
1 parent 80beda8 commit e1719d3
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -990,17 +990,18 @@ class Analyzer(override val catalogManager: CatalogManager)

private def getMetadataAttributes(plan: LogicalPlan): Seq[Attribute] = {
lazy val childMetadataOutput = plan.children.flatMap(_.metadataOutput)
plan.expressions.collect {
plan.expressions.flatMap(_.collect {
case a: Attribute if a.isMetadataCol => a
case a: Attribute if childMetadataOutput.exists(_.exprId == a.exprId) =>
childMetadataOutput.find(_.exprId == a.exprId).get
}
})
}

private def hasMetadataCol(plan: LogicalPlan): Boolean = {
lazy val childMetadataOutput = plan.children.flatMap(_.metadataOutput)
plan.expressions.exists(_.find {
case a: Attribute => a.isMetadataCol || childMetadataOutput.exists(_.exprId == a.exprId)
case a: Attribute =>
a.isMetadataCol || childMetadataOutput.exists(_.exprId == a.exprId)
case _ => false
}.isDefined)
}
Expand All @@ -1016,9 +1017,7 @@ class Analyzer(override val catalogManager: CatalogManager)
def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperatorsUp {
case node if node.children.nonEmpty && node.resolved && hasMetadataCol(node) =>
val inputAttrs = AttributeSet(node.children.flatMap(_.output))
val metaCols = getMetadataAttributes(node).flatMap(_.collect {
case a: Attribute if a.isMetadataCol && !inputAttrs.contains(a) => a
})
val metaCols = getMetadataAttributes(node).filterNot(inputAttrs.contains)
if (metaCols.isEmpty) {
node
} else {
Expand Down

0 comments on commit e1719d3

Please sign in to comment.