This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new cfac7d379f Make SQLExecute Query signature consistent with other SQL
operators (#32974)
cfac7d379f is described below
commit cfac7d379f43d8d15da65cae8620322dfd0043d6
Author: Jarek Potiuk <[email protected]>
AuthorDate: Fri Aug 4 21:34:33 2023 +0200
Make SQLExecute Query signature consistent with other SQL operators (#32974)
The database and conn_id are present in a number of SQL*Check oerators
but they were missing in the SQLExecuteQuery operator. This was no
problem because they were passed to BaseSQL operator via kwargs,
but this was inconsistent with the other operators and it was not
easily discoverable.
This PR does not make any functional changes, so no tests are needed
or possible to add, existing tests should continue working as they
did after this change.
---
airflow/providers/common/sql/operators/sql.py | 6 +++++-
tests/providers/exasol/operators/test_exasol.py | 1 +
tests/providers/snowflake/operators/test_snowflake.py | 1 +
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/airflow/providers/common/sql/operators/sql.py
b/airflow/providers/common/sql/operators/sql.py
index b0e70680ea..810207d1b7 100644
--- a/airflow/providers/common/sql/operators/sql.py
+++ b/airflow/providers/common/sql/operators/sql.py
@@ -204,6 +204,8 @@ class SQLExecuteQueryOperator(BaseSQLOperator):
:param handler: (optional) the function that will be applied to the cursor
(default: fetch_all_handler).
:param split_statements: (optional) if split single SQL string into
statements. By default, defers
to the default value in the ``run`` method of the configured hook.
+ :param conn_id: the connection ID used to connect to the database
+ :param database: name of database which overwrite the defined one in
connection
:param return_last: (optional) return the result of only last statement
(default: True).
:param show_return_value_in_logs: (optional) if true operator output will
be printed to the task log.
Use with caution. It's not recommended to dump large datasets to the
log. (default: False).
@@ -225,12 +227,14 @@ class SQLExecuteQueryOperator(BaseSQLOperator):
autocommit: bool = False,
parameters: Mapping | Iterable | None = None,
handler: Callable[[Any], Any] = fetch_all_handler,
+ conn_id: str | None = None,
+ database: str | None = None,
split_statements: bool | None = None,
return_last: bool = True,
show_return_value_in_logs: bool = False,
**kwargs,
) -> None:
- super().__init__(**kwargs)
+ super().__init__(conn_id=conn_id, database=database, **kwargs)
self.sql = sql
self.autocommit = autocommit
self.parameters = parameters
diff --git a/tests/providers/exasol/operators/test_exasol.py
b/tests/providers/exasol/operators/test_exasol.py
index c805684aa9..e7aa93f5ba 100644
--- a/tests/providers/exasol/operators/test_exasol.py
+++ b/tests/providers/exasol/operators/test_exasol.py
@@ -53,6 +53,7 @@ class TestExasol:
ExasolOperator(task_id="TEST", sql="SELECT 1", schema="dummy")
mock_base_op.assert_called_once_with(
conn_id="exasol_default",
+ database=None,
hook_params={"schema": "dummy"},
default_args={},
task_id="TEST",
diff --git a/tests/providers/snowflake/operators/test_snowflake.py
b/tests/providers/snowflake/operators/test_snowflake.py
index ea9d8333f3..ad294c89a8 100644
--- a/tests/providers/snowflake/operators/test_snowflake.py
+++ b/tests/providers/snowflake/operators/test_snowflake.py
@@ -90,6 +90,7 @@ class TestSnowflakeOperatorForParams:
mock_base_op.assert_called_once_with(
conn_id="snowflake_default",
task_id="snowflake_params_check",
+ database=None,
hook_params={
"warehouse": "test_warehouse",
"database": "test_database",