## 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."""Table to store information about mapped task instances (AIP-42)."""from__future__importannotationsimportcollections.abcimportenumfromtypingimportTYPE_CHECKING,Any,CollectionfromsqlalchemyimportCheckConstraint,Column,ForeignKeyConstraint,Integer,Stringfromairflow.models.baseimportCOLLATION_ARGS,ID_LEN,Basefromairflow.utils.sqlalchemyimportExtendedJSONifTYPE_CHECKING:fromairflow.models.taskinstanceimportTaskInstance
[docs]classTaskMapVariant(enum.Enum):"""Task map variant. Possible values are **dict** (for a key-value mapping) and **list** (for an ordered value sequence). """
[docs]classTaskMap(Base):"""Model to track dynamic task-mapping information. This is currently only populated by an upstream TaskInstance pushing an XCom that's pulled by a downstream for mapping purposes. """
[docs]deffrom_task_instance_xcom(cls,ti:TaskInstance,value:Collection)->TaskMap:ifti.run_idisNone:raiseValueError("cannot record task map for unrun task instance")returncls(dag_id=ti.dag_id,task_id=ti.task_id,run_id=ti.run_id,map_index=ti.map_index,length=len(value),keys=(list(value)ifisinstance(value,collections.abc.Mapping)elseNone),