uzhastik commented on code in PR #37458: URL: https://github.com/apache/airflow/pull/37458#discussion_r1523224271
########## 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): Review Comment: We use it for query text templating and for syntax highlighting (sql dialect). Can I achieve this with BaseOperator? I doubt We use it for backfill as well when Airflow starts our query and provides time intervals ########## 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: I know exact moment when to create and destroy hook. Any situations when caching is preferable? More ver it would be nice to call "hook.close()" when it is not needed anymore. Current code is quite straightforward: creates hook in execute and destroys it in on_kill. -- 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