simond commented on a change in pull request #9023:
URL: https://github.com/apache/airflow/pull/9023#discussion_r432392613



##########
File path: airflow/providers/snowflake/operators/snowflake_to_slack.py
##########
@@ -0,0 +1,152 @@
+# 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 typing import Iterable, Optional
+
+from pandas import DataFrame
+from tabulate import tabulate
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.slack.hooks.slack_webhook import SlackWebhookHook
+from airflow.providers.snowflake.hooks.snowflake import SnowflakeHook
+from airflow.utils.decorators import apply_defaults
+
+
+class SnowflakeToSlackOperator(BaseOperator):
+    """
+    Executes an SQL statement in Snowflake and sends the results to Slack. The 
results of the query are
+    rendered into the 'slack_message' parameter as a Pandas dataframe using a 
JINJA variable called '{{
+    results_df }}'. The 'results_df' variable name can be changed by specifing 
a different
+    'results_df_name' parameter. The Tabulate library is added to the JINJA 
environment as a filter to
+    allow the dataframe to be rendered nicely. For example, set 
'slack_message' to {{ results_df |
+    tabulate(tablefmt="pretty", headers="keys") }} to send the results to 
Slack as an ascii rendered table.
+
+
+    :param snowflake_conn_id: The Snowflake connection id
+    :type snowflake_conn_id: str
+    :param sql: The SQL statement to execute on Snowflake (templated)
+    :type sql: str
+    :param results_df_name: The name of the JINJA template's dataframe 
variable, default is 'results_df'
+    :type results_df_name: str
+    :param parameters: The parameters to pass to the SQL query
+    :type parameters: mapping or iterable
+    :param warehouse: The Snowflake virtual warehouse to use to run the SQL 
query
+    :type warehouse: str
+    :param database: The Snowflake database to use for the SQL query
+    :type database: str
+    :param schema: The schema to run the SQL against in Snowflake
+    :type schema: str
+    :param role: The role to use when connecting to Snowflake
+    :type role: str
+    :param slack_conn_id: The connection id for Slack
+    :type slack_conn_id: str
+    :param slack_token: The token to use to authenticate to Slack. If this is 
not provided, the
+        'webhook_token' attribute needs to be specified in the 'Extra' JSON 
field against the slack_conn_id
+    :type slack_token: str
+    :param slack_message: The templated Slack message to send with the data 
returned from Snowflake.
+        You can use the default JINJA variable {{ results_df }} to access the 
pandas dataframe containing the
+        SQL results
+    :type slack_message: str
+    """
+    template_fields = ['sql', 'slack_message']
+    template_ext = ['.sql', '.jinja', '.j2']
+    times_rendered = 0
+
+    # pylint: disable=too-many-arguments

Review comment:
       oops, I'll fix this thanks!




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

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


Reply via email to