create_index.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 CreateIndex(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE create_index_table (f1 INTEGER, f2 INTEGER, f3 INTEGER);
  18. > INSERT INTO create_index_table VALUES (1,2,3);
  19. """
  20. )
  21. )
  22. def manipulate(self) -> list[Testdrive]:
  23. return [
  24. Testdrive(dedent(s))
  25. for s in [
  26. """
  27. > INSERT INTO create_index_table VALUES (2,3,4);
  28. > CREATE DEFAULT INDEX ON create_index_table;
  29. > INSERT INTO create_index_table VALUES (3,4,5);
  30. """,
  31. """
  32. > INSERT INTO create_index_table VALUES (4,5,6);
  33. > CREATE INDEX create_index_table_index ON create_index_table (f1, f2);
  34. > INSERT INTO create_index_table VALUES (5,6,7);
  35. """,
  36. ]
  37. ]
  38. def validate(self) -> Testdrive:
  39. return Testdrive(
  40. dedent(
  41. """
  42. > SELECT * FROM create_index_table;
  43. 1 2 3
  44. 2 3 4
  45. 3 4 5
  46. 4 5 6
  47. 5 6 7
  48. > SELECT f1 FROM create_index_table;
  49. 1
  50. 2
  51. 3
  52. 4
  53. 5
  54. > SELECT f3 FROM create_index_table;
  55. 3
  56. 4
  57. 5
  58. 6
  59. 7
  60. """
  61. )
  62. )