Skip to content

Commit

Permalink
SDK-65: Allow submitting Spark SQL from a local file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit Agarwal committed Dec 1, 2015
1 parent 8da5a35 commit 5ec7b4c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
12 changes: 9 additions & 3 deletions qds_sdk/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,22 @@ def validate_script_location(cls, options):
elif fileExtension == ".scala":
options.language = "scala"
elif fileExtension == ".R":
options.language = "R"
options.language = "R"
elif fileExtension == ".sql":
options.language = "sql"
else:
raise ParseError("Invalid program type, Please choose one from python or scala or R %s" %str(fileExtension),
raise ParseError("Invalid program type %s. Please choose one from python, scala, R or sql." % str(fileExtension),
cls.optparser.format_help())
else:
raise ParseError("Invalid location, Please choose a local file location",
cls.optparser.format_help())

options.script_location = None
options.program = q
if options.language == "sql":
options.sql = q
options.language = None
else:
options.program = q

@classmethod
def parse(cls, args):
Expand Down
26 changes: 25 additions & 1 deletion tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def test_submit_script_location_local_java(self):
print_command()
with self.assertRaises(qds_sdk.exception.ParseError):
qds.main()

def test_submit_script_location_local_R(self):
with NamedTemporaryFile(suffix=".R") as tmp:
tmp.write('cat("hello, world!")'.encode("utf8"))
Expand All @@ -437,6 +437,30 @@ def test_submit_script_location_local_R(self):
'can_notify': False,
'script_location': None})

def test_submit_script_location_local_sql(self):
with NamedTemporaryFile(suffix=".sql") as tmp:
tmp.write('show tables'.encode("utf8"))
tmp.seek(0)
sys.argv = ['qds.py', 'sparkcmd', 'submit', '--script_location', tmp.name]
print_command()
Connection._api_call = Mock(return_value={'id': 1234})
qds.main()
Connection._api_call.assert_called_with('POST', 'commands',
{'macros': None,
'label': None,
'language': None,
'tags': None,
'name': None,
'sql': "show tables",
'program': None,
'app_id': None,
'cmdline':None,
'command_type': 'SparkCommand',
'arguments': None,
'user_program_arguments': None,
'can_notify': False,
'script_location': None})

def test_submit_sql(self):
sys.argv = ['qds.py', 'sparkcmd', 'submit', '--sql', 'show dummy']
print_command()
Expand Down

0 comments on commit 5ec7b4c

Please sign in to comment.