Class/Object

org.apache.spark.sql.execution

WholeStageCodegenExec

Related Docs: object WholeStageCodegenExec | package execution

Permalink

case class WholeStageCodegenExec(child: SparkPlan) extends SparkPlan with UnaryExecNode with CodegenSupport with Product with Serializable

WholeStageCodegen compile a subtree of plans that support codegen together into single Java function.

Here is the call graph of to generate Java source (plan A support codegen, but plan B does not):

WholeStageCodegen Plan A FakeInput Plan B

-> execute() | doExecute() ---------> inputRDDs() -------> inputRDDs() ------> execute() | +-----------------> produce() | doProduce() -------> produce() | doProduce() | doConsume() <--------- consume() | doConsume() <-------- consume()

SparkPlan A should override doProduce() and doConsume().

doCodeGen() will create a CodeGenContext, which will hold a list of variables for input, used to generated code for BoundReference.

Linear Supertypes
CodegenSupport, UnaryExecNode, SparkPlan, Serializable, Serializable, Logging, QueryPlan[SparkPlan], TreeNode[SparkPlan], Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. WholeStageCodegenExec
  2. CodegenSupport
  3. UnaryExecNode
  4. SparkPlan
  5. Serializable
  6. Serializable
  7. Logging
  8. QueryPlan
  9. TreeNode
  10. Product
  11. Equals
  12. AnyRef
  13. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new WholeStageCodegenExec(child: SparkPlan)

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. lazy val allAttributes: AttributeSeq

    Permalink
    Definition Classes
    QueryPlan
  5. def apply(number: Int): TreeNode[_]

    Permalink
    Definition Classes
    TreeNode
  6. def argString: String

    Permalink
    Definition Classes
    TreeNode
  7. def asCode: String

    Permalink
    Definition Classes
    TreeNode
  8. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  9. lazy val canonicalized: SparkPlan

    Permalink
    Attributes
    protected
    Definition Classes
    QueryPlan
  10. val child: SparkPlan

    Permalink
    Definition Classes
    WholeStageCodegenExecUnaryExecNode
  11. final def children: Seq[SparkPlan]

    Permalink
    Definition Classes
    UnaryExecNode → TreeNode
  12. lazy val cleanArgs: Seq[Any]

    Permalink
    Attributes
    protected
    Definition Classes
    QueryPlan
  13. def cleanExpression(e: Expression): Expression

    Permalink
    Attributes
    protected
    Definition Classes
    QueryPlan
  14. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  15. def collect[B](pf: PartialFunction[SparkPlan, B]): Seq[B]

    Permalink
    Definition Classes
    TreeNode
  16. def collectFirst[B](pf: PartialFunction[SparkPlan, B]): Option[B]

    Permalink
    Definition Classes
    TreeNode
  17. def collectLeaves(): Seq[SparkPlan]

    Permalink
    Definition Classes
    TreeNode
  18. lazy val constraints: ExpressionSet

    Permalink
    Definition Classes
    QueryPlan
  19. final def consume(ctx: CodegenContext, outputVars: Seq[ExprCode], row: String = null): String

    Permalink

    Consume the generated columns or row from current SparkPlan, call its parent's doConsume().

    Consume the generated columns or row from current SparkPlan, call its parent's doConsume().

    Definition Classes
    CodegenSupport
  20. lazy val containsChild: Set[TreeNode[_]]

    Permalink
    Definition Classes
    TreeNode
  21. def doCodeGen(): (CodegenContext, CodeAndComment)

    Permalink

    Generates code for this subtree.

    Generates code for this subtree.

    returns

    the tuple of the codegen context and the actual generated source.

  22. def doConsume(ctx: CodegenContext, input: Seq[ExprCode], row: ExprCode): String

    Permalink

    Generate the Java source code to process the rows from child SparkPlan.

    Generate the Java source code to process the rows from child SparkPlan.

    This should be override by subclass to support codegen.

    For example, Filter will generate the code like this:

    # code to evaluate the predicate expression, result is isNull1 and value2 if (isNull1 || !value2) continue; # call consume(), which will call parent.doConsume()

    Note: A plan can either consume the rows as UnsafeRow (row), or a list of variables (input).

    Definition Classes
    WholeStageCodegenExecCodegenSupport
  23. def doExecute(): RDD[InternalRow]

    Permalink

    Overridden by concrete implementations of SparkPlan.

    Overridden by concrete implementations of SparkPlan. Produces the result of the query as an RDD[InternalRow]

    Definition Classes
    WholeStageCodegenExecSparkPlan
  24. def doExecuteBroadcast[T](): Broadcast[T]

    Permalink

    Overridden by concrete implementations of SparkPlan.

    Overridden by concrete implementations of SparkPlan. Produces the result of the query as a broadcast variable.

    Attributes
    protected[org.apache.spark.sql]
    Definition Classes
    SparkPlan
  25. def doPrepare(): Unit

    Permalink

    Overridden by concrete implementations of SparkPlan.

    Overridden by concrete implementations of SparkPlan. It is guaranteed to run before any execute of SparkPlan. This is helpful if we want to set up some state before executing the query, e.g., BroadcastHashJoin uses it to broadcast asynchronously.

    Note: the prepare method has already walked down the tree, so the implementation doesn't need to call children's prepare methods.

    This will only be called once, protected by this.

    Attributes
    protected
    Definition Classes
    SparkPlan
  26. def doProduce(ctx: CodegenContext): String

    Permalink

    Generate the Java source code to process, should be overridden by subclass to support codegen.

    Generate the Java source code to process, should be overridden by subclass to support codegen.

    doProduce() usually generate the framework, for example, aggregation could generate this:

    if (!initialized) { # create a hash map, then build the aggregation hash map # call child.produce() initialized = true; } while (hashmap.hasNext()) { row = hashmap.next(); # build the aggregation results # create variables for results # call consume(), which will call parent.doConsume() if (shouldStop()) return; }

    Definition Classes
    WholeStageCodegenExecCodegenSupport
  27. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  28. def evaluateRequiredVariables(attributes: Seq[Attribute], variables: Seq[ExprCode], required: AttributeSet): String

    Permalink

    Returns source code to evaluate the variables for required attributes, and clear the code of evaluated variables, to prevent them to be evaluated twice.

    Returns source code to evaluate the variables for required attributes, and clear the code of evaluated variables, to prevent them to be evaluated twice.

    Attributes
    protected
    Definition Classes
    CodegenSupport
  29. def evaluateVariables(variables: Seq[ExprCode]): String

    Permalink

    Returns source code to evaluate all the variables, and clear the code of them, to prevent them to be evaluated twice.

    Returns source code to evaluate all the variables, and clear the code of them, to prevent them to be evaluated twice.

    Attributes
    protected
    Definition Classes
    CodegenSupport
  30. final def execute(): RDD[InternalRow]

    Permalink

    Returns the result of this query as an RDD[InternalRow] by delegating to doExecute after preparations.

    Returns the result of this query as an RDD[InternalRow] by delegating to doExecute after preparations.

    Concrete implementations of SparkPlan should override doExecute.

    Definition Classes
    SparkPlan
  31. final def executeBroadcast[T](): Broadcast[T]

    Permalink

    Returns the result of this query as a broadcast variable by delegating to doExecuteBroadcast after preparations.

    Returns the result of this query as a broadcast variable by delegating to doExecuteBroadcast after preparations.

    Concrete implementations of SparkPlan should override doExecuteBroadcast.

    Definition Classes
    SparkPlan
  32. def executeCollect(): Array[InternalRow]

    Permalink

    Runs this query returning the result as an array.

    Runs this query returning the result as an array.

    Definition Classes
    SparkPlan
  33. def executeCollectPublic(): Array[Row]

    Permalink

    Runs this query returning the result as an array, using external Row format.

    Runs this query returning the result as an array, using external Row format.

    Definition Classes
    SparkPlan
  34. final def executeQuery[T](query: ⇒ T): T

    Permalink

    Execute a query after preparing the query and adding query plan information to created RDDs for visualization.

    Execute a query after preparing the query and adding query plan information to created RDDs for visualization.

    Attributes
    protected
    Definition Classes
    SparkPlan
  35. def executeTake(n: Int): Array[InternalRow]

    Permalink

    Runs this query returning the first n rows as an array.

    Runs this query returning the first n rows as an array.

    This is modeled after RDD.take but never runs any job locally on the driver.

    Definition Classes
    SparkPlan
  36. def executeToIterator(): Iterator[InternalRow]

    Permalink

    Runs this query returning the result as an iterator of InternalRow.

    Runs this query returning the result as an iterator of InternalRow.

    Note: this will trigger multiple jobs (one for each partition).

    Definition Classes
    SparkPlan
  37. final def expressions: Seq[Expression]

    Permalink
    Definition Classes
    QueryPlan
  38. def fastEquals(other: TreeNode[_]): Boolean

    Permalink
    Definition Classes
    TreeNode
  39. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  40. def find(f: (SparkPlan) ⇒ Boolean): Option[SparkPlan]

    Permalink
    Definition Classes
    TreeNode
  41. def flatMap[A](f: (SparkPlan) ⇒ TraversableOnce[A]): Seq[A]

    Permalink
    Definition Classes
    TreeNode
  42. def foreach(f: (SparkPlan) ⇒ Unit): Unit

    Permalink
    Definition Classes
    TreeNode
  43. def foreachUp(f: (SparkPlan) ⇒ Unit): Unit

    Permalink
    Definition Classes
    TreeNode
  44. def generateTreeString(depth: Int, lastChildren: Seq[Boolean], builder: StringBuilder, verbose: Boolean, prefix: String = ""): StringBuilder

    Permalink
    Definition Classes
    WholeStageCodegenExec → TreeNode
  45. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  46. def getRelevantConstraints(constraints: Set[Expression]): Set[Expression]

    Permalink
    Attributes
    protected
    Definition Classes
    QueryPlan
  47. def hashCode(): Int

    Permalink
    Definition Classes
    TreeNode → AnyRef → Any
  48. def initializeLogIfNecessary(isInterpreter: Boolean): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  49. def innerChildren: Seq[QueryPlan[_]]

    Permalink
    Attributes
    protected
    Definition Classes
    QueryPlan → TreeNode
  50. def inputRDDs(): Seq[RDD[InternalRow]]

    Permalink

    Returns all the RDDs of InternalRow which generates the input rows.

    Returns all the RDDs of InternalRow which generates the input rows.

    Note: right now we support up to two RDDs.

    Definition Classes
    WholeStageCodegenExecCodegenSupport
  51. def inputSet: AttributeSet

    Permalink
    Definition Classes
    QueryPlan
  52. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  53. def isTraceEnabled(): Boolean

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  54. def jsonFields: List[JField]

    Permalink
    Attributes
    protected
    Definition Classes
    TreeNode
  55. def log: Logger

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  56. def logDebug(msg: ⇒ String, throwable: Throwable): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  57. def logDebug(msg: ⇒ String): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  58. def logError(msg: ⇒ String, throwable: Throwable): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  59. def logError(msg: ⇒ String): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  60. def logInfo(msg: ⇒ String, throwable: Throwable): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  61. def logInfo(msg: ⇒ String): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  62. def logName: String

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  63. def logTrace(msg: ⇒ String, throwable: Throwable): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  64. def logTrace(msg: ⇒ String): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  65. def logWarning(msg: ⇒ String, throwable: Throwable): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  66. def logWarning(msg: ⇒ String): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  67. def longMetric(name: String): SQLMetric

    Permalink

    Return a LongSQLMetric according to the name.

    Return a LongSQLMetric according to the name.

    Definition Classes
    SparkPlan
  68. def makeCopy(newArgs: Array[AnyRef]): SparkPlan

    Permalink

    Overridden make copy also propagates sqlContext to copied plan.

    Overridden make copy also propagates sqlContext to copied plan.

    Definition Classes
    SparkPlan → TreeNode
  69. def map[A](f: (SparkPlan) ⇒ A): Seq[A]

    Permalink
    Definition Classes
    TreeNode
  70. def mapChildren(f: (SparkPlan) ⇒ SparkPlan): SparkPlan

    Permalink
    Definition Classes
    TreeNode
  71. def mapExpressions(f: (Expression) ⇒ Expression): WholeStageCodegenExec.this.type

    Permalink
    Definition Classes
    QueryPlan
  72. def mapProductIterator[B](f: (Any) ⇒ B)(implicit arg0: ClassTag[B]): Array[B]

    Permalink
    Attributes
    protected
    Definition Classes
    TreeNode
  73. def metadata: Map[String, String]

    Permalink

    Return all metadata that describes more details of this SparkPlan.

    Return all metadata that describes more details of this SparkPlan.

    Definition Classes
    SparkPlan
  74. def metricTerm(ctx: CodegenContext, name: String): String

    Permalink

    Creates a metric using the specified name.

    Creates a metric using the specified name.

    returns

    name of the variable representing the metric

    Definition Classes
    CodegenSupport
  75. lazy val metrics: Map[String, SQLMetric]

    Permalink

    Return all metrics containing metrics of this SparkPlan.

    Return all metrics containing metrics of this SparkPlan.

    Definition Classes
    WholeStageCodegenExecSparkPlan
  76. def missingInput: AttributeSet

    Permalink
    Definition Classes
    QueryPlan
  77. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  78. def newMutableProjection(expressions: Seq[Expression], inputSchema: Seq[Attribute], useSubexprElimination: Boolean = false): MutableProjection

    Permalink
    Attributes
    protected
    Definition Classes
    SparkPlan
  79. def newNaturalAscendingOrdering(dataTypes: Seq[DataType]): Ordering[InternalRow]

    Permalink

    Creates a row ordering for the given schema, in natural ascending order.

    Creates a row ordering for the given schema, in natural ascending order.

    Attributes
    protected
    Definition Classes
    SparkPlan
  80. def newOrdering(order: Seq[SortOrder], inputSchema: Seq[Attribute]): Ordering[InternalRow]

    Permalink
    Attributes
    protected
    Definition Classes
    SparkPlan
  81. def newPredicate(expression: Expression, inputSchema: Seq[Attribute]): Predicate

    Permalink
    Attributes
    protected
    Definition Classes
    SparkPlan
  82. def nodeName: String

    Permalink
    Definition Classes
    TreeNode
  83. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  84. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  85. def numberedTreeString: String

    Permalink
    Definition Classes
    TreeNode
  86. val origin: Origin

    Permalink
    Definition Classes
    TreeNode
  87. def otherCopyArgs: Seq[AnyRef]

    Permalink
    Attributes
    protected
    Definition Classes
    TreeNode
  88. def output: Seq[Attribute]

    Permalink
    Definition Classes
    WholeStageCodegenExec → QueryPlan
  89. def outputOrdering: Seq[SortOrder]

    Permalink

    Specifies how data is ordered in each partition.

    Specifies how data is ordered in each partition.

    Definition Classes
    WholeStageCodegenExecSparkPlan
  90. def outputPartitioning: Partitioning

    Permalink

    Specifies how data is partitioned across different nodes in the cluster.

    Specifies how data is partitioned across different nodes in the cluster.

    Definition Classes
    WholeStageCodegenExecSparkPlan
  91. def outputSet: AttributeSet

    Permalink
    Definition Classes
    QueryPlan
  92. def p(number: Int): SparkPlan

    Permalink
    Definition Classes
    TreeNode
  93. var parent: CodegenSupport

    Permalink

    Which SparkPlan is calling produce() of this one.

    Which SparkPlan is calling produce() of this one. It's itself for the first SparkPlan.

    Attributes
    protected
    Definition Classes
    CodegenSupport
  94. final def prepare(): Unit

    Permalink

    Prepare a SparkPlan for execution.

    Prepare a SparkPlan for execution. It's idempotent.

    Definition Classes
    SparkPlan
  95. def prepareSubqueries(): Unit

    Permalink

    Finds scalar subquery expressions in this plan node and starts evaluating them.

    Finds scalar subquery expressions in this plan node and starts evaluating them.

    Attributes
    protected
    Definition Classes
    SparkPlan
  96. def prettyJson: String

    Permalink
    Definition Classes
    TreeNode
  97. def printSchema(): Unit

    Permalink
    Definition Classes
    QueryPlan
  98. final def produce(ctx: CodegenContext, parent: CodegenSupport): String

    Permalink

    Returns Java source code to process the rows from input RDD.

    Returns Java source code to process the rows from input RDD.

    Definition Classes
    CodegenSupport
  99. def producedAttributes: AttributeSet

    Permalink
    Definition Classes
    QueryPlan
  100. def references: AttributeSet

    Permalink
    Definition Classes
    QueryPlan
  101. def requiredChildDistribution: Seq[Distribution]

    Permalink

    Specifies any partition requirements on the input data for this operator.

    Specifies any partition requirements on the input data for this operator.

    Definition Classes
    SparkPlan
  102. def requiredChildOrdering: Seq[Seq[SortOrder]]

    Permalink

    Specifies sort order for each partition requirements on the input data for this operator.

    Specifies sort order for each partition requirements on the input data for this operator.

    Definition Classes
    SparkPlan
  103. def resetMetrics(): Unit

    Permalink

    Reset all the metrics.

    Reset all the metrics.

    Definition Classes
    SparkPlan
  104. def sameResult(plan: SparkPlan): Boolean

    Permalink
    Definition Classes
    QueryPlan
  105. lazy val schema: StructType

    Permalink
    Definition Classes
    QueryPlan
  106. def schemaString: String

    Permalink
    Definition Classes
    QueryPlan
  107. def simpleString: String

    Permalink
    Definition Classes
    QueryPlan → TreeNode
  108. def sparkContext: SparkContext

    Permalink
    Attributes
    protected
    Definition Classes
    SparkPlan
  109. final val sqlContext: SQLContext

    Permalink

    A handle to the SQL Context that was used to create this plan.

    A handle to the SQL Context that was used to create this plan. Since many operators need access to the sqlContext for RDD operations or configuration this field is automatically populated by the query planning infrastructure.

    Definition Classes
    SparkPlan
  110. def statePrefix: String

    Permalink
    Attributes
    protected
    Definition Classes
    QueryPlan
  111. def stringArgs: Iterator[Any]

    Permalink
    Attributes
    protected
    Definition Classes
    TreeNode
  112. val subexpressionEliminationEnabled: Boolean

    Permalink
    Definition Classes
    SparkPlan
  113. def subqueries: Seq[SparkPlan]

    Permalink
    Definition Classes
    QueryPlan
  114. def supportCodegen: Boolean

    Permalink

    Whether this SparkPlan support whole stage codegen or not.

    Whether this SparkPlan support whole stage codegen or not.

    Definition Classes
    CodegenSupport
  115. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  116. def toJSON: String

    Permalink
    Definition Classes
    TreeNode
  117. def toString(): String

    Permalink
    Definition Classes
    TreeNode → AnyRef → Any
  118. def transform(rule: PartialFunction[SparkPlan, SparkPlan]): SparkPlan

    Permalink
    Definition Classes
    TreeNode
  119. def transformAllExpressions(rule: PartialFunction[Expression, Expression]): WholeStageCodegenExec.this.type

    Permalink
    Definition Classes
    QueryPlan
  120. def transformDown(rule: PartialFunction[SparkPlan, SparkPlan]): SparkPlan

    Permalink
    Definition Classes
    TreeNode
  121. def transformExpressions(rule: PartialFunction[Expression, Expression]): WholeStageCodegenExec.this.type

    Permalink
    Definition Classes
    QueryPlan
  122. def transformExpressionsDown(rule: PartialFunction[Expression, Expression]): WholeStageCodegenExec.this.type

    Permalink
    Definition Classes
    QueryPlan
  123. def transformExpressionsUp(rule: PartialFunction[Expression, Expression]): WholeStageCodegenExec.this.type

    Permalink
    Definition Classes
    QueryPlan
  124. def transformUp(rule: PartialFunction[SparkPlan, SparkPlan]): SparkPlan

    Permalink
    Definition Classes
    TreeNode
  125. def treeString(verbose: Boolean): String

    Permalink
    Definition Classes
    TreeNode
  126. def treeString: String

    Permalink
    Definition Classes
    TreeNode
  127. def usedInputs: AttributeSet

    Permalink

    The subset of inputSet those should be evaluated before this plan.

    The subset of inputSet those should be evaluated before this plan.

    We will use this to insert some code to access those columns that are actually used by current plan before calling doConsume().

    Definition Classes
    CodegenSupport
  128. def validConstraints: Set[Expression]

    Permalink
    Attributes
    protected
    Definition Classes
    QueryPlan
  129. def verboseString: String

    Permalink
    Definition Classes
    QueryPlan → TreeNode
  130. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  131. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  132. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  133. def waitForSubqueries(): Unit

    Permalink

    Blocks the thread until all subqueries finish evaluation and update the results.

    Blocks the thread until all subqueries finish evaluation and update the results.

    Attributes
    protected
    Definition Classes
    SparkPlan
  134. def withNewChildren(newChildren: Seq[SparkPlan]): SparkPlan

    Permalink
    Definition Classes
    TreeNode

Inherited from CodegenSupport

Inherited from UnaryExecNode

Inherited from SparkPlan

Inherited from Serializable

Inherited from Serializable

Inherited from Logging

Inherited from QueryPlan[SparkPlan]

Inherited from TreeNode[SparkPlan]

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped