Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/providers/openlineage/plugins/macros.py: 0%

13 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:35 +0000

1# Licensed to the Apache Software Foundation (ASF) under one 

2# or more contributor license agreements. See the NOTICE file 

3# distributed with this work for additional information 

4# regarding copyright ownership. The ASF licenses this file 

5# to you under the Apache License, Version 2.0 (the 

6# "License"); you may not use this file except in compliance 

7# with the License. You may obtain a copy of the License at 

8# 

9# http://www.apache.org/licenses/LICENSE-2.0 

10# 

11# Unless required by applicable law or agreed to in writing, 

12# software distributed under the License is distributed on an 

13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 

14# KIND, either express or implied. See the License for the 

15# specific language governing permissions and limitations 

16# under the License. 

17from __future__ import annotations 

18 

19import os 

20import typing 

21 

22from airflow.configuration import conf 

23from airflow.providers.openlineage.plugins.adapter import OpenLineageAdapter 

24 

25if typing.TYPE_CHECKING: 

26 from airflow.models import TaskInstance 

27 

28_JOB_NAMESPACE = conf.get("openlineage", "namespace", fallback=os.getenv("OPENLINEAGE_NAMESPACE", "default")) 

29 

30 

31def lineage_run_id(task_instance: TaskInstance): 

32 """ 

33 Macro function which returns the generated run id for a given task. This 

34 can be used to forward the run id from a task to a child run so the job 

35 hierarchy is preserved. 

36 

37 .. seealso:: 

38 For more information on how to use this operator, take a look at the guide: 

39 :ref:`howto/macros:openlineage` 

40 """ 

41 return OpenLineageAdapter.build_task_instance_run_id( 

42 task_instance.task.task_id, task_instance.execution_date, task_instance.try_number 

43 ) 

44 

45 

46def lineage_parent_id(run_id: str, task_instance: TaskInstance): 

47 """ 

48 Macro function which returns the generated job and run id for a given task. This 

49 can be used to forward the ids from a task to a child run so the job 

50 hierarchy is preserved. Child run can create ParentRunFacet from those ids. 

51 

52 .. seealso:: 

53 For more information on how to use this macro, take a look at the guide: 

54 :ref:`howto/macros:openlineage` 

55 """ 

56 job_name = OpenLineageAdapter.build_task_instance_run_id( 

57 task_instance.task.task_id, task_instance.execution_date, task_instance.try_number 

58 ) 

59 return f"{_JOB_NAMESPACE}/{job_name}/{run_id}"