swap.slt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. mode standard
  10. reset-server
  11. # Enable the feature.
  12. simple conn=mz_system,user=mz_system
  13. ALTER SYSTEM SET enable_alter_swap TO true;
  14. ----
  15. COMPLETE 0
  16. statement ok
  17. CREATE SCHEMA blue;
  18. statement ok
  19. CREATE TABLE blue.t1 (x int);
  20. statement ok
  21. INSERT INTO blue.t1 VALUES (1), (2), (3);
  22. statement ok
  23. CREATE SCHEMA green;
  24. statement ok
  25. CREATE TABLE green.t2 (y int);
  26. statement ok
  27. INSERT INTO green.t2 VALUES (4), (5), (6);
  28. statement error db error: ERROR: unknown catalog item 'blue\.t2'
  29. SELECT * FROM blue.t2;
  30. statement ok
  31. ALTER SCHEMA blue SWAP WITH green;
  32. query I valuesort
  33. SELECT * FROM blue.t2;
  34. ----
  35. 4
  36. 5
  37. 6
  38. statement ok
  39. CREATE SCHEMA "!\_\""w3😊_weird_name";
  40. statement ok
  41. CREATE TABLE "!\_\""w3😊_weird_name".t2 (y int);
  42. statement ok
  43. INSERT INTO "!\_\""w3😊_weird_name".t2 VALUES (7), (8), (9);
  44. statement ok
  45. ALTER SCHEMA blue SWAP WITH "!\_\""w3😊_weird_name";
  46. query I valuesort
  47. SELECT * FROM "!\_\""w3😊_weird_name".t2;
  48. ----
  49. 4
  50. 5
  51. 6
  52. statement ok
  53. ALTER SCHEMA blue SWAP WITH blue;
  54. query I valuesort
  55. SELECT * FROM blue.t2;
  56. ----
  57. 7
  58. 8
  59. 9
  60. statement error db error: ERROR: unknown schema 'null'
  61. ALTER SCHEMA blue SWAP WITH NULL;
  62. statement error db error: ERROR: unknown schema 'null'
  63. ALTER SCHEMA NULL SWAP WITH green;
  64. statement ok
  65. CREATE SCHEMA this_is_a_schema_with_a_super_long_name_of_exactly_255_characters_which_happens_to_be_the_maximum_we_allow_in_materialize_for_identifiers_of_any_kind_including_for_the_schema_name_so_this_should_still_work_perfectly_fine_as_long_as_we_dont_make_it_longer;
  66. statement ok
  67. ALTER SCHEMA this_is_a_schema_with_a_super_long_name_of_exactly_255_characters_which_happens_to_be_the_maximum_we_allow_in_materialize_for_identifiers_of_any_kind_including_for_the_schema_name_so_this_should_still_work_perfectly_fine_as_long_as_we_dont_make_it_longer SWAP WITH blue;
  68. query I valuesort
  69. SELECT * FROM this_is_a_schema_with_a_super_long_name_of_exactly_255_characters_which_happens_to_be_the_maximum_we_allow_in_materialize_for_identifiers_of_any_kind_including_for_the_schema_name_so_this_should_still_work_perfectly_fine_as_long_as_we_dont_make_it_longer.t2;
  70. ----
  71. 7
  72. 8
  73. 9
  74. statement error db error: ERROR: cannot swap schemas that are in the ambient database
  75. ALTER SCHEMA mz_internal SWAP WITH mz_catalog;
  76. statement ok
  77. CREATE DATABASE a;
  78. statement ok
  79. CREATE SCHEMA a.green;
  80. statement ok
  81. CREATE DATABASE b;
  82. statement ok
  83. CREATE SCHEMA b.blue;
  84. statement error db error: ERROR: Expected end of statement, found dot
  85. ALTER SCHEMA a.green SWAP WITH b.blue;
  86. statement error db error: ERROR: unacceptable schema name 'mz_swap'
  87. CREATE SCHEMA mz_swap;
  88. statement ok
  89. CREATE CLUSTER foo SIZE = '1';
  90. statement ok
  91. CREATE CLUSTER bar SIZE = '1';
  92. statement ok
  93. CREATE INDEX green_idx IN CLUSTER foo ON green.t1 (x);
  94. query T
  95. SELECT name FROM mz_clusters JOIN ( SELECT cluster_id FROM mz_indexes WHERE name = 'green_idx' ) my_index ON mz_clusters.id = my_index.cluster_id;
  96. ----
  97. foo
  98. statement ok
  99. ALTER CLUSTER foo SWAP WITH bar;
  100. query T
  101. SELECT name FROM mz_clusters JOIN ( SELECT cluster_id FROM mz_indexes WHERE name = 'green_idx' ) my_index ON mz_clusters.id = my_index.cluster_id;
  102. ----
  103. bar
  104. # Disable the feature.
  105. simple conn=mz_system,user=mz_system
  106. ALTER SYSTEM SET enable_alter_swap TO false;
  107. ----
  108. COMPLETE 0
  109. statement error db error: ERROR: the ALTER SWAP feature for objects is not available
  110. ALTER CLUSTER bar SWAP WITH foo;
  111. # Cleanup.
  112. statement ok
  113. DROP CLUSTER foo CASCADE;
  114. statement ok
  115. DROP CLUSTER bar CASCADE;