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

PySparkTask: handle special characters in name (#2778) #2779

Merged
merged 2 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions luigi/contrib/spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import logging
import os
import re
import sys
import tempfile
import shutil
Expand Down Expand Up @@ -298,8 +299,9 @@ def app_command(self):
return [self.app, pickle_loc] + self.app_options()

def run(self):
self.run_path = tempfile.mkdtemp(prefix=self.name)
self.run_pickle = os.path.join(self.run_path, '.'.join([self.name.replace(' ', '_'), 'pickle']))
path_name_fragment = re.sub(r'[^\w]', '_', self.name)
self.run_path = tempfile.mkdtemp(prefix=path_name_fragment)
self.run_pickle = os.path.join(self.run_path, '.'.join([path_name_fragment, 'pickle']))
with open(self.run_pickle, 'wb') as fd:
# Copy module file to run path.
module_path = os.path.abspath(inspect.getfile(self.__class__))
Expand Down
11 changes: 11 additions & 0 deletions test/contrib/spark_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def main(self, sc, *args):
sc.textFile(self.input().path).saveAsTextFile(self.output().path)


class MessyNamePySparkTask(TestPySparkTask):
name = 'AppName(a,b,c,1:2,3/4)'


@attr('apache')
class SparkSubmitTaskTest(unittest.TestCase):
ss = 'ss-stub'
Expand Down Expand Up @@ -289,3 +293,10 @@ def mock_spark_submit(task):

sc.textFile.assert_called_with('input')
sc.textFile.return_value.saveAsTextFile.assert_called_with('output')

@patch('luigi.contrib.external_program.subprocess.Popen')
def test_name_cleanup(self, proc):
setup_run_process(proc)
job = MessyNamePySparkTask()
job.run()
assert 'AppName_a_b_c_1_2_3_4_' in job.run_path