rename_cluster.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 textwrap import dedent
  10. from materialize.checks.actions import Testdrive
  11. from materialize.checks.checks import Check
  12. class RenameCluster(Check):
  13. def manipulate(self) -> list[Testdrive]:
  14. return [
  15. Testdrive(dedent(s))
  16. for s in [
  17. """
  18. > CREATE TABLE rename_cluster1_table (f1 INTEGER);
  19. > CREATE TABLE rename_cluster2_table (f1 INTEGER);
  20. > INSERT INTO rename_cluster1_table VALUES (123);
  21. > INSERT INTO rename_cluster2_table VALUES (234);
  22. > CREATE CLUSTER rename_cluster1 REPLICAS (replica1 (SIZE '2-2'));
  23. > CREATE CLUSTER rename_cluster2 REPLICAS (replica1 (SIZE '2-2'));
  24. > SET cluster=rename_cluster1
  25. > CREATE DEFAULT INDEX ON rename_cluster1_table;
  26. > CREATE MATERIALIZED VIEW rename_cluster1_view AS SELECT SUM(f1) FROM rename_cluster1_table;
  27. > SET cluster=rename_cluster2
  28. > CREATE DEFAULT INDEX ON rename_cluster2_table;
  29. > CREATE MATERIALIZED VIEW rename_cluster2_view AS SELECT SUM(f1) FROM rename_cluster2_table;
  30. > ALTER CLUSTER rename_cluster1 RENAME TO rename_cluster_new1;
  31. """,
  32. """
  33. > ALTER CLUSTER rename_cluster2 RENAME TO rename_cluster_new2;
  34. """,
  35. ]
  36. ]
  37. def validate(self) -> Testdrive:
  38. return Testdrive(
  39. dedent(
  40. """
  41. > SET cluster=rename_cluster_new1
  42. > SET cluster=rename_cluster_new2
  43. > SET cluster=default
  44. > SELECT * FROM rename_cluster1_table;
  45. 123
  46. > SELECT * FROM rename_cluster1_view;
  47. 123
  48. > SELECT * FROM rename_cluster2_table;
  49. 234
  50. > SELECT * FROM rename_cluster2_view;
  51. 234
  52. """
  53. )
  54. )