Skip to content
Open
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 @@ -520,9 +520,41 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]]
def subqueries: Seq[PlanType] = _subqueries()

private val _subqueries = new TransientBestEffortLazyVal(() =>
expressions.filter(_.containsPattern(PLAN_EXPRESSION)).flatMap(_.collect {
case e: PlanExpression[_] => e.plan.asInstanceOf[PlanType]
})
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I understand, the earlier logic did not return None in case there were any subqueries regardless of the plantype. Now we do have a chance of empty sequence to be returned right? If so, should we not have UTs for that.

{
val queryPlanBaseClass = classOf[QueryPlan[_]]

def directChildQueryPlanClass(clazz: Class[_]): Option[Class[_]] = {
var current = clazz
while (current != null && queryPlanBaseClass.isAssignableFrom(current)) {
val parent = current.getSuperclass
if (parent == queryPlanBaseClass) {
return Some(current)
}
current = parent
}
None
}

val baseQueryPlanClass = directChildQueryPlanClass(getClass)

val rawSubqueries = expressions
.filter(_.containsPattern(PLAN_EXPRESSION))
.flatMap(_.collect {
case planExpression: PlanExpression[_] =>
planExpression.plan
})

baseQueryPlanClass match {
case Some(baseClass) =>
rawSubqueries.collect {
case subquery
if directChildQueryPlanClass(subquery.getClass).contains(baseClass) =>
subquery.asInstanceOf[PlanType]
}
case None =>
Seq.empty
}
}
)

/**
Expand Down