-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Airflow Data Quality Provider Plugin #69413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
253e970
05368ae
1fcb52a
7879a83
37e98ea
67ad2a1
75ca3b7
4ecff34
ac51983
9f83f2d
d6f5438
3297351
c008d63
e221004
0394a1f
b8c50fe
d4f96f4
6af5e51
8f2f582
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -294,6 +294,7 @@ conda | |
| conf | ||
| Config | ||
| config | ||
| ConfigDict | ||
| configfile | ||
| configMap | ||
| configmap | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| www-hash.txt | ||
| *.iml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
| --- | ||
| default_stages: [pre-commit, pre-push] | ||
| minimum_prek_version: '0.3.4' | ||
| default_language_version: | ||
| python: python3 | ||
| node: 22.19.0 | ||
| golang: 1.24.0 | ||
| repos: | ||
| - repo: local | ||
| hooks: | ||
| - id: ts-compile-lint-common-dataquality-ui | ||
| name: Compile Data Quality UI | ||
| description: Type-check changed TypeScript files in the Data Quality plugin UI | ||
| language: node | ||
| files: | | ||
| (?x) | ||
| ^src/airflow/providers/common/dataquality/plugins/www/.*\.(js|ts|tsx|yaml|css|json)$ | ||
| exclude: | | ||
| (?x) | ||
| ^src/airflow/providers/common/dataquality/plugins/www/node-modules/.*| | ||
| ^src/airflow/providers/common/dataquality/plugins/www/.pnpm-store | ||
| entry: ../../../scripts/ci/prek/ts_compile_lint_common_dataquality.py | ||
| additional_dependencies: ['pnpm@10.25.0'] | ||
| pass_filenames: true | ||
| require_serial: true | ||
| - id: compile-common-dataquality-provider-assets | ||
| name: Compile Common Data Quality provider assets | ||
| language: node | ||
| stages: ['pre-commit', 'manual'] | ||
| files: ^src/airflow/providers/common/dataquality/plugins/www/ | ||
| entry: ../../../scripts/ci/prek/compile_provider_assets.py dataquality | ||
| pass_filenames: false | ||
| additional_dependencies: ['pnpm@10.25.0'] | ||
| - id: generate-common-dataquality-ruleset-schema | ||
| name: Generate Data Quality RuleSet schema | ||
| language: python | ||
| entry: ../../../scripts/ci/prek/generate_common_dataquality_ruleset_schema.py | ||
| pass_filenames: false | ||
| always_run: true | ||
| files: > | ||
| (?x) | ||
| ^src/airflow/providers/common/dataquality/rules/.*\.py$| | ||
| ^src/airflow/providers/common/dataquality/skills/dataquality-rule-authoring/references/ruleset\.schema\.json$ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
|
||
| .. _dq:agents: | ||
|
|
||
| Generating rules with an LLM | ||
| ============================== | ||
|
|
||
| Writing a :class:`~airflow.providers.common.dataquality.rules.RuleSet` by hand for every table doesn't scale. | ||
| An LLM can propose one from a table's column definitions instead, given the check catalog as | ||
| context. | ||
|
|
||
| The ``dataquality-rule-authoring`` skill | ||
| ---------------------------------------- | ||
|
|
||
| This provider ships an `Agent Skill <https://agentskills.io>`__ at | ||
| ``airflow/providers/common/dataquality/skills/dataquality-rule-authoring/``: a ``SKILL.md`` documenting the | ||
| ``RuleSet``/``DQRule`` fields and check catalog, plus a generated JSON Schema | ||
| (``references/ruleset.schema.json``) for validation. | ||
|
|
||
| Point ``common.ai``'s :doc:`AgentSkillsToolset <apache-airflow-providers-common-ai:toolsets>` at | ||
| it, and give the model ``output_type=RuleSet`` so pydantic-ai validates -- and self-corrects -- | ||
| its output before the task completes: | ||
|
|
||
| .. exampleinclude:: /../src/airflow/providers/common/dataquality/example_dags/example_dq_llm_generated_ruleset.py | ||
| :language: python | ||
| :start-after: [START howto_task_dq_generate_ruleset_with_llm] | ||
| :end-before: [END howto_task_dq_generate_ruleset_with_llm] | ||
|
|
||
| Requires ``apache-airflow-providers-common-ai[skills]`` and a configured ``llm_conn_id``. | ||
|
|
||
| Wiring the result into a check | ||
| --------------------------------- | ||
|
|
||
| ``@task.dq_check`` can leave ``ruleset=`` unset and return the LLM task's result at execution | ||
| time instead: | ||
|
|
||
| .. exampleinclude:: /../src/airflow/providers/common/dataquality/example_dags/example_dq_llm_generated_ruleset.py | ||
| :language: python | ||
| :start-after: [START howto_decorator_dq_check_llm_runtime_ruleset] | ||
| :end-before: [END howto_decorator_dq_check_llm_runtime_ruleset] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| .. 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. | ||
|
|
||
| .. _dq:assets: | ||
|
|
||
| Assets and quality gating | ||
| ============================ | ||
|
|
||
| Quality rules can travel with the :class:`~airflow.sdk.Asset` they describe instead of being | ||
| scattered across every Dag that checks it, and a downstream consumer Dag can refuse to run when | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a big fan of describing random bad practices that the code replaces. I suggest
|
||
| the data it was triggered by did not meet a minimum quality bar. | ||
|
|
||
| Attaching a ruleset to an asset | ||
| ---------------------------------- | ||
|
|
||
| :func:`~airflow.providers.common.dataquality.assets.asset_quality` stores ruleset, connection, and table | ||
| configuration inside ``Asset.extra`` under the ``airflow.dataquality`` key, so it is serialized with the | ||
| Dag and needs no Airflow core changes: | ||
|
|
||
| .. exampleinclude:: /../src/airflow/providers/common/dataquality/example_dags/example_dq_require_quality.py | ||
| :language: python | ||
| :start-after: [START howto_asset_quality] | ||
| :end-before: [END howto_asset_quality] | ||
|
|
||
| Pass the resulting asset to :class:`~airflow.providers.common.dataquality.operators.dq_check.DQCheckOperator` | ||
| via ``asset=`` (see :doc:`operators`) instead of ``table``/``ruleset``/``conn_id``: the operator | ||
| resolves all three from the asset's config, adds the asset to its own outlets, and attaches its | ||
| summary -- including the quality ``score`` used below -- to the asset event. | ||
|
|
||
| Only one Dag should call ``asset_quality()`` for a given asset ``name``/``uri``. Airflow keeps one | ||
| shared record per asset across all Dags, so if more than one Dag attaches (or omits) config for the | ||
| same asset, whichever Dag parsed most recently determines what's stored. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this preferred over a loud dag parse error? |
||
|
|
||
| Gating a consumer Dag on quality | ||
| ------------------------------------ | ||
|
|
||
| :func:`~airflow.providers.common.dataquality.assets.require_quality` builds a ``@task.short_circuit`` task that | ||
| reads the ``score`` off the asset event that triggered the current run, and skips every | ||
| downstream task when that event has no quality summary at all, or its score is below | ||
| ``min_score``: | ||
|
|
||
| .. exampleinclude:: /../src/airflow/providers/common/dataquality/example_dags/example_dq_require_quality.py | ||
| :language: python | ||
| :start-after: [START howto_require_quality] | ||
| :end-before: [END howto_require_quality] | ||
|
|
||
| Put the gate first in a Dag scheduled by the asset, and chain everything else after it: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| with DAG("orders_consumer", schedule=orders_asset) as consumer: | ||
| gate = require_quality(orders_asset, min_score=0.95) | ||
| gate >> process_orders() | ||
|
|
||
| ``min_score`` must be between ``0`` and ``1``; the check considers only the *most recent* | ||
| triggering event for the asset when a run was triggered by several. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| .. 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. | ||
|
|
||
| .. include:: /../../../../devel-common/src/sphinx_exts/includes/providers-configurations-ref.rst | ||
| .. include:: /../../../../devel-common/src/sphinx_exts/includes/sections-and-options.rst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a middle ground between "by hand" and "via LLM" - deterministic scripts. This also allows users w/o LLM access to use the tools. These can be bundled into the SKILL or placed somewhere in the plugin.