-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26450][SQL] Avoid rebuilding map of schema for every column in projection #23392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
6b66711
a9dbbec
67a943a
3362744
306e0a5
a25b59c
b977d3e
1497d3a
777c5b4
fbd6787
686e7b5
b1afb3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ import org.apache.spark.rdd.RDD | |
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.errors._ | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.expressions.BindReferences.bindReferences | ||
| import org.apache.spark.sql.catalyst.expressions.aggregate._ | ||
| import org.apache.spark.sql.catalyst.expressions.codegen._ | ||
| import org.apache.spark.sql.catalyst.expressions.codegen.Block._ | ||
|
|
@@ -199,15 +200,12 @@ case class HashAggregateExec( | |
| val (resultVars, genResult) = if (modes.contains(Final) || modes.contains(Complete)) { | ||
| // evaluate aggregate results | ||
| ctx.currentVars = bufVars | ||
| val aggResults = functions.map(_.evaluateExpression).map { e => | ||
| BindReferences.bindReference(e, aggregateBufferAttributes).genCode(ctx) | ||
| } | ||
| val aggResults = bindReferences(functions.map(_.evaluateExpression), | ||
| aggregateBufferAttributes).map(_.genCode(ctx)) | ||
| val evaluateAggResults = evaluateVariables(aggResults) | ||
| // evaluate result expressions | ||
| ctx.currentVars = aggResults | ||
| val resultVars = resultExpressions.map { e => | ||
| BindReferences.bindReference(e, aggregateAttributes).genCode(ctx) | ||
| } | ||
| val resultVars = bindReferences(resultExpressions, aggregateAttributes).map(_.genCode(ctx)) | ||
| (resultVars, s""" | ||
| |$evaluateAggResults | ||
| |${evaluateVariables(resultVars)} | ||
|
|
@@ -264,7 +262,7 @@ case class HashAggregateExec( | |
| } | ||
| } | ||
| ctx.currentVars = bufVars ++ input | ||
| val boundUpdateExpr = updateExpr.map(BindReferences.bindReference(_, inputAttrs)) | ||
| val boundUpdateExpr = bindReferences(updateExpr, inputAttrs) | ||
| val subExprs = ctx.subexpressionEliminationForWholeStageCodegen(boundUpdateExpr) | ||
| val effectiveCodes = subExprs.codes.mkString("\n") | ||
| val aggVals = ctx.withSubExprEliminationExprs(subExprs.states) { | ||
|
|
@@ -456,16 +454,14 @@ case class HashAggregateExec( | |
| val evaluateBufferVars = evaluateVariables(bufferVars) | ||
| // evaluate the aggregation result | ||
| ctx.currentVars = bufferVars | ||
| val aggResults = declFunctions.map(_.evaluateExpression).map { e => | ||
| BindReferences.bindReference(e, aggregateBufferAttributes).genCode(ctx) | ||
| } | ||
| val aggResults = bindReferences(declFunctions.map(_.evaluateExpression), | ||
|
||
| aggregateBufferAttributes).map(_.genCode(ctx)) | ||
| val evaluateAggResults = evaluateVariables(aggResults) | ||
| // generate the final result | ||
| ctx.currentVars = keyVars ++ aggResults | ||
| val inputAttrs = groupingAttributes ++ aggregateAttributes | ||
| val resultVars = resultExpressions.map { e => | ||
| BindReferences.bindReference(e, inputAttrs).genCode(ctx) | ||
| } | ||
| val resultVars = bindReferences[Expression](resultExpressions, | ||
|
||
| inputAttrs).map(_.genCode(ctx)) | ||
| s""" | ||
| $evaluateKeyVars | ||
| $evaluateBufferVars | ||
|
|
@@ -494,9 +490,8 @@ case class HashAggregateExec( | |
|
|
||
| ctx.currentVars = keyVars ++ resultBufferVars | ||
| val inputAttrs = resultExpressions.map(_.toAttribute) | ||
| val resultVars = resultExpressions.map { e => | ||
| BindReferences.bindReference(e, inputAttrs).genCode(ctx) | ||
| } | ||
| val resultVars = bindReferences[Expression](resultExpressions, | ||
|
||
| inputAttrs).map(_.genCode(ctx)) | ||
| s""" | ||
| $evaluateKeyVars | ||
| $evaluateResultBufferVars | ||
|
|
@@ -506,9 +501,8 @@ case class HashAggregateExec( | |
| // generate result based on grouping key | ||
| ctx.INPUT_ROW = keyTerm | ||
| ctx.currentVars = null | ||
| val eval = resultExpressions.map{ e => | ||
| BindReferences.bindReference(e, groupingAttributes).genCode(ctx) | ||
| } | ||
| val eval = bindReferences[Expression](resultExpressions, | ||
|
||
| groupingAttributes).map(_.genCode(ctx)) | ||
| consume(ctx, eval) | ||
| } | ||
| ctx.addNewFunction(funcName, | ||
|
|
@@ -730,9 +724,9 @@ case class HashAggregateExec( | |
| private def doConsumeWithKeys(ctx: CodegenContext, input: Seq[ExprCode]): String = { | ||
| // create grouping key | ||
| val unsafeRowKeyCode = GenerateUnsafeProjection.createCode( | ||
| ctx, groupingExpressions.map(e => BindReferences.bindReference[Expression](e, child.output))) | ||
| ctx, bindReferences[Expression](groupingExpressions, child.output)) | ||
| val fastRowKeys = ctx.generateExpressions( | ||
| groupingExpressions.map(e => BindReferences.bindReference[Expression](e, child.output))) | ||
| bindReferences[Expression](groupingExpressions, child.output)) | ||
| val unsafeRowKeys = unsafeRowKeyCode.value | ||
| val unsafeRowBuffer = ctx.freshName("unsafeRowAggBuffer") | ||
| val fastRowBuffer = ctx.freshName("fastAggBuffer") | ||
|
|
@@ -825,7 +819,7 @@ case class HashAggregateExec( | |
|
|
||
| val updateRowInRegularHashMap: String = { | ||
| ctx.INPUT_ROW = unsafeRowBuffer | ||
| val boundUpdateExpr = updateExpr.map(BindReferences.bindReference(_, inputAttr)) | ||
| val boundUpdateExpr = bindReferences(updateExpr, inputAttr) | ||
| val subExprs = ctx.subexpressionEliminationForWholeStageCodegen(boundUpdateExpr) | ||
| val effectiveCodes = subExprs.codes.mkString("\n") | ||
| val unsafeRowBufferEvals = ctx.withSubExprEliminationExprs(subExprs.states) { | ||
|
|
@@ -849,7 +843,7 @@ case class HashAggregateExec( | |
| if (isFastHashMapEnabled) { | ||
| if (isVectorizedHashMapEnabled) { | ||
| ctx.INPUT_ROW = fastRowBuffer | ||
| val boundUpdateExpr = updateExpr.map(BindReferences.bindReference(_, inputAttr)) | ||
| val boundUpdateExpr = bindReferences(updateExpr, inputAttr) | ||
| val subExprs = ctx.subexpressionEliminationForWholeStageCodegen(boundUpdateExpr) | ||
| val effectiveCodes = subExprs.codes.mkString("\n") | ||
| val fastRowEvals = ctx.withSubExprEliminationExprs(subExprs.states) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ import org.apache.spark.sql.catalyst.InternalRow | |
| import org.apache.spark.sql.catalyst.catalog.BucketSpec | ||
| import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.expressions.BindReferences.bindReferences | ||
| import org.apache.spark.sql.catalyst.plans.physical.HashPartitioning | ||
| import org.apache.spark.sql.catalyst.util.{CaseInsensitiveMap, DateTimeUtils} | ||
| import org.apache.spark.sql.execution.{SortExec, SparkPlan, SQLExecution} | ||
|
|
@@ -145,9 +146,9 @@ object FileFormatWriter extends Logging { | |
| // SPARK-21165: the `requiredOrdering` is based on the attributes from analyzed plan, and | ||
| // the physical plan may have different attribute ids due to optimizer removing some | ||
| // aliases. Here we bind the expression ahead to avoid potential attribute ids mismatch. | ||
| val orderingExpr = requiredOrdering | ||
| .map(SortOrder(_, Ascending)) | ||
| .map(BindReferences.bindReference(_, outputSpec.outputColumns)) | ||
| val orderingExpr = bindReferences( | ||
| requiredOrdering.map(SortOrder(_, Ascending)), | ||
| outputSpec.outputColumns) | ||
|
||
| SortExec( | ||
| orderingExpr, | ||
| global = false, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
functions.map(_.evaluateExpression),in the next line