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-26262][SQL] Runs SQLQueryTestSuite on mixed config sets: WHOLESTAGE_CODEGEN_ENABLED and CODEGEN_FACTORY_MODE #23213

Closed
wants to merge 5 commits into from

Conversation

maropu
Copy link
Member

@maropu maropu commented Dec 4, 2018

What changes were proposed in this pull request?

For better test coverage, this pr proposed to use the 4 mixed config sets of WHOLESTAGE_CODEGEN_ENABLED and CODEGEN_FACTORY_MODE when running SQLQueryTestSuite:

  1. WHOLESTAGE_CODEGEN_ENABLED=true, CODEGEN_FACTORY_MODE=CODEGEN_ONLY
  2. WHOLESTAGE_CODEGEN_ENABLED=false, CODEGEN_FACTORY_MODE=CODEGEN_ONLY
  3. WHOLESTAGE_CODEGEN_ENABLED=true, CODEGEN_FACTORY_MODE=NO_CODEGEN
  4. WHOLESTAGE_CODEGEN_ENABLED=false, CODEGEN_FACTORY_MODE=NO_CODEGEN

This pr also moved some existing tests into ExplainSuite because explain output results are different between codegen and interpreter modes.

How was this patch tested?

Existing tests.

@SparkQA
Copy link

SparkQA commented Dec 4, 2018

Test build #99646 has finished for PR 23213 at commit 2ced0ca.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member Author

maropu commented Dec 4, 2018

cc: @cloud-fan @mgaido91

}
}

test("optimized plan should show the rewritten aggregate expression") {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move them to ExplainSuite?

Copy link
Member Author

Choose a reason for hiding this comment

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

all the tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

all the explain related tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

Copy link
Member

Choose a reason for hiding this comment

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

Please update the PR description too.

Copy link
Member

Choose a reason for hiding this comment

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

+1 for @viirya 's comment. We need to update the title and description of PR and JIRA.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated! Thanks, guys!

@mgaido91
Copy link
Contributor

mgaido91 commented Dec 4, 2018

just a question, why didn't we introduce something like what was done in SPARK-24562? I see that these are configs which are valid for all queries, so using what was done in SPARK-24562 is not a good idea, but something similar (eg a file with all the config sets to use)?

val codegenConfigSets = Array(CODEGEN_ONLY, NO_CODEGEN).map {
case codegenFactoryMode =>
Array(SQLConf.CODEGEN_FACTORY_MODE.key -> codegenFactoryMode.toString)
val codegenConfigSets = Array(("false", "NO_CODEGEN"), ("true", "CODEGEN_ONLY")).map {
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we test all the combinations? e.g. wholeStage=on, codegen=off

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

Copy link
Member

Choose a reason for hiding this comment

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

will this increase too much test time?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will check the time later, too.

@maropu
Copy link
Member Author

maropu commented Dec 4, 2018

yea, its similar, but I personally think its orthogonal to SPARK-24562. This pr only targets a default config set for codegen-only and interpreter mode tests.

@mgaido91
Copy link
Contributor

mgaido91 commented Dec 4, 2018

I personally think its orthogonal to SPARK-24562.

yes I agree. I am just asking if it makes sense to create a framework like that. Now it is only about codegen, but in the future we may want to add more configs. What do you think?

@cloud-fan
Copy link
Contributor

We should create such a framework when we need to have per-file config settings for testing.

@SparkQA
Copy link

SparkQA commented Dec 4, 2018

Test build #99661 has finished for PR 23213 at commit 3ef5e3e.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 4, 2018

Test build #99663 has finished for PR 23213 at commit 57eec69.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 4, 2018

Test build #99662 has finished for PR 23213 at commit 0305a05.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

// plan should show the rewritten aggregate expression.
val df = sql("SELECT k, every(v), some(v), any(v) FROM test_agg GROUP BY k")
checkKeywordsExistsInExplain(df,
"Aggregate [k#x], [k#x, min(v#x) AS every(v)#x, max(v#x) AS some(v)#x, " +
Copy link
Member

Choose a reason for hiding this comment

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

Since extended=false in line 33, the test suite only compares with Physical Plan. Maybe, did you change line 33 in your codebase?

Copy link
Member

@dongjoon-hyun dongjoon-hyun Dec 4, 2018

Choose a reason for hiding this comment

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

The other two failures fail with the same reason.

Copy link
Member Author

@maropu maropu Dec 5, 2018

Choose a reason for hiding this comment

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

yea, you're right... I forgot to set true at extended in explain...

@maropu maropu changed the title [SPARK-26262][SQL] Run SQLQueryTestSuite with WHOLESTAGE_CODEGEN_ENABLED=false [SPARK-26262][SQL] Runs SQLQueryTestSuite on mixed config sets: WHOLESTAGE_CODEGEN_ENABLED and CODEGEN_FACTORY_MODE Dec 5, 2018
@SparkQA
Copy link

SparkQA commented Dec 5, 2018

Test build #99692 has finished for PR 23213 at commit 808af50.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

do you know how long SQLQueryTestSuite takes? We are making it longer by 4 times here, so better to know the overhead.

@maropu
Copy link
Member Author

maropu commented Dec 5, 2018

I'm looking into that now ;) Just give me more time to check.

@maropu
Copy link
Member Author

maropu commented Dec 5, 2018

yea, it seemed it was longer by ~4 times;

23:25:43.880 WARN org.apache.spark.sql.SQLQueryTestSuite: 
=== Codegen/Interpreter Time Metrics ===
Total time: 602.64531157 seconds

Configs                                                                       Run Time                             

spark.sql.codegen.wholeStage=true,spark.sql.codegen.factoryMode=NO_CODEGEN    156414789416                                   
spark.sql.codegen.wholeStage=false,spark.sql.codegen.factoryMode=CODEGEN_ONLY 138343055840                                   
spark.sql.codegen.wholeStage=true,spark.sql.codegen.factoryMode=CODEGEN_ONLY  171905020550                                   
spark.sql.codegen.wholeStage=false,spark.sql.codegen.factoryMode=NO_CODEGEN   135982445764  

7a69e0b

@cloud-fan
Copy link
Contributor

that's a lot of time...

Can we think more about the combination of codegen and wholeStage? When we turn on whole stage codegen but turn off codegen, what will happen?

@maropu
Copy link
Member Author

maropu commented Dec 5, 2018

Sorry, my bad; it was longer than the current master by ~2 times. That's because the current master has already run two config set patterns (wholeStage=true,factoryMode=CODEGEN_ONLY and wholeStage=true,factoryMode=NO_CODEGEN) in SQLQueryTestSuite. The second test run (wholeStage=true,factoryMode=NO_CODEGEN) was introduced in my previous pr (#22512).

IMHO two config set patterns below could cover most code paths in Spark?

  • wholeStage=true, factoryMode=CODEGEN_ONLY
  • wholeStage=false, factoryMode=NO_CODEGEN

In this case, there is little change in the test time;

// the current master
=== Codegen/Interpreter Time Metrics ===
Total time: 358.584989321 seconds

Configs                                                                      Run Time                             
spark.sql.codegen.wholeStage=true,spark.sql.codegen.factoryMode=NO_CODEGEN   165961038511                                   
spark.sql.codegen.wholeStage=true,spark.sql.codegen.factoryMode=CODEGEN_ONLY 192623950810  

// with this pr
=== Codegen/Interpreter Time Metrics ===
Total time: 345.468455247 seconds

Configs                                                                      Run Time                             
spark.sql.codegen.wholeStage=false,spark.sql.codegen.factoryMode=NO_CODEGEN  148895478870    
spark.sql.codegen.wholeStage=true,spark.sql.codegen.factoryMode=CODEGEN_ONLY 196572976377                                   

WDYT?

@mgaido91
Copy link
Contributor

mgaido91 commented Dec 5, 2018

Yes, I am wondering too: which is the difference between:
spark.sql.codegen.wholeStage=false,spark.sql.codegen.factoryMode=NO_CODEGEN and spark.sql.codegen.wholeStage=true,spark.sql.codegen.factoryMode=NO_CODEGEN?

@cloud-fan
Copy link
Contributor

how about wholeStage=false, factoryMode=CODE_ONLY? I think it's different from wholeStage=false, factoryMode=NO_CODEGEN.

@maropu
Copy link
Member Author

maropu commented Dec 5, 2018

yea, I think they're not totally the same..., but I'm not sure that the test run (wholeStage=false, factoryMode=CODE_ONLY) is worth the time cost.

@cloud-fan
Copy link
Contributor

But whole stage codegen will not test GenerateUnsafeProject, GenerateMutableProject, etc., right?

@cloud-fan
Copy link
Contributor

If we look at test coverage, wholeStage=false, factoryMode=CODE_ONLY will go through code paths that wholeStageCodegen doesn't cover. Or did I miss something?

@SparkQA
Copy link

SparkQA commented Dec 6, 2018

Test build #99750 has finished for PR 23213 at commit a9c108f.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member Author

maropu commented Dec 6, 2018

retest this please

@SparkQA
Copy link

SparkQA commented Dec 6, 2018

Test build #99756 has finished for PR 23213 at commit a9c108f.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Retest this please.

@mgaido91
Copy link
Contributor

mgaido91 commented Dec 6, 2018

@maropu I'd say so, but I am still not sure what (if there is one) is the difference between wholeStage=false,sactoryMode=NO_CODEGEN and wholeStage=true,factoryMode=NO_CODEGEN. wholeStage=true,factoryMode=NO_CODEGEN doesn't make much sense IMHO. Could you please check what that runs?

@SparkQA
Copy link

SparkQA commented Dec 6, 2018

Test build #99762 has finished for PR 23213 at commit a9c108f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

these 3 combinations LGTM.

@SparkQA
Copy link

SparkQA commented Dec 10, 2018

Test build #99933 has finished for PR 23213 at commit a9c108f.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Dec 11, 2018

Test build #99942 has finished for PR 23213 at commit a9c108f.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Retest this please.

@HyukjinKwon
Copy link
Member

HyukjinKwon commented Dec 11, 2018

Ah, I had the same question as #23213 (comment). It would be good to update PR description :-).

@cloud-fan
Copy link
Contributor

when wholeStageCogen is on, there is no way to avoid codegen, so codegenFactoryMode doesn't make difference.

@viirya
Copy link
Member

viirya commented Dec 11, 2018

I think wholeStageCodegen doesn't disallow using those objects in interpreted mode. The objects can be in interpreted mode if it rolls back from codegen in case of compilation error.

@SparkQA
Copy link

SparkQA commented Dec 11, 2018

Test build #99945 has finished for PR 23213 at commit a9c108f.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member

retest this please

@cloud-fan
Copy link
Contributor

I think wholeStageCodegen doesn't disallow using those objects in interpreted mode. The objects can be in interpreted mode if it rolls back from codegen in case of compilation error.

But the test coverage is the same, right? If wholeStageCodege falls back, we are testing the same thing as turning off wholeStageCodegen

@viirya
Copy link
Member

viirya commented Dec 11, 2018

Isn't it possibly that wholeStageCodege doesn't falls back but codegen.factoryMode falls back, and vice verse? The falling back of factoryMode is happened at individual codegen generator.

@cloud-fan
Copy link
Contributor

The definition of "fallback" is different in wholeStageCodegen. It's effectively turning off wholeStageCodegen. Depending on the factoryMode, it might further fallbacks to interpreted execution, or normal codegen.

// note: this is not a robust way to split queries using semicolon, but works for now.
val queries = code.mkString("\n").split("(?<=[^\\\\]);").map(_.trim).filter(_ != "").toSeq

// When we are regenerating the golden files, we don't need to set any config as they
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about this. Imagine a case which is failing without setting a config for instance: I think we should pick one config set (any is fine) instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Imagine a case which is failing without setting a config for instance

We will check the result for all different configs, and test will fail, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

We will check the result for all different configs

For all different configs specified there doesn't mean without setting that config at all. For instance, let's imagine that we add a config for throwing an exception when a decimal overflows (with this behavior being the default): in the current tests, we can just add the config value to "do not throw an exception" for all the config sets which are present there. After this patch, that wouldn't work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently this test framework requires all the cases return the same result(without config and with any combination of configs). Did I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think only with any combination of configs is true, not without config.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know which test case leverages this feature? I'm a little surprised that we allow tests without configs have different behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

no, I think there is none as of now (this feature is not widely adopted...), but I think it is a case which can happen in the future (as in the example above, which may really be a case if we go on with the creating of a SQL strict mode)

Copy link
Contributor

Choose a reason for hiding this comment

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

If we do need to test the SQL strict mode, I think we need to adopt SPARK-24562 then.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean in general, in the current condition, there is no way you can successfully run the tests if the default value of a config produces (for any reason) an output different from some other values and we want to test only the non-default values. It may not be a problem but I think anyway this is a limitation which we can easily avoid by adding here the SETs for the first config set if any. So I see no reason why not to do that, which is safer IMHO.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's easier to reason about the test if we require it to always produce the same result without config and with any combination of configs.

If no tests depend on it, I'd like to not bother about it and keep it as it was. We already clear configs with generating result: https://github.com/apache/spark/pull/23213/files#diff-432455394ca50800d5de508861984ca5L157

@mgaido91
Copy link
Contributor

Thanks for the kind answer @cloud-fan. Then yes, I am +1 for the 3 configs suggested in #23213 (comment).

@SparkQA
Copy link

SparkQA commented Dec 11, 2018

Test build #99959 has finished for PR 23213 at commit a9c108f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 11, 2018

Test build #99957 has finished for PR 23213 at commit a9c108f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@kiszk
Copy link
Member

kiszk commented Dec 19, 2018

LGTM with the 3 configs in #23213 (comment).

@kiszk
Copy link
Member

kiszk commented Dec 19, 2018

retest this please

@SparkQA
Copy link

SparkQA commented Dec 19, 2018

Test build #100313 has finished for PR 23213 at commit a9c108f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@asfgit asfgit closed this in 61c443a Dec 20, 2018
holdenk pushed a commit to holdenk/spark that referenced this pull request Jan 5, 2019
…STAGE_CODEGEN_ENABLED and CODEGEN_FACTORY_MODE

## What changes were proposed in this pull request?
For better test coverage, this pr proposed to use the 4 mixed config sets of `WHOLESTAGE_CODEGEN_ENABLED` and `CODEGEN_FACTORY_MODE`  when running `SQLQueryTestSuite`:
1. WHOLESTAGE_CODEGEN_ENABLED=true, CODEGEN_FACTORY_MODE=CODEGEN_ONLY
2. WHOLESTAGE_CODEGEN_ENABLED=false, CODEGEN_FACTORY_MODE=CODEGEN_ONLY
3. WHOLESTAGE_CODEGEN_ENABLED=true, CODEGEN_FACTORY_MODE=NO_CODEGEN
4. WHOLESTAGE_CODEGEN_ENABLED=false, CODEGEN_FACTORY_MODE=NO_CODEGEN

This pr also moved some existing tests into `ExplainSuite` because explain output results are different between codegen and interpreter modes.

## How was this patch tested?
Existing tests.

Closes apache#23213 from maropu/InterpreterModeTest.

Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
…STAGE_CODEGEN_ENABLED and CODEGEN_FACTORY_MODE

## What changes were proposed in this pull request?
For better test coverage, this pr proposed to use the 4 mixed config sets of `WHOLESTAGE_CODEGEN_ENABLED` and `CODEGEN_FACTORY_MODE`  when running `SQLQueryTestSuite`:
1. WHOLESTAGE_CODEGEN_ENABLED=true, CODEGEN_FACTORY_MODE=CODEGEN_ONLY
2. WHOLESTAGE_CODEGEN_ENABLED=false, CODEGEN_FACTORY_MODE=CODEGEN_ONLY
3. WHOLESTAGE_CODEGEN_ENABLED=true, CODEGEN_FACTORY_MODE=NO_CODEGEN
4. WHOLESTAGE_CODEGEN_ENABLED=false, CODEGEN_FACTORY_MODE=NO_CODEGEN

This pr also moved some existing tests into `ExplainSuite` because explain output results are different between codegen and interpreter modes.

## How was this patch tested?
Existing tests.

Closes apache#23213 from maropu/InterpreterModeTest.

Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants