boittega commented on a change in pull request #15794:
URL: https://github.com/apache/airflow/pull/15794#discussion_r631002008
##########
File path: airflow/providers/apache/spark/hooks/spark_sql.py
##########
@@ -72,13 +77,33 @@ def __init__(
executor_memory: Optional[str] = None,
keytab: Optional[str] = None,
principal: Optional[str] = None,
- master: str = 'yarn',
+ master: Optional[str] = None,
name: str = 'default-name',
num_executors: Optional[int] = None,
verbose: bool = True,
- yarn_queue: str = 'default',
+ yarn_queue: Optional[str] = None,
) -> None:
super().__init__()
+
+ try:
+ conn: "Optional[Connection]" = self.get_connection(conn_id)
+ except AirflowNotFoundException:
+ conn = None
+ options = {}
+ else:
+ options = conn.extra_dejson
+
+ # Set arguments to values set in Connection if not explicitly provided.
+ if master is None:
+ if conn is None:
+ master = "yarn"
+ elif conn.port:
+ master = f"{conn.host}:{conn.port}"
+ else:
+ master = conn.host
+ if yarn_queue is None:
+ yarn_queue = options.get("queue", "default")
+
self._sql = sql
self._conf = conf
self._conn = self.get_connection(conn_id)
Review comment:
you created the variable `conn` on line 89 with the same result, but
inside of the try.
The idea is to only call the function `get_connection` once but you are
calling it on line 89 and 109, line 109 will raise an error because it is not
in a try.
Does it make sense?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]