question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[AIP-31] Create XComArg model

See original GitHub issue

Description

XComArg is a class that references an XCom entry from an operator. Can be used to explicitly set XCom dependencies and explictly pass results between operators.

Class attributes:

  • operator: BaseOperator: Origin operator instance.
  • key: str: Stores key for XCom value. Defaults to airflow.models.xcom. XCOM_RETURN_KEY

Class methods

  • get(context: dict)-> Any: Resolves XCom value given operator and key.
  • __getitem__(key, str) -> XComArg: Easy method to create new XComArg using the same operator but a different key.
  • add_downstream_dependent(operator: BaseOperator)->None: Add an operator as a downstream dependency of operator. [Optional] Makes this task simpler.

Proposed implementation: https://github.com/casassg/corrent/blob/master/corrent/xcom_arg.py

Use case / motivation

  • Explicit way to pass around results between operators.
  • This object is a reference to an XCom value that has not been created and will need to be resolved in the future.
  • It can generate new XComArgs that point to the same operator but has a different key by using the key accessor. E.g: output[‘train’].
  • To do so, it includes as class attributes both the originating operator instance and a key (both needed to pull the XCom).
  • Has a property op that allows access to the origin operator.

Stretch goal

  • Store type class for the XCom and lie to MyPy when trying to check class signature.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
jonathanshircommented, Apr 22, 2020

Hey guys, the databand team and I decided to implement [AIP-31] starting tomorrow. Will be in touch with you soon for implementation discussions. Thanks, Johnny 😃

1reaction
evgenyshulmancommented, Apr 25, 2020

it’s definitely an option for people who wants a “purely function” approach from the beginning. Most of Airflow users are already very invested in the current implementation without functional operators.

  1. They will have to rewrite their current implementation ( extract into function with @task).
  2. In case it’s part of internal operator implementation it’s even harder to do
  3. It will affect an execution graph (extra node), while some Airflow users are trying to keep graph very clean.

IMHO: ( as I wrote at current PR), we should decide before we push implementation into Airflow/master and we should base our decision on some examples we wrote with end to end usage of AIP-31 implementation. I see a point in keeping everything as simple as possible, at the same time, I want all users to be happy if it doesn’t affect implementation in a bad way 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

airflow.models.xcom_arg — Airflow Documentation
This is used to determine how many task instances the scheduler should create for a downstream using this XComArg for task-mapping.
Read more >
Airflow 2.0: DAG Authoring Redesigned
TaskFlow API (AIP-31). The first significant change is the introduction of TaskFlow API. This new thing consists of three features: XComArg — a...
Read more >
July 10, 2020
AIP-31 : Airflow functional ... Ex: model training metrics. ... BaseOperator property to generate default XComArg: .output.
Read more >
Streamline Pipeline Code with Functional DAGs in Airflow 2.0
Here is Databand's intro to AIP-31, a guide for data engineers on how ... for quickly creating complex pipelines with many chains of...
Read more >
[AIRFLOW-8057] [AIP-31] Add @task decorator
_called = True + return XComArg(self) + + def copy(self, task_id: Optional[str] = None, **kwargs): + """ + Create a copy of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found