query_output_mode.py 984 B

1234567891011121314151617181920212223242526272829303132
  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 enum import Enum
  10. class QueryOutputMode(Enum):
  11. SELECT = "select"
  12. EXPLAIN = "explain"
  13. EXPLAIN_PHYSICAL = "explain_physical"
  14. def __str__(self):
  15. return str(self.value).lower()
  16. QUERY_OUTPUT_MODE_CHOICES = list(QueryOutputMode)
  17. def query_output_mode_to_sql(mode: QueryOutputMode) -> str:
  18. if mode == QueryOutputMode.SELECT:
  19. return ""
  20. elif mode == QueryOutputMode.EXPLAIN:
  21. return "EXPLAIN"
  22. elif mode == QueryOutputMode.EXPLAIN_PHYSICAL:
  23. return "EXPLAIN PHYSICAL PLAN AS TEXT FOR"
  24. else:
  25. raise ValueError(f"Unsupported mode: {mode}")