Skip to content

Commit

Permalink
PySparkTask: special characters in name (#2778)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-its committed Sep 10, 2019
1 parent 1e99e6b commit ea97908
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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']))
name = re.sub(r'[^\w]', '_', self.name)
self.run_path = tempfile.mkdtemp(prefix=name)
self.run_pickle = os.path.join(self.run_path, '.'.join([name, '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

0 comments on commit ea97908

Please sign in to comment.