-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
996ff4c
commit dbaabba
Showing
16 changed files
with
148 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
gluten-core/src/main/scala/io/glutenproject/extension/RewriteTypedImperativeAggregate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.glutenproject.extension | ||
|
||
import io.glutenproject.backendsapi.BackendsApiManager | ||
import io.glutenproject.utils.PullOutProjectHelper | ||
|
||
import org.apache.spark.sql.catalyst.expressions.AttributeReference | ||
import org.apache.spark.sql.catalyst.expressions.aggregate._ | ||
import org.apache.spark.sql.catalyst.rules.Rule | ||
import org.apache.spark.sql.execution.SparkPlan | ||
import org.apache.spark.sql.execution.aggregate.BaseAggregateExec | ||
|
||
object RewriteTypedImperativeAggregate extends Rule[SparkPlan] with PullOutProjectHelper { | ||
private lazy val shouldRewriteTypedImperativeAggregate = | ||
BackendsApiManager.getSettings.shouldRewriteTypedImperativeAggregate() | ||
|
||
def shouldRewrite(ae: AggregateExpression): Boolean = { | ||
ae.aggregateFunction match { | ||
case _: CollectList | _: CollectSet => | ||
ae.mode match { | ||
case Partial | PartialMerge => true | ||
case _ => false | ||
} | ||
case _ => false | ||
} | ||
} | ||
|
||
override def apply(plan: SparkPlan): SparkPlan = { | ||
if (!shouldRewriteTypedImperativeAggregate) { | ||
return plan | ||
} | ||
|
||
plan match { | ||
case agg: BaseAggregateExec if agg.aggregateExpressions.exists(shouldRewrite) => | ||
val exprMap = agg.aggregateExpressions | ||
.filter(shouldRewrite) | ||
.map(ae => ae.aggregateFunction.inputAggBufferAttributes.head -> ae) | ||
.toMap | ||
val newResultExpressions = agg.resultExpressions.map { | ||
case attr: AttributeReference => | ||
exprMap | ||
.get(attr) | ||
.map { | ||
ae => | ||
attr.copy(dataType = ae.aggregateFunction.dataType)( | ||
exprId = attr.exprId, | ||
qualifier = attr.qualifier | ||
) | ||
} | ||
.getOrElse(attr) | ||
case other => other | ||
} | ||
copyBaseAggregateExec(agg)(newResultExpressions = newResultExpressions) | ||
|
||
case _ => plan | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters