entities.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. """Defines base entities used for providing lineage information."""
  19. from __future__ import annotations
  20. from typing import Any, ClassVar
  21. import attr
  22. @attr.s(auto_attribs=True)
  23. class File:
  24. """File entity. Refers to a file."""
  25. template_fields: ClassVar = ("url",)
  26. url: str = attr.ib()
  27. type_hint: str | None = None
  28. @attr.s(auto_attribs=True, kw_only=True)
  29. class User:
  30. """User entity. Identifies a user."""
  31. email: str = attr.ib()
  32. first_name: str | None = None
  33. last_name: str | None = None
  34. template_fields: ClassVar = ("email", "first_name", "last_name")
  35. @attr.s(auto_attribs=True, kw_only=True)
  36. class Tag:
  37. """Tag or classification entity."""
  38. tag_name: str = attr.ib()
  39. template_fields: ClassVar = ("tag_name",)
  40. @attr.s(auto_attribs=True, kw_only=True)
  41. class Column:
  42. """Column of a Table."""
  43. name: str = attr.ib()
  44. description: str | None = None
  45. data_type: str = attr.ib()
  46. tags: list[Tag] = []
  47. template_fields: ClassVar = ("name", "description", "data_type", "tags")
  48. # this is a temporary hack to satisfy mypy. Once
  49. # https://github.com/python/mypy/issues/6136 is resolved, use
  50. # `attr.converters.default_if_none(default=False)`
  51. def default_if_none(arg: bool | None) -> bool:
  52. """Get default value when None."""
  53. return arg or False
  54. @attr.s(auto_attribs=True, kw_only=True)
  55. class Table:
  56. """Table entity."""
  57. database: str = attr.ib()
  58. cluster: str = attr.ib()
  59. name: str = attr.ib()
  60. tags: list[Tag] = []
  61. description: str | None = None
  62. columns: list[Column] = []
  63. owners: list[User] = []
  64. extra: dict[str, Any] = {}
  65. type_hint: str | None = None
  66. template_fields: ClassVar = (
  67. "database",
  68. "cluster",
  69. "name",
  70. "tags",
  71. "description",
  72. "columns",
  73. "owners",
  74. "extra",
  75. )