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-25267][SQL][TEST] Disable ConvertToLocalRelation in the test cases of sql/core and sql/hive #22270

Closed
wants to merge 3 commits into from

Conversation

dilipbiswal
Copy link
Contributor

What changes were proposed in this pull request?

In SharedSparkSession and TestHive, we need to disable the rule ConvertToLocalRelation for better test case coverage.

How was this patch tested?

Identify the failures after excluding "ConvertToLocalRelation" rule.

@SparkQA
Copy link

SparkQA commented Aug 29, 2018

Test build #95432 has finished for PR 22270 at commit bd57944.

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

@dilipbiswal
Copy link
Contributor Author

retest this please

@SparkQA
Copy link

SparkQA commented Aug 29, 2018

Test build #95435 has finished for PR 22270 at commit bd57944.

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

@SparkQA
Copy link

SparkQA commented Aug 30, 2018

Test build #95457 has finished for PR 22270 at commit b83fa29.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

import com.github.fommil.netlib.BLAS.{getInstance => blas}
import org.apache.commons.io.FileUtils
import org.apache.commons.io.filefilter.TrueFileFilter
import org.scalatest.BeforeAndAfterEach

Copy link
Member

Choose a reason for hiding this comment

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

Revert the blank lines?

withClue("transform should fail when ids exceed integer range. ") {
val model = als.fit(df)
def testTransformIdExceedsIntRange[A : Encoder](dataFrame: DataFrame): Unit = {
withSQLConf(SQLConf.OPTIMIZER_EXCLUDED_RULES.key -> "") {
Copy link
Member

Choose a reason for hiding this comment

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

If we only want to disable ConvertToLocalRelation in sql/core and sql/hive, maybe we can set this sql conf at MLTest?

I don't see any usage of withSQLConf in ml tests. It looks a bit weird to see it here.

Copy link
Contributor Author

@dilipbiswal dilipbiswal Aug 30, 2018

Choose a reason for hiding this comment

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

@viirya Thanks !! Actually currently i am just making changes to move forward with testing to identify the failures. I will open separate pr for code/test fix. So lets discuss the right way to fix the problem there ? I agree with your suggestion here :-)

Copy link
Member

Choose a reason for hiding this comment

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

Sure. :)

@@ -59,7 +60,8 @@ object TestHive
.set("spark.sql.warehouse.dir", TestHiveContext.makeWarehouseDir().toURI.getPath)
// SPARK-8910
.set("spark.ui.enabled", "false")
.set("spark.unsafe.exceptionOnMemoryLeak", "true")))
.set("spark.unsafe.exceptionOnMemoryLeak", "true")
.set(SQLConf.OPTIMIZER_EXCLUDED_RULES.key, ConvertToLocalRelation.ruleName)))
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a comment for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@viirya Sure.. i will add.

@SparkQA
Copy link

SparkQA commented Aug 30, 2018

Test build #95458 has finished for PR 22270 at commit 877ad96.

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

@SparkQA
Copy link

SparkQA commented Aug 30, 2018

Test build #95484 has finished for PR 22270 at commit 7953ebd.

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

@SparkQA
Copy link

SparkQA commented Aug 31, 2018

Test build #95516 has finished for PR 22270 at commit 53f4984.

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

@SparkQA
Copy link

SparkQA commented Aug 31, 2018

Test build #95529 has finished for PR 22270 at commit 78cce41.

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

s"""
for (int $i = 0; $i < $arr.numElements(); $i ++) {
if ($arr.isNullAt($i)) {
${ev.isNull} = true;
${setIsNullCode}
Copy link
Member

Choose a reason for hiding this comment

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

nit: ${setIsNullCode} -> $setIsNullCode
btw, you found some bugs when excluding the ConvertToLocalRelation rule in tests, right?

Copy link
Member

Choose a reason for hiding this comment

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

Please open separate JIRAs and PRs for the codegen fixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gatorsmile OK.. Sean.

} else if (${ctx.genEqual(right.dataType, value, getValue)}) {
${ev.isNull} = false;
${unsetIsNullCode}
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maropu will change

@@ -1730,9 +1730,8 @@ class DataFrameSuite extends QueryTest with SharedSQLContext {

test("SPARK-9083: sort with non-deterministic expressions") {
import org.apache.spark.util.random.XORShiftRandom
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this import into the top? (this is not related to this pr though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maropu will do.

@@ -85,12 +85,12 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
}

val df5 = Seq((Seq("a", null), Seq(1, 2))).toDF("k", "v")
intercept[RuntimeException] {
intercept[Exception] {
df5.select(map_from_arrays($"k", $"v")).collect
Copy link
Member

Choose a reason for hiding this comment

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

What's the concrete exception this query throws?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maropu I will double check and get back. But i think it was SparkException.

Copy link
Contributor Author

@dilipbiswal dilipbiswal Sep 6, 2018

Choose a reason for hiding this comment

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

@maropu We get a SparkException here which in turn wraps a RuntimeException. When we have ConvertToLocalRelation active, we get a RuntimeException from driver. But when we disable it, the error is raised from the executor with a SparkException as the top level exception. Please let me know if my understanding is not correct.

@@ -1464,12 +1465,14 @@ case class ArrayContains(left: Expression, right: Expression)
nullSafeCodeGen(ctx, ev, (arr, value) => {
val i = ctx.freshName("i")
val getValue = CodeGenerator.getValue(arr, right.dataType, i)
val setIsNullCode = if (nullable) s"${ev.isNull} = true;" else ""
val unsetIsNullCode = if (nullable) s"${ev.isNull} = false;" else ""
s"""
for (int $i = 0; $i < $arr.numElements(); $i ++) {
if ($arr.isNullAt($i)) {
Copy link
Member

Choose a reason for hiding this comment

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

(This is also not related to this pr though....) when left.dataType.asInstanceOf[ArrayType].containsNull = false, I think we don't need this condition if ($arr.isNullAt($i)) {?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maropu You are right !! I will try to optimize this in the other pr i am going to open. please check if you like it.

Copy link
Member

Choose a reason for hiding this comment

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

many thanks! ya, plz ping me to review ;)

@@ -85,12 +85,12 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
}

val df5 = Seq((Seq("a", null), Seq(1, 2))).toDF("k", "v")
intercept[RuntimeException] {
intercept[Exception] {
Copy link
Member

Choose a reason for hiding this comment

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

Let us capture the exception and compare the error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gatorsmile Thanks.. I am checking the message now.

@cloud-fan
Copy link
Contributor

Thanks for looking into this!

I think we have to clean up our test framework later (after 2.4). We should identify the test cases that are actually testing the expressions, and run it with/without enabling the local relation optimization, to test both codegen and interpreted code paths.

Since the current test suites are a little messy, this will be a lot of work, to reorganize them. I'm looking forward to seeing us accomplish it in Spark 3.0!

@dilipbiswal
Copy link
Contributor Author

dilipbiswal commented Sep 1, 2018

@cloud-fan Thank you Wenchen. Do we want to fix the two codegen compile errors in 2.4 ? One is in ArrayContains and the other is in ArraySort. I will work on re-organizing the suites to test both codegen and non codegen path for spark 3.0.

@ueshin
Copy link
Member

ueshin commented Sep 2, 2018

@dilipbiswal Let's fix the two functions in 2.4. Could you open a pr to fix the two functions? Thanks!

@dilipbiswal
Copy link
Contributor Author

@ueshin Thank you.. will do.

@dilipbiswal
Copy link
Contributor Author

@ueshin Opened (#22314) and (#22315). Thank you.

@@ -85,12 +85,12 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
}

val df5 = Seq((Seq("a", null), Seq(1, 2))).toDF("k", "v")
intercept[RuntimeException] {
intercept[Exception] {
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
Contributor Author

Choose a reason for hiding this comment

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

@HyukjinKwon We get a SparkException here which in turn wraps a RuntimeException. When we have ConvertToLocalRelation active, we get a RuntimeException from driver. But when we disable it, the error is raised from the executor with a SparkException as the top level exception. Thats the reason i changed it to intercept Exception so that this test can run both when the rule is active vs when its not.

@gatorsmile
Copy link
Member

@dilipbiswal Any update on this PR?

@dilipbiswal
Copy link
Contributor Author

@gatorsmile Yeah.. i will push the changes tonight for you to take a look.

@gatorsmile
Copy link
Member

Thank you!

@SparkQA
Copy link

SparkQA commented Sep 6, 2018

Test build #95735 has finished for PR 22270 at commit 507f89c.

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

@dilipbiswal
Copy link
Contributor Author

retest this please

@SparkQA
Copy link

SparkQA commented Sep 6, 2018

Test build #95742 has finished for PR 22270 at commit 507f89c.

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

@dilipbiswal
Copy link
Contributor Author

cc @gatorsmile

@gatorsmile
Copy link
Member

LGTM Thanks! Merged to master/2.4

asfgit pushed a commit that referenced this pull request Sep 7, 2018
…ases of sql/core and sql/hive

## What changes were proposed in this pull request?
In SharedSparkSession and TestHive, we need to disable the rule ConvertToLocalRelation for better test case coverage.
## How was this patch tested?
Identify the failures after excluding "ConvertToLocalRelation" rule.

Closes #22270 from dilipbiswal/SPARK-25267-final.

Authored-by: Dilip Biswal <dbiswal@us.ibm.com>
Signed-off-by: gatorsmile <gatorsmile@gmail.com>
(cherry picked from commit 6d7bc5a)
Signed-off-by: gatorsmile <gatorsmile@gmail.com>
@asfgit asfgit closed this in 6d7bc5a Sep 7, 2018
@dilipbiswal
Copy link
Contributor Author

Thanks a lot @gatorsmile

val seed = 33
val df = (1 to 100).map(Tuple1.apply).toDF("i")
val df = (1 to 100).map(Tuple1.apply).toDF("i").repartition(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I didn't follow this thread closely. Why do we need these repartition(1) changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cloud-fan I was just trying get this test case to pass when ConvertToLocalRelation is enabled as well as disabled. So when this rule is active, i saw that all the calls to random.nextXXX happens in one thread. When this rule is disabled, the random values get evaluated under the project operator and gets called from multiple threads. Thats why i am repartitioning the data frame to enforce single threaded execution. Is this not the right thing to do ? Please let me know ..

Copy link
Member

@HyukjinKwon HyukjinKwon Sep 10, 2018

Choose a reason for hiding this comment

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

BTW, do we still test the local relation conversion, which might be more common to users as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HyukjinKwon We are leaving this optimization on for MLTest as of now. Should we open it up for TestHive and keep it disabled it for SharedSparkSession ? cc @gatorsmile

Copy link
Member

Choose a reason for hiding this comment

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

I agree with this change It's okay. Was wondering if we actually make the coverage lower for local relation specifically, or if some other tests should be added additionally.

@@ -85,14 +85,16 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
}

val df5 = Seq((Seq("a", null), Seq(1, 2))).toDF("k", "v")
intercept[RuntimeException] {
val msg1 = intercept[Exception] {
Copy link
Member

Choose a reason for hiding this comment

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

re: #22270 (comment)

Didn't we disable the local relation test? Why don't we catch explicit SparkExection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HyukjinKwon Yeah... we could have caught SparkException here. My intention was to have this test case pass both when location relation optimization is on and off. Thats why i changed it a a generic exception along with verifying the error text.

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