jedcunningham commented on code in PR #38821: URL: https://github.com/apache/airflow/pull/38821#discussion_r1558815849
########## airflow/example_dags/example_dataset_event_extra.py: ########## @@ -0,0 +1,93 @@ +# 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. + +""" +Example DAG to demonstrate annotating a dataset event with extra information. +""" + +from __future__ import annotations + +import datetime + +from airflow.datasets import Dataset +from airflow.datasets.metadata import Metadata +from airflow.models.dag import DAG +from airflow.operators.bash import BashOperator + +ds = Dataset("s3://output/1.txt") + +with DAG( + dag_id="produce_with_yield", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: + + @dag.task(outlets=[ds]) + def produce(): + yield Metadata(ds, {"hi": "bye"}) + + produce() + +with DAG( + dag_id="produce_with_context", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: + + @dag.task(outlets=[ds]) + def produce(*, dataset_events): + dataset_events[ds].extra = {"hi": "bye"} + + produce() + +with DAG( + dag_id="produce_classic_from_execute", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +): + + class EmittingBashOperator(BashOperator): Review Comment: I'm a little hesitant to show this approach in an example DAG. Feels too low level. If this is the right approach for folks, they probably don't need the example in the first place? ########## airflow/example_dags/example_dataset_event_extra.py: ########## @@ -0,0 +1,93 @@ +# 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. + +""" +Example DAG to demonstrate annotating a dataset event with extra information. +""" + +from __future__ import annotations + +import datetime + +from airflow.datasets import Dataset +from airflow.datasets.metadata import Metadata +from airflow.models.dag import DAG +from airflow.operators.bash import BashOperator + +ds = Dataset("s3://output/1.txt") + +with DAG( + dag_id="produce_with_yield", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: + + @dag.task(outlets=[ds]) + def produce(): + yield Metadata(ds, {"hi": "bye"}) + + produce() + +with DAG( + dag_id="produce_with_context", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: Review Comment: ```suggestion ): ``` ########## airflow/example_dags/example_dataset_event_extra.py: ########## @@ -0,0 +1,93 @@ +# 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. + +""" +Example DAG to demonstrate annotating a dataset event with extra information. +""" + +from __future__ import annotations + +import datetime + +from airflow.datasets import Dataset +from airflow.datasets.metadata import Metadata +from airflow.models.dag import DAG +from airflow.operators.bash import BashOperator + +ds = Dataset("s3://output/1.txt") + +with DAG( + dag_id="produce_with_yield", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: + + @dag.task(outlets=[ds]) + def produce(): + yield Metadata(ds, {"hi": "bye"}) + + produce() + +with DAG( + dag_id="produce_with_context", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], Review Comment: ```suggestion tags=["produces"], ``` ########## airflow/example_dags/example_dataset_event_extra.py: ########## @@ -0,0 +1,93 @@ +# 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. + +""" +Example DAG to demonstrate annotating a dataset event with extra information. +""" + +from __future__ import annotations + +import datetime + +from airflow.datasets import Dataset +from airflow.datasets.metadata import Metadata +from airflow.models.dag import DAG +from airflow.operators.bash import BashOperator + +ds = Dataset("s3://output/1.txt") + +with DAG( + dag_id="produce_with_yield", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: Review Comment: ```suggestion ): ``` ########## airflow/example_dags/example_dataset_event_extra.py: ########## @@ -0,0 +1,93 @@ +# 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. + +""" +Example DAG to demonstrate annotating a dataset event with extra information. +""" + +from __future__ import annotations + +import datetime + +from airflow.datasets import Dataset +from airflow.datasets.metadata import Metadata +from airflow.models.dag import DAG +from airflow.operators.bash import BashOperator + +ds = Dataset("s3://output/1.txt") + +with DAG( + dag_id="produce_with_yield", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], Review Comment: ```suggestion tags=["produces"], ``` Not a dataset scheduled dag. Might be better with no tags? ########## airflow/example_dags/example_dataset_event_extra.py: ########## @@ -0,0 +1,93 @@ +# 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. + +""" +Example DAG to demonstrate annotating a dataset event with extra information. +""" + +from __future__ import annotations + +import datetime + +from airflow.datasets import Dataset +from airflow.datasets.metadata import Metadata +from airflow.models.dag import DAG +from airflow.operators.bash import BashOperator + +ds = Dataset("s3://output/1.txt") + +with DAG( + dag_id="produce_with_yield", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: + + @dag.task(outlets=[ds]) + def produce(): + yield Metadata(ds, {"hi": "bye"}) + + produce() + +with DAG( + dag_id="produce_with_context", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: + + @dag.task(outlets=[ds]) + def produce(*, dataset_events): + dataset_events[ds].extra = {"hi": "bye"} + + produce() + +with DAG( + dag_id="produce_classic_from_execute", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +): + + class EmittingBashOperator(BashOperator): + def execute(self, context): + result = super().execute(context) + context["dataset_events"].extra = {"hi": "bye"} + return result + + EmittingBashOperator(task_id="produce", outlets=[ds], bash_command=":") + +with DAG( + dag_id="produce_classic_from_task_hook", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], Review Comment: ```suggestion tags=["produces"], ``` ########## airflow/example_dags/example_dataset_event_extra.py: ########## @@ -0,0 +1,93 @@ +# 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. + +""" +Example DAG to demonstrate annotating a dataset event with extra information. +""" + +from __future__ import annotations + +import datetime + +from airflow.datasets import Dataset +from airflow.datasets.metadata import Metadata +from airflow.models.dag import DAG +from airflow.operators.bash import BashOperator + +ds = Dataset("s3://output/1.txt") + +with DAG( + dag_id="produce_with_yield", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: + + @dag.task(outlets=[ds]) + def produce(): + yield Metadata(ds, {"hi": "bye"}) + + produce() + +with DAG( + dag_id="produce_with_context", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], +) as dag: + + @dag.task(outlets=[ds]) + def produce(*, dataset_events): + dataset_events[ds].extra = {"hi": "bye"} + + produce() + +with DAG( + dag_id="produce_classic_from_execute", + catchup=False, + start_date=datetime.datetime.min, + schedule="@daily", + tags=["produces", "dataset-scheduled"], Review Comment: ```suggestion tags=["produces"], ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
