multi_mz_executors.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 materialize.output_consistency.execution.evaluation_strategy import (
  10. EvaluationStrategy,
  11. EvaluationStrategyKey,
  12. )
  13. from materialize.output_consistency.execution.sql_executor import SqlExecutor
  14. from materialize.output_consistency.execution.sql_executors import SqlExecutors
  15. class MultiMzSqlExecutors(SqlExecutors):
  16. def __init__(self, executor1: SqlExecutor, executor2: SqlExecutor):
  17. super().__init__(executor1)
  18. self.executor2 = executor2
  19. def get_executor(self, strategy: EvaluationStrategy) -> SqlExecutor:
  20. if strategy.identifier in [
  21. EvaluationStrategyKey.MZ_DATAFLOW_RENDERING_OTHER_DB,
  22. EvaluationStrategyKey.MZ_CONSTANT_FOLDING_OTHER_DB,
  23. ]:
  24. return self.executor2
  25. return super().get_executor(strategy)
  26. def get_database_infos(self) -> str:
  27. return (
  28. f"Using {self.executor.name} in version '{self.executor.query_version()}'. "
  29. f"Using {self.executor2.name} in version '{self.executor2.query_version()}'."
  30. )
  31. def uses_different_versions(self) -> bool:
  32. return self.executor.query_version() != self.executor2.query_version()