Repository navigation
Description
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
Activity
[-]Allow DAGs to trigger on Datasets with wildcard[/-][+]Allow DAGs to trigger on Datasets with wildcard/regex[/+]lotrias17 commentedon Apr 22, 2024
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.
lotrias17 commentedon Apr 22, 2024
Also, we would be very grateful for any guidance from anyone if possible.
kovla commentedon Apr 22, 2024
The original proposal seconded.
Lee-W commentedon Apr 30, 2024
Hi @lotrias17, I just assigned this one to you. I can not assign it to @TiDeane. Once a comment has been left from @TiDeane, I should be able to assign it
Lee-W commentedon Apr 30, 2024
@sunank200 As you submitted a bunch of dataset related PRs these days, I think you might be interested in join the discussion 🙂
TiDeane commentedon Apr 30, 2024
Hello, just commenting so you can assign me as well @Lee-W. I'm going to be working on this with @lotrias17.
Lee-W commentedon Apr 30, 2024
Just assigned @TiDeane . Thanks
!
lotrias17 commentedon May 18, 2024
We are running into problems with Session. How could we initialize a session in a function inside class DAG (in models/dag.py), with the intention of searching the db for the datasets related to the DAG? Thank you in advance.
2 remaining items
TiDeane commentedon Jun 14, 2024
We haven't been able to get much progress on this feature, so unfortunately we're going to drop it so others with more experience can pick it up. We're very sorry, and hope for the best for future contributors.
sjyangkevin commentedon Apr 28, 2025
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.
potiuk commentedon Apr 28, 2025
Feel free. That's a good motivation to contribute :)
sjyangkevin commentedon May 4, 2025
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
sjyangkevin commentedon May 4, 2025
Link the asset alias with the asset event and propagate information to consumer task, accessing through
triggering_asset_eventsvia context.Asset


/raw/data/file_05032025.csvcreated at runtime, and event attached to alias can be accessed by consumer task.Asset
/raw/data/file_05042025.csvcreated at runtime, and event attached to alias can be accessed by consumer task.In this way, producer task can dynamically generate asset, and attached the asset event to the alias, using alias as outlets. Consumer DAG can be scheduled on a single asset alias, and gather information about those dynamically created asset.
sjyangkevin commentedon May 5, 2025
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!
#50182
Lee-W commentedon May 6, 2025
Do you mean
extra? I think they're there. Just not included in the__repr__.Also, you'll need to actally access the inlets.
e.g.,
sounds reasonable to me
inlet_eventsshould be fine. Butinlet_eventsis not something used to triggered a dag. It's more like an extra infomration a dag can requested from the history.triggering_asset_eventsshould probably be fine as well 🤔kind of? depends on what kind of information. this is how we request the asset event history for a specific asset. e.g., the following logic is implemented here
sounds reasonable to me
sjyangkevin commentedon May 6, 2025
Thank you very much for the followup. Sorry for writing a very long text trying to explain my thinking. Please let me know if there is any follow up questions.
I want to explain it using my DAG code and logs. From what I understand the use case, each event will be mapped to an asset respectively. Suppose I have three file drop events pulled by the producer DAG and it generates three different assets.
file_A_2025-05-03->Asset(name='file_A_2025-05-03')file_A_2025-05-04->Asset(name='file_A_2025-05-04')file_A_2025-05-05->Asset(name='file_A_2025-05-05')I think the original objective is to have the consumer DAG trigger on updates to
Asset(name='file_A_{year}-{month}-{day}'), but asset name doesn't support regex kind of definition. After a few experiments, I found that we can createAssets and attached the corresponding asset event to the Asset Alias defined throughoutlet_events. The consumer DAG can then be triggered on the Asset Alias. In this way, the producer DAG can define regex/wildcard matching (through DAG code) and create an asset event on match. Please see the DAG code below for my experiment. Now come to the question:TL;DR
The
extraseems only available for DAG trigger onAssetbut not available for DAG trigger onAssetAlias.In the consumer task, I tried to access the
inlet_eventsand thetriggering_asset_events, and wasn't able to see either theAssetor theAssetEeventattached to theAssetAlias, as shown above. These information seems only available when the DAG is triggered onAsset, as shown in the screenshot below.Why the asset event or asset information matter in this case?
It can be thought as a work around to implement the requirements in a simplified way. When the consumer task can access the asset event, suppose a file drop create
Asset(name='file_A_2025-05-04')and attach to the Asset Alias. Downstream task trigger on the alias can fetch the asset'sname,uri, or evenextrafrom thetriggering_asset_eventsfrom context. In this way, for each consumer DAG Run triggered by the event on the asset alias, the consumer task can access the corresponding asset event and process on the correct file drop. This might also answer: #50182 (review).Producer DAG
Consumer DAG
sjyangkevin commentedon May 6, 2025
I also want to attach an example when the
AssetandAssetAliasare used in joint. After the code change #50182, the asset event is available for DAG trigger on alias, by accessingtriggering_asset_events.Consumer DAG