LATERAL VIEW (OUTER)?
generatorFunctionName (arg1, arg2, ...)
tblName
AS? col1, col2, ...
Generator — Catalyst Expressions that Generate Zero Or More Rows
Generator
is a contract for Catalyst expressions that can produce zero or more rows given a single input row.
Generator
supports whole-stage codegen when not CodegenFallback by default.
Name | Description | ||
---|---|---|---|
|
|||
|
|||
|
Corresponds to |
||
|
|||
|
|||
Represents an unresolved generator. Created when
|
|||
|
Used exclusively in the now-deprecated |
Note
|
You can only have one generator per select clause that is enforced by ExtractGenerator in
If you want to have more than one generator in a structured query you should use
|
Generator Contract
package org.apache.spark.sql.catalyst.expressions
trait Generator extends Expression {
// only required methods that have no implementation
def elementSchema: StructType
def eval(input: InternalRow): TraversableOnce[InternalRow]
}
Method | Description |
---|---|
StructType of the elements generated |
|
Used when… |
Explode Generator Unary Expression
Explode
is a unary expression that produces a sequence of records for each value in the array or map.
Explode
is a result of executing explode
function (in SQL and functions)
scala> sql("SELECT explode(array(10,20))").explain
== Physical Plan ==
Generate explode([10,20]), false, false, [col#68]
+- Scan OneRowRelation[]
scala> sql("SELECT explode(array(10,20))").queryExecution.optimizedPlan.expressions(0)
res18: org.apache.spark.sql.catalyst.expressions.Expression = explode([10,20])
val arrayDF = Seq(Array(0,1)).toDF("array")
scala> arrayDF.withColumn("num", explode('array)).explain
== Physical Plan ==
Generate explode(array#93), true, false, [array#93, num#102]
+- LocalTableScan [array#93]
PosExplode
Caution
|
FIXME |
ExplodeBase Unary Expression
ExplodeBase
is the base class for Explode and PosExplode.
ExplodeBase
is UnaryExpression and Generator with CodegenFallback.