-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-7735] [pyspark] Raise Exception on non-zero exit from pipe commands #6262
Conversation
This will allow problems with piped commands to be detected. This will also allow tasks to be retried where errors are rare (such as network problems in piped commands).
A simple test of this: a = sc.parallelize([1, 2, 3])
b = a.pipe('cc') # a clearly incorrect pipe command
b.collect() The old behaviour is to return an empty list ( : org.apache.spark.SparkException: Job aborted due to stage failure: Task 2 in stage 0.0 failed 1 times, most recent failure: Lost task 2.0 in stage 0.0 (TID 2, localhost): org.apache.spark.api.python.PythonException: Traceback (most recent call last): |
@megatron-me-uk have a look at https://cwiki.apache.org/confluence/display/SPARK/Contributing+to+Spark first please -- you missed a few steps here. The change may well be fine. |
Ah, I hadn't seen that! Will take a look. |
I believe that this change will bring pyspark more in line with the operation of the scala implementation.
In scala, the output of an external command is read from stdout until EOF. Then the exit status is checked. If exitStatus is not Zero an Exception is thrown. |
I think it makes sense; really I was getting at making a JIRA to track this. |
OK, seems I have to create an account etc. I will put it on my to-do list. Thanks for the help! |
Ran into the same issue. Thanks for the patch! |
Jenkins, this is ok to test. |
Can you add a regression test for this in |
Test build #33865 has finished for PR 6262 at commit
|
Test build #34085 has finished for PR 6262 at commit
|
Test build #34175 has finished for PR 6262 at commit
|
This is an error in PEP8 but not in pylint.
Test build #34178 has finished for PR 6262 at commit
|
The test failed on "org.apache.spark.network.netty.NettyBlockTransferSecuritySuite.security mismatch auth off on client" which I don't think is related to this pull request :( |
Test build #34945 has finished for PR 6262 at commit
|
Test build #34948 has finished for PR 6262 at commit
|
Test build #35126 has finished for PR 6262 at commit
|
Test build #35136 has finished for PR 6262 at commit
|
Also be more specific about the Exception we expect to see
Test build #35142 has finished for PR 6262 at commit
|
The jenkins script is looking for results for JUnit, but we skipped all scala tests if only python or R is modified. I think we should fix the jenkins script. Davies Liu 已使用 Sparrow (http://www.sparrowmailapp.com/?sig) 在 2015年6月23日 星期二,上午8:02,Josh Rosen 写道:
|
raise Exception("Pipe function `%s' exited " | ||
"with error code %d" % (command, pipe.returncode)) | ||
else: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make check_return_code
a generator, for example:
def check_return_code():
# check return code
for x in range(0):
yield x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point I will change it.
Test build #35676 has finished for PR 6262 at commit
|
Test build #35693 has finished for PR 6262 at commit
|
permissive - do not check returncode strict - only allow returncode 0 grep - allow returncode 0 or 1
add optional argument 'mode' for rdd.pipe
Test build #36208 has finished for PR 6262 at commit
|
return True when an exception should be raised
Test build #36213 has finished for PR 6262 at commit
|
OK so I have implemented an optional argument 'mode' which by default ('permissive') maintains the current behaviour. I have added two other modes: For using grep I would recommend the 'grep' mode as it is probably better to raise an exception if grep fails for other reasons than not finding any matches. I wanted to update the docstring with this information but haven't yet found an example where optional arguments are documented which I can use as a style guide. |
@@ -687,13 +687,25 @@ def groupBy(self, f, numPartitions=None): | |||
return self.map(lambda x: (f(x), x)).groupByKey(numPartitions) | |||
|
|||
@ignore_unicode_prefix | |||
def pipe(self, command, env={}): | |||
def pipe(self, command, env={}, mode='permissive'): | |||
""" | |||
Return an RDD created by piping elements to a forked external process. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add doc for mode
?
Could we only have two mode? Fail on non-zero code or not, then it will be easier to understand. We can call it |
I guess the benefit of having a third mode is that grep can return 1 for no results without raising an exception but if grep encounters an error of some unknown kind it will return 2 and an exception will be raised. |
(rather than mode)
use boolean checkCode rather than more complicated mode optional argument. Also add param to docstring
Use boolean checkCode optional parameter
Test build #36666 has finished for PR 6262 at commit
|
Test build #36667 has finished for PR 6262 at commit
|
I have changed the implementation of the optional parameter to a boolean |
Test build #36790 has finished for PR 6262 at commit
|
I have simplified the optional parameter to be a boolean and added this to the docstring. |
…mands This will allow problems with piped commands to be detected. This will also allow tasks to be retried where errors are rare (such as network problems in piped commands). Author: Scott Taylor <[email protected]> Closes #6262 from megatron-me-uk/patch-2 and squashes the following commits: 04ae1d5 [Scott Taylor] Remove spurious empty line 98fa101 [Scott Taylor] fix blank line style error 574b564 [Scott Taylor] Merge pull request #2 from megatron-me-uk/patch-4 0c1e762 [Scott Taylor] Update rdd pipe method for checkCode ab9a2e1 [Scott Taylor] Update rdd pipe tests for checkCode eb4801c [Scott Taylor] fix fail_condition b0ac3a4 [Scott Taylor] Merge pull request #1 from megatron-me-uk/megatron-me-uk-patch-1 a307d13 [Scott Taylor] update rdd tests to test pipe modes 34fcdc3 [Scott Taylor] add optional argument 'mode' for rdd.pipe a0c0161 [Scott Taylor] fix generator issue 8a9ef9c [Scott Taylor] make check_return_code an iterator 0486ae3 [Scott Taylor] style fixes 8ed89a6 [Scott Taylor] Chain generators to prevent potential deadlock 4153b02 [Scott Taylor] fix list.sort returns None 491d3fc [Scott Taylor] Pass a function handle to assertRaises 3344a21 [Scott Taylor] wrap assertRaises with QuietTest 3ab8c7a [Scott Taylor] remove whitespace for style cc1a73d [Scott Taylor] fix style issues in pipe test 8db4073 [Scott Taylor] Add a test for rdd pipe functions 1b3dc4e [Scott Taylor] fix missing space around operator style 0974f98 [Scott Taylor] add space between words in multiline string 45f4977 [Scott Taylor] fix line too long style error 5745d85 [Scott Taylor] Remove space to fix style f552d49 [Scott Taylor] Catch non-zero exit from pipe commands
Can one of the admins verify this patch? |
@megatron-me-uk This is merged into master, could you close this PR? |
This will allow problems with piped commands to be detected.
This will also allow tasks to be retried where errors are rare (such as network problems in piped commands).