airflow: Allow DAGs to trigger on Datasets with wildcard/regex
Description
I would like to have the possibility to have a DAG trigger on ANY dataset matching a wildcard/regex.
Use case/motivation
We have 2 (similar) use cases.
Trigger ingestion process on file arrival.
Files land in blob storage, which triggers events like:
{
"filename": "/raw/my/folder1/2024/04/15/file1.csv",
"event": "fileCreated"
}
and
{
"filename": "/raw/my/folder1/2024/04/15/file1.json",
"event": "fileCreated"
}
and
{
"filename": "/raw/my/folder1/2024/02/10/file1.json",
"event": "fileCreated"
}
These events are converted to Dataset update events, either by calling the Airflow API, or a DAG that polls a queue that contains the above events. In the above case, three Datasets would be updated:
ingestionblob://raw/my/folder1/2024/04/15/file1.csvingestionblob://raw/my/folder1/2024/04/15/file1.jsoningestionblob://raw/my/folder1/2024/02/10/file1.json
Image that we have a DAG ingestCSVFromRawRealTime. I would like to be able to trigger that DAG on datasets with wildcards ingestionblob://raw/my/folder1/{today.year}/{today.month}/{today.day}/*.csv.
Similarly for some DAGs like ingestJsonFromRawRealTime or ingestBackfilledCsvFromRaw.
Ideally, we can create capture groups in the regex of the Dataset trigger, and use these capture groups as DAG parameter.
Monitor database updates
Our (Databricks) DWH, like almost all other dbms’s, has a 3-level namespace: database.schema.table. We will create a mechanism to emit dataset events like
database1.bronze.table7database4.silver.view3database2.gold.streamingTable1- …
Sometimes, we want to be notified on updates to the whole database, schema or table. There are some use cases where having wildcard triggers would be beneficial:
- Airflow needs to trigger a
syncin our BI tool (eg. PowerBI, Tableau) if an object from thegoldschema indatabase2is updated. - When data arrived in the
bronzeschema, some curation scripts needs to be kicked-off to generate a ‘cleaned’ silver table.
Related issues
- 34534. But with the new logical operators for Datasets, we can already trigger on more than 1 dataset.
Are you willing to submit a PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 18 (17 by maintainers)
Feel free. That’s a good motivation to contribute 😃
The original proposal seconded.
Hello, could a colleague (@TiDeane) and I be assigned to this issue? We are working for a university project and would be grateful to implement this feature. Thank you in advance.
Hi @Lee-W , I opened a draft PR and want to get an early feedback. I still need to figure out how to run proper testing on my local environment and experiments with more scenarios of the use cases mentioned in the issue. Below is the link to the draft PR. Can I get your help to have a look on it? Thank you!
https://github.com/apache/airflow/pull/50182
Hi, I want to share some updates about the progress so far and also ask some questions. I would appreciate if anyone can provide me some feedback or suggestions.
Considering all the assets generated at runtime can actually be attached to an asset alias. The consumer task can treat the asset alias as a single “asset” and be triggered when a new asset is attached and updated by producer.
From my perspective, the use cases can be achieved by either being able to access the name or uri of the asset that is attached to the asset alias, or through the
extrakeyword from thetriggering_asset_eventsfrom thecontextin the consumer task.However, I’ve run some experiments, and found that these information are not propagated to either the
inlet_eventsor thetriggering_asset_events, as shown below the log from the consumer task.I actually attached the information in the
outlet_events, and below is the log from the producer task.In terms of implementation, I am trying to see if the following information can be accessible from the consumer task when the consumer DAG is triggered through asset alias.
AssetUniqueKey(name='/raw/data/file_05032025.csv', uri='/raw/data/file_05032025.csv')ininlet_events.extra={'filename': '/raw/data/file_05032025.csv'}intriggering_asset_events.Questions:
inlet_eventsandtriggering_asset_events?InletEventsAccessorsundertask-sdk/src/airflow/sdk/execution_time/context.py. Is it the right place to look at and modify the information being included ininlet_events?Below is what I think about why this approach can resolve the issue.
Below is my producer and consumer DAG code that generate the logs above. Thanks.
Producer
Consumer
Hi, could I be assigned to this issue? I am currently working on a project with the exact same use case. This feature will be helpful for a more flexible data-aware scheduling. Thanks.
Just assigned @TiDeane . Thanks !