You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/03/27 12:20:08 UTC

[GitHub] [airflow] eladkal commented on a change in pull request #22548: WIP: Add Arango hook

eladkal commented on a change in pull request #22548:
URL: https://github.com/apache/airflow/pull/22548#discussion_r835898414



##########
File path: airflow/providers/arangodb/sensors/arangodb.py
##########
@@ -0,0 +1,55 @@
+#
+# 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, Sequence
+
+from airflow.providers.arangodb.hooks.arangodb import ArangoDBHook
+from airflow.sensors.base import BaseSensorOperator
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class AQLSensor(BaseSensorOperator):
+    """
+    Checks for the existence of a document which
+    matches the given query in ArangoDB. Example:
+
+    :param collection: Target DB collection.
+    :param query: The query to find the target document.
+    :param arangodb_conn_id: The :ref:`ArangoDB connection id <howto/connection:arangodb>` to use
+        when connecting to ArangoDB.
+    :param arangodb_db: Target ArangoDB name.
+    """
+
+    template_fields: Sequence[str] = ('sql',)

Review comment:
       Should we add also `template_ext`?

##########
File path: airflow/providers/arangodb/example_dags/example_arangodb.py
##########
@@ -0,0 +1,59 @@
+# 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.
+import logging
+from datetime import datetime
+from typing import Any, Optional
+
+from github import GithubException
+
+from airflow import AirflowException

Review comment:
       Please check the imports. You have 3 unused imports

##########
File path: airflow/providers/arangodb/operators/arangodb.py
##########
@@ -0,0 +1,61 @@
+#
+# 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, Optional, Sequence, Callable
+
+from airflow.models import BaseOperator
+from airflow.providers.arangodb.hooks.arangodb import ArangoDBHook
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class AQLOperator(BaseOperator):
+    """
+    Executes AQL query in a ArangoDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:AQLOperator`
+
+    :param sql: the AQL query to be executed. Can receive a str representing a
+        sql statement
+    :param result_processor: function to further process the Result from ArangoDB
+    :param arangodb_conn_id: Reference to :ref:`ArangoDB connection id <howto/connection:arangodb>`.
+    """
+
+    template_fields: Sequence[str] = ('sql',)

Review comment:
       Should we add also `template_ext`?

##########
File path: airflow/providers/arangodb/hooks/arangodb.py
##########
@@ -0,0 +1,107 @@
+#
+# 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 allows connecting to a ArangoDB."""
+from typing import Dict, Optional, Any
+
+from arango import ArangoClient as ArangoDBClient, AQLQueryExecuteError
+from arango.result import Result
+
+from airflow import AirflowException
+from airflow.hooks.base import BaseHook
+
+
+class ArangoDBHook(BaseHook):

Review comment:
       Can we expose also `create_database`, `create_collection`, `create_graph` from the python lib?
   These are all very simple 1-2 line functions I believe




-- 
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-unsubscribe@airflow.apache.org

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