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

[AIRFLOW-4289] fix spark_binary argument being ignored in SparkSubmit… #5564

Merged
merged 1 commit into from
Jul 31, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions airflow/contrib/hooks/spark_submit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self,
application_args=None,
env_vars=None,
verbose=False,
spark_binary="spark-submit"):
spark_binary=None):
self._conf = conf
self._conn_id = conn_id
self._files = files
Expand Down Expand Up @@ -170,7 +170,7 @@ def _resolve_connection(self):
'queue': None,
'deploy_mode': None,
'spark_home': None,
'spark_binary': self._spark_binary,
'spark_binary': self._spark_binary or "spark-submit",
'namespace': 'default'}

try:
Expand All @@ -187,7 +187,8 @@ def _resolve_connection(self):
conn_data['queue'] = extra.get('queue', None)
conn_data['deploy_mode'] = extra.get('deploy-mode', None)
conn_data['spark_home'] = extra.get('spark-home', None)
conn_data['spark_binary'] = extra.get('spark-binary', "spark-submit")
conn_data['spark_binary'] = self._spark_binary or \
extra.get('spark-binary', "spark-submit")
conn_data['namespace'] = extra.get('namespace', 'default')
except AirflowException:
self.log.info(
Expand Down
37 changes: 37 additions & 0 deletions tests/contrib/hooks/test_spark_submit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,43 @@ def test_resolve_connection_spark_binary_set_connection(self):
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(cmd[0], 'custom-spark-submit')

def test_resolve_connection_spark_binary_default_value_override(self):
# Given
hook = SparkSubmitHook(conn_id='spark_binary_set',
spark_binary='another-custom-spark-submit')

# When
connection = hook._resolve_connection()
cmd = hook._build_spark_submit_command(self._spark_job_file)

# Then
expected_spark_connection = {"master": "yarn",
"spark_binary": "another-custom-spark-submit",
"deploy_mode": None,
"queue": None,
"spark_home": None,
"namespace": 'default'}
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(cmd[0], 'another-custom-spark-submit')

def test_resolve_connection_spark_binary_default_value(self):
# Given
hook = SparkSubmitHook(conn_id='spark_default')

# When
connection = hook._resolve_connection()
cmd = hook._build_spark_submit_command(self._spark_job_file)

# Then
expected_spark_connection = {"master": "yarn",
"spark_binary": "spark-submit",
"deploy_mode": None,
"queue": 'root.default',
"spark_home": None,
"namespace": 'default'}
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(cmd[0], 'spark-submit')

def test_resolve_connection_spark_binary_and_home_set_connection(self):
# Given
hook = SparkSubmitHook(conn_id='spark_binary_and_home_set')
Expand Down