pateash commented on code in PR #25714:
URL: https://github.com/apache/airflow/pull/25714#discussion_r977688554


##########
airflow/providers/clickhouse/operators/clickhouse.py:
##########
@@ -0,0 +1,72 @@
+#
+# 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 TYPE_CHECKING, Any, Callable, Dict, Optional, Sequence
+
+from airflow.models import BaseOperator
+from airflow.providers.clickhouse.hooks.clickhouse import ClickHouseHook
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class ClickHouseOperator(BaseOperator):
+    """
+    Executes SQL query in a ClickHouse database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:ClickHouseOperator`
+
+    :param sql: the SQL query to be executed. Can receive a str representing a
+        SQL statement, or you can provide .sql file having the query
+    :param params: substitution parameters for SELECT queries and data for 
INSERT queries.
+    :param database: database to query, if not provided schema from Connection 
will be used (optional)
+    :param result_processor: function to further process the Result from 
ClickHouse
+    :param clickhouse_conn_id: Reference to
+        :ref:`ClickHouse connection id<howto/connection:clickhouse>`.
+    """
+
+    template_fields: Sequence[str] = ('sql',)
+
+    template_ext: Sequence[str] = (".sql",)
+    template_fields_renderers = {"sql": "sql"}
+    ui_color = '#ebcc34'
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        clickhouse_conn_id: str = 'clickhouse_default',
+        params: Optional[Dict[str, Any]] = None,
+        database: Optional[str] = None,
+        result_processor: Optional[Callable] = None,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.clickhouse_conn_id = clickhouse_conn_id
+        self.sql = sql
+        self.params = params
+        self.database = database
+        self.result_processor = result_processor
+
+    def execute(self, context: 'Context'):
+        hook = ClickHouseHook(clickhouse_conn_id=self.clickhouse_conn_id, 
database=self.database)
+
+        result = hook.query(sql=self.sql, params=self.params)
+        if self.result_processor:
+            self.result_processor(result)

Review Comment:
   result process is a callback which could be passed by the user to proess the 
result similar to arangodb provider.



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

Reply via email to