Source code for airflow.providers.common.compat.lineage.entities
#
# 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.
"""Defines base entities used for providing lineage information."""
from __future__ import annotations
from typing import Any, ClassVar
import attr
@attr.s(auto_attribs=True)
[docs]
class File:
"""File entity. Refers to a file."""
[docs]
template_fields: ClassVar = ("url",)
[docs]
type_hint: str | None = None
@attr.s(auto_attribs=True, kw_only=True)
[docs]
class User:
"""User entity. Identifies a user."""
[docs]
first_name: str | None = None
[docs]
last_name: str | None = None
[docs]
template_fields: ClassVar = ("email", "first_name", "last_name")
@attr.s(auto_attribs=True, kw_only=True)
[docs]
class Tag:
"""Tag or classification entity."""
[docs]
tag_name: str = attr.ib()
[docs]
template_fields: ClassVar = ("tag_name",)
@attr.s(auto_attribs=True, kw_only=True)
[docs]
class Column:
"""Column of a Table."""
[docs]
description: str | None = None
[docs]
data_type: str = attr.ib()
[docs]
template_fields: ClassVar = ("name", "description", "data_type", "tags")
# this is a temporary hack to satisfy mypy. Once
# https://github.com/python/mypy/issues/6136 is resolved, use
# `attr.converters.default_if_none(default=False)`
[docs]
def default_if_none(arg: bool | None) -> bool:
"""Get default value when None."""
return arg or False
@attr.s(auto_attribs=True, kw_only=True)
[docs]
class Table:
"""Table entity."""
[docs]
database: str = attr.ib()
[docs]
cluster: str = attr.ib()
[docs]
description: str | None = None
[docs]
columns: list[Column] = []
[docs]
owners: list[User] = []
[docs]
type_hint: str | None = None
[docs]
template_fields: ClassVar = (
"database",
"cluster",
"name",
"tags",
"description",
"columns",
"owners",
"extra",
)