bilalaslamseattle commented on code in PR #30428: URL: https://github.com/apache/airflow/pull/30428#discussion_r1155301131
########## airflow/providers/databricks/sensors/sql.py: ########## @@ -0,0 +1,131 @@ +# +# 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. +# +"""This module contains Databricks sensors.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence + +from airflow.compat.functools import cached_property +from airflow.providers.common.sql.hooks.sql import fetch_all_handler +from airflow.providers.databricks.hooks.databricks_sql import DatabricksSqlHook +from airflow.sensors.base import BaseSensorOperator +from airflow.exceptions import AirflowException + +if TYPE_CHECKING: + from airflow.utils.context import Context + + +class DatabricksSqlSensor(BaseSensorOperator): + """ + Sensor that runs a SQL query on Databricks. + + :param databricks_conn_id: Reference to :ref:`Databricks + connection id<howto/connection:databricks>` (templated), defaults to + DatabricksSqlHook.default_conn_name. + :param sql_warehouse_name: Optional name of Databricks SQL Warehouse. If not specified, ``http_path`` Review Comment: Nit: warehouse should be lowercase. ########## airflow/providers/databricks/sensors/sql.py: ########## @@ -0,0 +1,131 @@ +# +# 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. +# +"""This module contains Databricks sensors.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence + +from airflow.compat.functools import cached_property +from airflow.providers.common.sql.hooks.sql import fetch_all_handler +from airflow.providers.databricks.hooks.databricks_sql import DatabricksSqlHook +from airflow.sensors.base import BaseSensorOperator +from airflow.exceptions import AirflowException + +if TYPE_CHECKING: + from airflow.utils.context import Context + + +class DatabricksSqlSensor(BaseSensorOperator): + """ + Sensor that runs a SQL query on Databricks. + + :param databricks_conn_id: Reference to :ref:`Databricks + connection id<howto/connection:databricks>` (templated), defaults to + DatabricksSqlHook.default_conn_name. + :param sql_warehouse_name: Optional name of Databricks SQL Warehouse. If not specified, ``http_path`` + must be provided as described below, defaults to None + :param http_path: Optional string specifying HTTP path of Databricks SQL Warehouse or All Purpose Cluster. + If not specified, it should be either specified in the Databricks connection's + extra parameters, or ``sql_warehouse_name`` must be specified. + :param session_configuration: An optional dictionary of Spark session parameters. If not specified, Review Comment: Remove period after `parameters.` ########## docs/apache-airflow-providers-databricks/operators/sql.rst: ########## @@ -84,3 +84,39 @@ An example usage of the DatabricksSqlOperator to perform statements from a file :language: python :start-after: [START howto_operator_databricks_sql_multiple_file] :end-before: [END howto_operator_databricks_sql_multiple_file] + + +DatabricksSqlSensor +=================== + +Use the :class:`~airflow.providers.databricks.sensors.sql.DatabricksSqlSensor` to run the sensor +for a specific Delta table on a Databricks SQL workspace. Review Comment: Did you mean on a Databricks SQL warehouse? ########## airflow/providers/databricks/sensors/sql.py: ########## @@ -0,0 +1,131 @@ +# +# 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. +# +"""This module contains Databricks sensors.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence + +from airflow.compat.functools import cached_property +from airflow.providers.common.sql.hooks.sql import fetch_all_handler +from airflow.providers.databricks.hooks.databricks_sql import DatabricksSqlHook +from airflow.sensors.base import BaseSensorOperator +from airflow.exceptions import AirflowException + +if TYPE_CHECKING: + from airflow.utils.context import Context + + +class DatabricksSqlSensor(BaseSensorOperator): + """ + Sensor that runs a SQL query on Databricks. + + :param databricks_conn_id: Reference to :ref:`Databricks + connection id<howto/connection:databricks>` (templated), defaults to + DatabricksSqlHook.default_conn_name. + :param sql_warehouse_name: Optional name of Databricks SQL Warehouse. If not specified, ``http_path`` + must be provided as described below, defaults to None + :param http_path: Optional string specifying HTTP path of Databricks SQL Warehouse or All Purpose Cluster. + If not specified, it should be either specified in the Databricks connection's + extra parameters, or ``sql_warehouse_name`` must be specified. + :param session_configuration: An optional dictionary of Spark session parameters. If not specified, + it could be specified in the Databricks connection's extra parameters., defaults to None + :param http_headers: An optional list of (k, v) pairs + that will be set as HTTP headers on every request. (templated). + :param catalog: An optional initial catalog to use. + Requires Databricks Runtime version 9.0+ (templated), defaults to "" + :param schema: An optional initial schema to use. + Requires Databricks Runtime version 9.0+ (templated), defaults to "default" + :param sql: SQL statement to be executed. + :param handler: Handler for DbApiHook.run() to return results, defaults to fetch_all_handler + :param client_parameters: Additional parameters internal to Databricks SQL Connector parameters. Review Comment: Nit: lowercase "Connector" ########## airflow/providers/databricks/sensors/sql.py: ########## @@ -0,0 +1,131 @@ +# +# 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. +# +"""This module contains Databricks sensors.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence + +from airflow.compat.functools import cached_property +from airflow.providers.common.sql.hooks.sql import fetch_all_handler +from airflow.providers.databricks.hooks.databricks_sql import DatabricksSqlHook +from airflow.sensors.base import BaseSensorOperator +from airflow.exceptions import AirflowException + +if TYPE_CHECKING: + from airflow.utils.context import Context + + +class DatabricksSqlSensor(BaseSensorOperator): + """ + Sensor that runs a SQL query on Databricks. + + :param databricks_conn_id: Reference to :ref:`Databricks + connection id<howto/connection:databricks>` (templated), defaults to + DatabricksSqlHook.default_conn_name. + :param sql_warehouse_name: Optional name of Databricks SQL Warehouse. If not specified, ``http_path`` + must be provided as described below, defaults to None + :param http_path: Optional string specifying HTTP path of Databricks SQL Warehouse or All Purpose Cluster. Review Comment: Nit: cluster should be lowercase. ########## docs/apache-airflow-providers-databricks/operators/sql.rst: ########## @@ -84,3 +84,39 @@ An example usage of the DatabricksSqlOperator to perform statements from a file :language: python :start-after: [START howto_operator_databricks_sql_multiple_file] :end-before: [END howto_operator_databricks_sql_multiple_file] + + +DatabricksSqlSensor +=================== + +Use the :class:`~airflow.providers.databricks.sensors.sql.DatabricksSqlSensor` to run the sensor +for a specific Delta table on a Databricks SQL workspace. + +Using the Sensor +---------------- + +The sensor executes the SQL statement supplied by the user. The only required parameters are: + +* ``sql`` - SQL query to execute for the sensor. + +* One of ``sql_endpoint_name`` (name of Databricks SQL endpoint to use) or ``http_path`` (HTTP path for Databricks SQL endpoint or Databricks cluster). Review Comment: Warehouse? -- 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]
