Skip to content
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

[SPARK-44236][SQL] Disable WholeStageCodegen when set spark.sql.codegen.factoryMode to NO_CODEGEN #41779

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ abstract class CodeGeneratorWithInterpretedFallback[IN, OUT] extends Logging {

def createObject(in: IN): OUT = {
// We are allowed to choose codegen-only or no-codegen modes if under tests.
val config = SQLConf.get.getConf(SQLConf.CODEGEN_FACTORY_MODE)
val fallbackMode = CodegenObjectFactoryMode.withName(config)
val fallbackMode = CodegenObjectFactoryMode.withName(SQLConf.get.codegenFactoryMode)

fallbackMode match {
case CodegenObjectFactoryMode.CODEGEN_ONLY =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4641,6 +4641,8 @@ class SQLConf extends Serializable with Logging {

def codegenFallback: Boolean = getConf(CODEGEN_FALLBACK)

def codegenFactoryMode: String = getConf(CODEGEN_FACTORY_MODE)

def codegenComments: Boolean = getConf(StaticSQLConf.CODEGEN_COMMENTS)

def loggingMaxLinesForCodegen: Int = getConf(CODEGEN_LOGGING_MAX_LINES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ trait CodegenInterpretedPlanTest extends PlanTest {
super.test(testName + " (codegen path)", testTags: _*)(
withSQLConf(SQLConf.CODEGEN_FACTORY_MODE.key -> codegenMode) { testFun })(pos)
super.test(testName + " (interpreted path)", testTags: _*)(
withSQLConf(SQLConf.CODEGEN_FACTORY_MODE.key -> interpretedMode) {
withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "false") { testFun }})(pos)
withSQLConf(SQLConf.CODEGEN_FACTORY_MODE.key -> interpretedMode) { testFun })(pos)
}

protected def testFallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,8 @@ case class CollapseCodegenStages(
}

def apply(plan: SparkPlan): SparkPlan = {
if (conf.wholeStageEnabled) {
if (conf.wholeStageEnabled && CodegenObjectFactoryMode.withName(conf.codegenFactoryMode)
!= CodegenObjectFactoryMode.NO_CODEGEN) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cloud-fan Could you look at this, please.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @cloud-fan Can you take a look this, thanks.

insertWholeStageCodegen(plan)
} else {
plan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.execution

import org.apache.spark.sql.{Dataset, QueryTest, Row, SaveMode}
import org.apache.spark.sql.catalyst.expressions.CodegenObjectFactoryMode
import org.apache.spark.sql.catalyst.expressions.codegen.{ByteCodeStats, CodeAndComment, CodeGenerator}
import org.apache.spark.sql.execution.adaptive.DisableAdaptiveExecutionSuite
import org.apache.spark.sql.execution.aggregate.{HashAggregateExec, SortAggregateExec}
Expand Down Expand Up @@ -182,6 +183,16 @@ class WholeStageCodegenSuite extends QueryTest with SharedSparkSession
Seq(Row(0, 0, 0), Row(1, 1, 1), Row(2, 2, 2), Row(3, 3, 3), Row(4, 4, 4)))
}

test("SPARK-44236: disable WholeStageCodegen when set spark.sql.codegen.factoryMode is " +
"NO_CODEGEN") {
withSQLConf(SQLConf.CODEGEN_FACTORY_MODE.key -> CodegenObjectFactoryMode.NO_CODEGEN.toString) {
val df = spark.range(10).select($"id" + 1)
val plan = df.queryExecution.executedPlan
assert(!plan.exists(_.isInstanceOf[WholeStageCodegenExec]))
checkAnswer(df, 1L to 10L map { i => Row(i) })
}
}

test("Full Outer ShuffledHashJoin and SortMergeJoin should be included in WholeStageCodegen") {
val df1 = spark.range(5).select($"id".as("k1"))
val df2 = spark.range(10).select($"id".as("k2"))
Expand Down