Taragolis commented on code in PR #37458:
URL: https://github.com/apache/airflow/pull/37458#discussion_r1524627620


##########
airflow/providers/yandex/operators/yandexcloud_yq.py:
##########
@@ -0,0 +1,89 @@
+# 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 typing import TYPE_CHECKING, Any, Sequence
+
+from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator
+from airflow.providers.yandex.hooks.yq import YQHook
+from airflow.providers.yandex.links.yq import YQLink
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class YQExecuteQueryOperator(SQLExecuteQueryOperator):
+    """
+    Executes sql code using Yandex Query service.
+
+    :param sql: the SQL code to be executed as a single string
+    :param name: name of the query in YandexQuery
+    :param folder_id: cloud folder id where to create query
+    :param connection_id: Airflow connection ID to get parameters from
+    :param folder_id: cloud folder id where to create query
+    """
+
+    operator_extra_links = (YQLink(),)
+    template_fields: Sequence[str] = ("sql",)
+    template_fields_renderers = {"sql": "sql"}
+    template_ext: Sequence[str] = (".sql",)
+    ui_color = "#ededed"
+
+    def __init__(
+        self,
+        *,
+        name: str | None = None,
+        folder_id: str | None = None,
+        connection_id: str | None = None,
+        public_ssh_key: str | None = None,
+        service_account_id: str | None = None,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.name = name
+        self.folder_id = folder_id
+        self.connection_id = connection_id
+        self.public_ssh_key = public_ssh_key
+        self.service_account_id = service_account_id
+
+        self.hook: YQHook | None = None

Review Comment:
   In most cases it preferable:
   - Type Checking, time-to time mypy might complain about `YQHook | None` 
because for it not every-time clear is it  already assigned or not,
   - Changes in the code, we not assume that code will frozen in time, which 
might accidentally run before self.hook assigned
   
   So properties help in this cases, and also make mocking easier in complex 
situation.
   However property itself (getter) will create hook every time, so better to 
use `cached_propery` which assigned exactly one time during first invocation.
   
   For now that is fine, but it is a big chance that it moved in 
`cached_propery` in the future when something goes wrong.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to