This is an automated email from the ASF dual-hosted git repository.
taragolis 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 aee3cfc91e Consolidate hook management in
AzureDataExplorerQueryOperator (#34436)
aee3cfc91e is described below
commit aee3cfc91e0ade7b13ec5375a56dd2fe03d3517f
Author: Hussein Awala <[email protected]>
AuthorDate: Mon Sep 18 21:13:15 2023 +0200
Consolidate hook management in AzureDataExplorerQueryOperator (#34436)
* Consolidate hook management in AzureDataExplorerQueryOperator
* use AirflowProviderDeprecationWarning
---
airflow/providers/microsoft/azure/operators/adx.py | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/airflow/providers/microsoft/azure/operators/adx.py
b/airflow/providers/microsoft/azure/operators/adx.py
index babf38c038..630c6d497b 100644
--- a/airflow/providers/microsoft/azure/operators/adx.py
+++ b/airflow/providers/microsoft/azure/operators/adx.py
@@ -18,9 +18,13 @@
"""This module contains Azure Data Explorer operators."""
from __future__ import annotations
+from functools import cached_property
from typing import TYPE_CHECKING, Sequence
+from deprecated.classic import deprecated
+
from airflow.configuration import conf
+from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.models import BaseOperator
from airflow.providers.microsoft.azure.hooks.adx import AzureDataExplorerHook
@@ -61,10 +65,16 @@ class AzureDataExplorerQueryOperator(BaseOperator):
self.options = options
self.azure_data_explorer_conn_id = azure_data_explorer_conn_id
- def get_hook(self) -> AzureDataExplorerHook:
+ @cached_property
+ def hook(self) -> AzureDataExplorerHook:
"""Returns new instance of AzureDataExplorerHook."""
return AzureDataExplorerHook(self.azure_data_explorer_conn_id)
+ @deprecated(reason="use `hook` property instead.",
category=AirflowProviderDeprecationWarning)
+ def get_hook(self) -> AzureDataExplorerHook:
+ """Returns new instance of AzureDataExplorerHook."""
+ return self.hook
+
def execute(self, context: Context) -> KustoResultTable | str:
"""
Run KQL Query on Azure Data Explorer (Kusto).
@@ -73,8 +83,7 @@ class AzureDataExplorerQueryOperator(BaseOperator):
https://docs.microsoft.com/en-us/azure/kusto/api/rest/response2
"""
- hook = self.get_hook()
- response = hook.run_query(self.query, self.database, self.options)
+ response = self.hook.run_query(self.query, self.database, self.options)
if conf.getboolean("core", "enable_xcom_pickling"):
return response.primary_results[0]
else: