drop_index.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 DropIndex(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE drop_index_table (f1 INTEGER, f2 INTEGER, f3 INTEGER);
  18. > INSERT INTO drop_index_table VALUES (1,1,1);
  19. > CREATE DEFAULT INDEX ON drop_index_table;
  20. > INSERT INTO drop_index_table VALUES (2,2,2);
  21. > CREATE INDEX drop_index_index1 ON drop_index_table (f1, f2);
  22. > INSERT INTO drop_index_table VALUES (3,3,3);
  23. > CREATE MATERIALIZED VIEW drop_index_view AS SELECT f1, f2 FROM drop_index_table WHERE f1 > 0;
  24. """
  25. )
  26. )
  27. def manipulate(self) -> list[Testdrive]:
  28. return [
  29. Testdrive(dedent(s))
  30. for s in [
  31. """
  32. > INSERT INTO drop_index_table VALUES (4,4,4);
  33. > DROP INDEX drop_index_index1;
  34. > INSERT INTO drop_index_table VALUES (5,5,5);
  35. > CREATE INDEX drop_index_index2 ON drop_index_table (f1, f2);
  36. > INSERT INTO drop_index_table VALUES (6,6,6);
  37. """,
  38. """
  39. > INSERT INTO drop_index_table VALUES (7,7,7);
  40. > DROP INDEX drop_index_table_primary_idx;
  41. > INSERT INTO drop_index_table VALUES (8,8,8);
  42. > DROP INDEX drop_index_index2;
  43. > INSERT INTO drop_index_table VALUES (9,9,9);
  44. """,
  45. ]
  46. ]
  47. def validate(self) -> Testdrive:
  48. return Testdrive(
  49. dedent(
  50. """
  51. > SELECT * FROM drop_index_table;
  52. 1 1 1
  53. 2 2 2
  54. 3 3 3
  55. 4 4 4
  56. 5 5 5
  57. 6 6 6
  58. 7 7 7
  59. 8 8 8
  60. 9 9 9
  61. > SELECT f1 FROM drop_index_table;
  62. 1
  63. 2
  64. 3
  65. 4
  66. 5
  67. 6
  68. 7
  69. 8
  70. 9
  71. > SELECT f3 FROM drop_index_table;
  72. 1
  73. 2
  74. 3
  75. 4
  76. 5
  77. 6
  78. 7
  79. 8
  80. 9
  81. > SELECT * FROM drop_index_view;
  82. 1 1
  83. 2 2
  84. 3 3
  85. 4 4
  86. 5 5
  87. 6 6
  88. 7 7
  89. 8 8
  90. 9 9
  91. """
  92. )
  93. )