data_source.py 1012 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from dataclasses import dataclass
  10. @dataclass(unsafe_hash=True)
  11. class DataSource:
  12. table_index: int | None = None
  13. custom_db_object_name: str | None = None
  14. def get_db_object_name(
  15. self,
  16. base_name: str,
  17. ) -> str:
  18. if self.custom_db_object_name is not None:
  19. return self.custom_db_object_name
  20. table_index_suffix = (
  21. f"_{self.table_index}" if self.table_index is not None else ""
  22. )
  23. return f"{base_name}{table_index_suffix}"
  24. def alias(self) -> str:
  25. if self.table_index is None:
  26. return "s"
  27. return f"s{self.table_index}"