Skip to content

Commit

Permalink
Add inputSet, references to QueryPlan. Improve tree string with a pre…
Browse files Browse the repository at this point in the history
…fix to denote invalid or unresolved nodes.
  • Loading branch information
marmbrus committed Oct 5, 2014
1 parent fbeab54 commit 8c69303
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ abstract class QueryPlan[PlanType <: TreeNode[PlanType]] extends TreeNode[PlanTy
*/
def outputSet: AttributeSet = AttributeSet(output)

/**
* All Attributes that appear in expressions from this operator. Note that this set does not
* include attributes that are implicitly referenced by being passed through to the output tuple.
*/
def references: AttributeSet = AttributeSet(expressions.flatMap(_.references))

/**
* The set of all attributes that are input to this operator by its children.
*/
def inputSet: AttributeSet =
AttributeSet(children.flatMap(_.asInstanceOf[QueryPlan[PlanType]].output))

/**
* Attributes that are referenced by expressions but not provided by this nodes children.
* Subclasses should override this method if they produce attributes internally as it is used by
* assertions designed to prevent the construction of invalid plans.
*/
def missingInput: AttributeSet = references -- inputSet

/**
* Runs [[transform]] with `rule` on all expressions present in this query operator.
* Users should not expect a specific directionality. If a specific directionality is needed,
Expand Down Expand Up @@ -132,4 +151,8 @@ abstract class QueryPlan[PlanType <: TreeNode[PlanType]] extends TreeNode[PlanTy

/** Prints out the schema in the tree format */
def printSchema(): Unit = println(schemaString)

protected def statePrefix = if (missingInput.nonEmpty && children.nonEmpty) "!" else ""

override def simpleString = statePrefix + super.simpleString
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
sizeInBytes = children.map(_.statistics).map(_.sizeInBytes).product)
}

/**
* Returns the set of attributes that this node takes as
* input from its children.
*/
lazy val inputSet: AttributeSet = AttributeSet(children.flatMap(_.output))

/**
* Returns true if this expression and all its children have been resolved to a specific schema
* and false if it still contains any unresolved placeholders. Implementations of LogicalPlan
Expand All @@ -68,6 +62,8 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
*/
lazy val resolved: Boolean = !expressions.exists(!_.resolved) && childrenResolved

override protected def statePrefix = if (!resolved) "'" else super.statePrefix

/**
* Returns true if all its children of this query plan have been resolved.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ case class Aggregate(
child: LogicalPlan)
extends UnaryNode {

/** The set of all AttributeReferences required for this aggregation. */
def references =
AttributeSet(
groupingExpressions.flatMap(_.references) ++ aggregateExpressions.flatMap(_.references))

override def output = aggregateExpressions.map(_.toAttribute)
}

Expand Down

0 comments on commit 8c69303

Please sign in to comment.