-
Notifications
You must be signed in to change notification settings - Fork 455
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
4e0aab0
commit 47ece74
Showing
14 changed files
with
301 additions
and
10 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
43 changes: 43 additions & 0 deletions
43
...it/src/main/scala/org/apache/gluten/extension/columnar/rewrite/ProjectColumnPruning.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,43 @@ | ||
/* | ||
* 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 org.apache.gluten.extension.columnar.rewrite | ||
|
||
import org.apache.spark.sql.execution.{ProjectExec, SparkPlan, UnaryExecNode} | ||
|
||
/** | ||
* After applying the PullOutPreProject rule, there may be some projects that contain columns not | ||
* consumed by the parent. These columns will be removed by this rewrite rule. | ||
*/ | ||
object ProjectColumnPruning extends RewriteSingleNode { | ||
override def isRewritable(plan: SparkPlan): Boolean = { | ||
RewriteEligibility.isRewritable(plan) | ||
} | ||
|
||
override def rewrite(plan: SparkPlan): SparkPlan = plan match { | ||
case parent: UnaryExecNode if parent.child.isInstanceOf[ProjectExec] => | ||
val project = parent.child.asInstanceOf[ProjectExec] | ||
val unusedAttribute = project.outputSet -- parent.references | ||
|
||
if (unusedAttribute.nonEmpty) { | ||
val newProject = project.copy(projectList = project.projectList.diff(unusedAttribute.toSeq)) | ||
parent.withNewChildren(Seq(newProject)) | ||
} else { | ||
parent | ||
} | ||
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
57 changes: 57 additions & 0 deletions
57
...ark32/src/test/scala/org/apache/spark/sql/extension/GlutenExtensionRewriteRuleSuite.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,57 @@ | ||
/* | ||
* 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 org.apache.spark.sql.extension | ||
|
||
import org.apache.gluten.execution.ProjectExecTransformer | ||
|
||
import org.apache.spark.SparkConf | ||
import org.apache.spark.sql.GlutenSQLTestsTrait | ||
|
||
class GlutenExtensionRewriteRuleSuite extends GlutenSQLTestsTrait { | ||
|
||
override def sparkConf: SparkConf = { | ||
super.sparkConf | ||
.set("spark.sql.adaptive.enabled", "false") | ||
} | ||
|
||
testGluten("GLUTEN-8183 - Pruning unused column in project") { | ||
val query = | ||
""" | ||
|SELECT | ||
| max(n1), | ||
| max(n2), | ||
| sum(IF(n1 + n2 + n3 % 2 = 0, 1, 0)) | ||
|FROM | ||
| ( | ||
| SELECT | ||
| id + 1 AS n1, | ||
| id + 2 AS n2, | ||
| IF(id % 2 = 0, id + 3, id + 4) AS n3 | ||
| FROM | ||
| RANGE(10) | ||
| ) | ||
|""".stripMargin | ||
|
||
val df = sql(query) | ||
assert( | ||
getExecutedPlan(df).exists { | ||
case project: ProjectExecTransformer => project.projectList.length == 3 | ||
case _ => false | ||
} | ||
) | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
...ark33/src/test/scala/org/apache/spark/sql/extension/GlutenExtensionRewriteRuleSuite.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,57 @@ | ||
/* | ||
* 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 org.apache.spark.sql.extension | ||
|
||
import org.apache.gluten.execution.ProjectExecTransformer | ||
|
||
import org.apache.spark.SparkConf | ||
import org.apache.spark.sql.GlutenSQLTestsTrait | ||
|
||
class GlutenExtensionRewriteRuleSuite extends GlutenSQLTestsTrait { | ||
|
||
override def sparkConf: SparkConf = { | ||
super.sparkConf | ||
.set("spark.sql.adaptive.enabled", "false") | ||
} | ||
|
||
testGluten("GLUTEN-8183 - Pruning unused column in project") { | ||
val query = | ||
""" | ||
|SELECT | ||
| max(n1), | ||
| max(n2), | ||
| sum(IF(n1 + n2 + n3 % 2 = 0, 1, 0)) | ||
|FROM | ||
| ( | ||
| SELECT | ||
| id + 1 AS n1, | ||
| id + 2 AS n2, | ||
| IF(id % 2 = 0, id + 3, id + 4) AS n3 | ||
| FROM | ||
| RANGE(10) | ||
| ) | ||
|""".stripMargin | ||
|
||
val df = sql(query) | ||
assert( | ||
getExecutedPlan(df).exists { | ||
case project: ProjectExecTransformer => project.projectList.length == 3 | ||
case _ => false | ||
} | ||
) | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
...ark34/src/test/scala/org/apache/spark/sql/extension/GlutenExtensionRewriteRuleSuite.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,57 @@ | ||
/* | ||
* 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 org.apache.spark.sql.extension | ||
|
||
import org.apache.gluten.execution.ProjectExecTransformer | ||
|
||
import org.apache.spark.SparkConf | ||
import org.apache.spark.sql.GlutenSQLTestsTrait | ||
|
||
class GlutenExtensionRewriteRuleSuite extends GlutenSQLTestsTrait { | ||
|
||
override def sparkConf: SparkConf = { | ||
super.sparkConf | ||
.set("spark.sql.adaptive.enabled", "false") | ||
} | ||
|
||
testGluten("GLUTEN-8183 - Pruning unused column in project") { | ||
val query = | ||
""" | ||
|SELECT | ||
| max(n1), | ||
| max(n2), | ||
| sum(IF(n1 + n2 + n3 % 2 = 0, 1, 0)) | ||
|FROM | ||
| ( | ||
| SELECT | ||
| id + 1 AS n1, | ||
| id + 2 AS n2, | ||
| IF(id % 2 = 0, id + 3, id + 4) AS n3 | ||
| FROM | ||
| RANGE(10) | ||
| ) | ||
|""".stripMargin | ||
|
||
val df = sql(query) | ||
assert( | ||
getExecutedPlan(df).exists { | ||
case project: ProjectExecTransformer => project.projectList.length == 3 | ||
case _ => false | ||
} | ||
) | ||
} | ||
} |
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
Oops, something went wrong.