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

[MINOR][SQL] Use resource path for test_script.sh #15246

Closed
wants to merge 5 commits into from

Conversation

weiqingy
Copy link
Contributor

What changes were proposed in this pull request?

This PR modified the test case test("script") to use resource path for test_script.sh. Make the test case portable (even in IntelliJ).

How was this patch tested?

Passed the test case.
Before:
Run test("script") in IntelliJ:

Caused by: org.apache.spark.SparkException: Subprocess exited with status 127. Error: bash: src/test/resources/test_script.sh: No such file or directory 

After:
Test passed.

@SparkQA
Copy link

SparkQA commented Sep 26, 2016

Test build #65933 has finished for PR 15246 at commit d799eea.

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

@srowen
Copy link
Member

srowen commented Sep 27, 2016

Hm, I see why this happens to work, because the file is not packaged inside a jar file. Normally that's what getResource is for, and if it were in a jar this wouldn't work. It's not a bad idea though isn't it easier to just set the working dir for the project in your IDE? IJ can do that.

@weiqingy
Copy link
Contributor Author

Hi, @srowen Thanks a lot for the comments. Yes, setting the working dir can work. However, working dir varies from machine to machine. It would be a little tricky to maintain and troubleshoot in the future. Configuration settings of IDE is not managed and version controlled now. So I think it will be better to make the test case independent with the IDE settings.

@srowen
Copy link
Member

srowen commented Sep 28, 2016

It's a fair point, though I'm also wondering -- aren't there many other instances of this throughout the tests? in some cases the file would happen to get put on a classpath by the IDE but not always. Is it possible to fix more, or all such issues the same way?

@weiqingy
Copy link
Contributor Author

Hi, @srowen Yes, you are right. I am searching the code base to see if we can fix more.

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 4, 2016

I have searched src/test/resourcein the code base to get test cases which hard code src/test/resources. Except for two ignore tests in SQLQuerySuite, for those can not pass in IDE, they are modified to use resource path instead.

@SparkQA
Copy link

SparkQA commented Oct 4, 2016

Test build #66300 has finished for PR 15246 at commit 6129187.

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

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 4, 2016

Hi, @srowen Could you please review this again? Thanks.

@srowen
Copy link
Member

srowen commented Oct 4, 2016

I wonder if you could make a utility method for this in SparkFunSuite ? and then I think there are two more files that load a file from src/test/resources, in the hive-thriftserver module, as CliSuite and HiveThriftserver2Suites. I think those might be able to use a similar treatment.

I suppose it's fine to assume that whatever is in src/test/resources would be on the test classpath at runtime because Maven would always put it there, yes.

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 4, 2016

Hi, @srowen Thanks for the suggestion. Yes, I have updated the PR to add utility methods for this in SparkFunSuite and include CliSuite and HiveThriftserver2Suites. The reason CliSuite and HiveThriftserver2Suites are missed in my previouse PR is their default working dir in my IDE is /Users/wyang/WorkingSpace/sparkrepo/sql/catalyst, and their test cases does not have this issue.

@SparkQA
Copy link

SparkQA commented Oct 4, 2016

Test build #66337 has finished for PR 15246 at commit cf161f7.

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

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 4, 2016

At commit 2ea3eea, it reverted the changes in CliSuite and HiveThriftServer2Suites since their target files are not on the their test classpath ( e.g. in the test("Commands using SerDe provided in --jars") of CliSuite, ../hive/src/test/resources/hive-hcatalog-core-0.13.1.jar is actually /Users/wyang/WorkingSpace/sparkrepo/sql/hive/src/test/resources/hive-hcatalog-core-0.13.1.jar)

@SparkQA
Copy link

SparkQA commented Oct 5, 2016

Test build #66344 has finished for PR 15246 at commit 2ea3eea.

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

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 5, 2016

Not sure why org.apache.spark.streaming.kafka010.DirectKafkaStreamSuite.pattern based subscription failed. Looking into it.

@weiqingy weiqingy closed this Oct 5, 2016
@weiqingy weiqingy reopened this Oct 5, 2016
@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 5, 2016

The changes should be safe to org.apache.spark.streaming.kafka010.DirectKafkaStreamSuite.pattern based subscription, I'll re-trigger again.

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 5, 2016

Retest this please.

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 5, 2016

Hi, @srowen Could you please re-trigger jenkins to retest this? I think the the failure of org.apache.spark.streaming.kafka010.DirectKafkaStreamSuite.pattern based subscription is not caused by the change of this PR. Thank you very much.

@srowen
Copy link
Member

srowen commented Oct 5, 2016

Jenkins add to whitelist

@srowen
Copy link
Member

srowen commented Oct 5, 2016

Jenkins retest this please

@SparkQA
Copy link

SparkQA commented Oct 5, 2016

Test build #66390 has finished for PR 15246 at commit 2ea3eea.

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

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 5, 2016

org.apache.spark.streaming.kafka010.DirectKafkaStreamSuite.pattern based subscription failed again, but it passed in my laptop. I still think the failure is not related to this PR. @srowen Could you please give some suggestion? Thanks.

@@ -41,6 +43,15 @@ abstract class SparkFunSuite
}
}

// helper function
protected final def getFile(file: String): File = {
Copy link
Member

Choose a reason for hiding this comment

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

I like what you've done here with getCanonicalPath. Does this call here need getCanonicalFile for good measure? I supposes there's also something like Paths.get(... toURI).toFile but I don't know if that acts any differently.

How about calling these getTestResourceFile and getTestResourcePath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@srowen getTestResourceFile and getTestResourcePath look better. Thanks.

URL class doesn't have a method like getCanonicalFile. It has getFile only.

Also, I tested Paths.get(... toURI).toFile. The only difference I noticed is that it keeps spaces as usual, but getFile(file).getCanonicalPath converts spaces to "%20". I suppose they are both OK.

@@ -17,6 +17,7 @@

package org.apache.spark.sql.hive.execution

import java.io.File
Copy link
Member

Choose a reason for hiding this comment

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

Is this used? maybe I'm missing it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Will delete it.

if (testCommandAvailable("bash") && testCommandAvailable("echo | sed")) {
val df = Seq(("x1", "y1", "z1"), ("x2", "y2", "z2")).toDF("c1", "c2", "c3")
df.createOrReplaceTempView("script_table")
val query1 = sql(
"""
s"""
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering whether string interpolation and triple quotes work together, and I think they do except for some odd corner cases: http://stackoverflow.com/questions/25632924/whats-the-difference-between-raw-string-interpolation-and-triple-quotes-in-scal It's probably OK here but made me double-check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Good catch. There are some odd corner cases for s""" """, but it should be OK here.

@SparkQA
Copy link

SparkQA commented Oct 7, 2016

Test build #66482 has finished for PR 15246 at commit 1233aa2.

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

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 7, 2016

Hi, @srowen all tests passed this time. Could you please review this PR again? Thanks.

@weiqingy
Copy link
Contributor Author

weiqingy commented Oct 7, 2016

Thank you for approving, @srowen

@srowen
Copy link
Member

srowen commented Oct 8, 2016

Merged to master

@asfgit asfgit closed this in 8a6bbe0 Oct 8, 2016
uzadude pushed a commit to uzadude/spark that referenced this pull request Jan 27, 2017
## What changes were proposed in this pull request?
This PR modified the test case `test("script")` to use resource path for `test_script.sh`. Make the test case portable (even in IntelliJ).

## How was this patch tested?
Passed the test case.
Before:
Run `test("script")` in IntelliJ:
```
Caused by: org.apache.spark.SparkException: Subprocess exited with status 127. Error: bash: src/test/resources/test_script.sh: No such file or directory
```
After:
Test passed.

Author: Weiqing Yang <yangweiqing001@gmail.com>

Closes apache#15246 from weiqingy/hivetest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants