|
18 | 18 | package org.apache.spark.sql.internal |
19 | 19 |
|
20 | 20 | import org.apache.spark.sql.{QueryTest, Row, SparkSession, SQLContext} |
| 21 | +import org.apache.spark.sql.execution.WholeStageCodegenExec |
21 | 22 | import org.apache.spark.sql.test.{SharedSQLContext, TestSQLContext} |
22 | 23 |
|
23 | 24 | class SQLConfSuite extends QueryTest with SharedSQLContext { |
@@ -219,4 +220,32 @@ class SQLConfSuite extends QueryTest with SharedSQLContext { |
219 | 220 | } |
220 | 221 | } |
221 | 222 |
|
| 223 | + test("MAX_CASES_BRANCHES") { |
| 224 | + withTable("tab1") { |
| 225 | + spark.range(10).write.saveAsTable("tab1") |
| 226 | + val sql_one_branch_caseWhen = "SELECT CASE WHEN id = 1 THEN 1 END FROM tab1" |
| 227 | + val sql_two_branch_caseWhen = "SELECT CASE WHEN id = 1 THEN 1 ELSE 0 END FROM tab1" |
| 228 | + |
| 229 | + withSQLConf(SQLConf.MAX_CASES_BRANCHES.key -> "0") { |
| 230 | + assert(!sql(sql_one_branch_caseWhen) |
| 231 | + .queryExecution.executedPlan.isInstanceOf[WholeStageCodegenExec]) |
| 232 | + assert(!sql(sql_two_branch_caseWhen) |
| 233 | + .queryExecution.executedPlan.isInstanceOf[WholeStageCodegenExec]) |
| 234 | + } |
| 235 | + |
| 236 | + withSQLConf(SQLConf.MAX_CASES_BRANCHES.key -> "1") { |
| 237 | + assert(sql(sql_one_branch_caseWhen) |
| 238 | + .queryExecution.executedPlan.isInstanceOf[WholeStageCodegenExec]) |
| 239 | + assert(!sql(sql_two_branch_caseWhen) |
| 240 | + .queryExecution.executedPlan.isInstanceOf[WholeStageCodegenExec]) |
| 241 | + } |
| 242 | + |
| 243 | + withSQLConf(SQLConf.MAX_CASES_BRANCHES.key -> "2") { |
| 244 | + assert(sql(sql_one_branch_caseWhen) |
| 245 | + .queryExecution.executedPlan.isInstanceOf[WholeStageCodegenExec]) |
| 246 | + assert(sql(sql_two_branch_caseWhen) |
| 247 | + .queryExecution.executedPlan.isInstanceOf[WholeStageCodegenExec]) |
| 248 | + } |
| 249 | + } |
| 250 | + } |
222 | 251 | } |
0 commit comments