mobuchowski commented on code in PR #60851:
URL: https://github.com/apache/airflow/pull/60851#discussion_r2812957358


##########
providers/common/sql/tests/system/common/sql/example_sql_execute_query.py:
##########
@@ -55,6 +56,13 @@
     )
     # [END howto_operator_sql_execute_query]
 
+    # [START howto_decorator_sql_execute_query]
+    @task.sql(split_statements=True, return_last=False)
+    def execute_query_taskflow():
+        return f"SELECT 1; SELECT * FROM {AIRFLOW_DB_METADATA_TABLE} LIMIT 1;"

Review Comment:
   AFAIK you need to call the taskflow operators to actually execute them, like 
in docs: 
https://airflow.apache.org/docs/apache-airflow/stable/tutorial/taskflow.html#step-3-build-the-flow



##########
providers/common/sql/src/airflow/providers/common/sql/decorators/sql.py:
##########
@@ -0,0 +1,129 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from collections.abc import Callable, Collection, Mapping, Sequence
+from typing import TYPE_CHECKING, Any, ClassVar
+
+from airflow.providers.common.compat.sdk import (
+    AIRFLOW_V_3_0_PLUS,
+    DecoratedOperator,
+    TaskDecorator,
+    context_merge,
+    task_decorator_factory,
+)
+from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator
+from airflow.utils.operator_helpers import determine_kwargs
+
+if AIRFLOW_V_3_0_PLUS:
+    from airflow.sdk.definitions._internal.types import SET_DURING_EXECUTION
+else:
+    from airflow.utils.types import NOTSET as SET_DURING_EXECUTION  # type: 
ignore[attr-defined,no-redef]
+
+
+if TYPE_CHECKING:
+    from airflow.providers.common.compat.sdk import Context
+
+
+class _SQLDecoratedOperator(DecoratedOperator, SQLExecuteQueryOperator):
+    """
+    Wraps a Python callable and uses the callable return value as the SQL 
command to be executed.
+
+    :param python_callable: A reference to an object that is callable.
+    :param op_kwargs: A dictionary of keyword arguments that will get unpacked 
(templated).
+    :param op_args: A list of positional arguments that will get unpacked 
(templated).
+    """
+
+    template_fields: Sequence[str] = (
+        *DecoratedOperator.template_fields,
+        *SQLExecuteQueryOperator.template_fields,
+    )
+    template_fields_renderers: ClassVar[dict[str, str]] = {
+        **DecoratedOperator.template_fields_renderers,
+        **SQLExecuteQueryOperator.template_fields_renderers,
+    }
+
+    custom_operator_name: str = "@task.sql"
+

Review Comment:
   Should this set 
   ```
   overwrite_rtif_after_execution: bool = True
   ```
   similar to task.bash operator?
   
   



##########
providers/common/sql/src/airflow/providers/common/sql/decorators/sql.py:
##########
@@ -0,0 +1,129 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from collections.abc import Callable, Collection, Mapping, Sequence
+from typing import TYPE_CHECKING, Any, ClassVar
+
+from airflow.providers.common.compat.sdk import (
+    AIRFLOW_V_3_0_PLUS,
+    DecoratedOperator,
+    TaskDecorator,
+    context_merge,
+    task_decorator_factory,
+)
+from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator
+from airflow.utils.operator_helpers import determine_kwargs
+
+if AIRFLOW_V_3_0_PLUS:
+    from airflow.sdk.definitions._internal.types import SET_DURING_EXECUTION
+else:
+    from airflow.utils.types import NOTSET as SET_DURING_EXECUTION  # type: 
ignore[attr-defined,no-redef]
+
+
+if TYPE_CHECKING:
+    from airflow.providers.common.compat.sdk import Context
+
+
+class _SQLDecoratedOperator(DecoratedOperator, SQLExecuteQueryOperator):
+    """
+    Wraps a Python callable and uses the callable return value as the SQL 
command to be executed.
+
+    :param python_callable: A reference to an object that is callable.
+    :param op_kwargs: A dictionary of keyword arguments that will get unpacked 
(templated).
+    :param op_args: A list of positional arguments that will get unpacked 
(templated).
+    """
+
+    template_fields: Sequence[str] = (
+        *DecoratedOperator.template_fields,
+        *SQLExecuteQueryOperator.template_fields,
+    )
+    template_fields_renderers: ClassVar[dict[str, str]] = {
+        **DecoratedOperator.template_fields_renderers,
+        **SQLExecuteQueryOperator.template_fields_renderers,
+    }
+
+    custom_operator_name: str = "@task.sql"
+
+    def __init__(
+        self,
+        python_callable: Callable,
+        op_args: Collection[Any] | None = None,
+        op_kwargs: Mapping[str, Any] | None = None,
+        **kwargs,

Review Comment:
   Should those be keyword-only params like other taskflow operators?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to