操作符

您可以在 ArangoDBHook 中构建自己的 Operator Hook。

使用 AQLOperatorArangoDB 中执行 AQL 查询。

您可以使用 AQLOperator 对结果进行进一步处理,并根据需要使用 result_processor 可调用对象进行自定义处理。

以下示例演示如何列出 students 集合中的所有文档。

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

您也可以提供文件模板 (.sql) 来加载查询,请记住路径相对于 dags/ 文件夹;如果想使用其他路径,请在创建 Dag 对象时提供 template_searchpath 参数,

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",
)

传感器

使用 AQLSensor 通过 AQL 查询等待文档或集合在 ArangoDB 中出现。

以下示例演示如何等待 students 集合中学生姓名为 judy 的文档。

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,
)

类似于 AQLOperator,您也可以提供文件模板来加载查询 -

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,
)

此条目是否有帮助?