Operators

You can build your own Operator hook in ArangoDBHook.

Use the AQLOperator to execute AQL query in ArangoDB.

You can further process your result using AQLOperator and further process the result using result_processor Callable as you like.

An example of Listing all Documents in students collection can be implemented as following:

airflow/providers/arangodb/example_dags/example_arangodb.py[source]


operator = AQLOperator(
    task_id="aql_operator",
    query="FOR doc IN students RETURN doc",
    dag=dag,
    result_processor=lambda cursor: print([document["name"] for document in cursor]),
)

You can also provide file template (.sql) to load query, remember path is relative to dags/ folder, if you want to provide any other path please provide template_searchpath while creating DAG object,

airflow/providers/arangodb/example_dags/example_arangodb.py[source]


operator2 = AQLOperator(
    task_id="aql_operator_template_file",
    dag=dag,
    result_processor=lambda cursor: print([document["name"] for document in cursor]),
    query="search_all.sql",
)

Sensors

Use the AQLSensor to wait for a document or collection using AQL query in ArangoDB.

An example for waiting a document in students collection with student name judy can be implemented as following:

airflow/providers/arangodb/example_dags/example_arangodb.py[source]


sensor = AQLSensor(
    task_id="aql_sensor",
    query="FOR doc IN students FILTER doc.name == 'judy' RETURN doc",
    timeout=60,
    poke_interval=10,
    dag=dag,
)

Similar to AQLOperator, You can also provide file template to load query -

airflow/providers/arangodb/example_dags/example_arangodb.py[source]


sensor2 = AQLSensor(
    task_id="aql_sensor_template_file",
    query="search_judy.sql",
    timeout=60,
    poke_interval=10,
    dag=dag,
)

Was this entry helpful?