create_table.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 CreateTable(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE create_table1 (f1 INTEGER, f2 INTEGER NOT NULL DEFAULT 1234);
  18. > INSERT INTO create_table1 VALUES (1, 1);
  19. """
  20. )
  21. )
  22. def manipulate(self) -> list[Testdrive]:
  23. return [
  24. Testdrive(dedent(s))
  25. for s in [
  26. """
  27. > CREATE TABLE create_table2 (f1 INTEGER, f2 INTEGER NOT NULL DEFAULT 1234);
  28. > INSERT INTO create_table2 VALUES (2,2);
  29. > CREATE MATERIALIZED VIEW create_table_view1 AS SELECT create_table1.f1 FROM create_table1, create_table2;
  30. """,
  31. """
  32. > CREATE TABLE create_table3 (f1 INTEGER, f2 INTEGER NOT NULL DEFAULT 1234);
  33. > INSERT INTO create_table3 VALUES (3,3);
  34. > CREATE MATERIALIZED VIEW create_table_view2 AS SELECT create_table2.f1 FROM create_table2, create_table3;
  35. """,
  36. ]
  37. ]
  38. def validate(self) -> Testdrive:
  39. return Testdrive(
  40. dedent(
  41. """
  42. > SELECT * FROM create_table1;
  43. 1 1
  44. > SELECT * FROM create_table2;
  45. 2 2
  46. > SELECT * FROM create_table3;
  47. 3 3
  48. > SELECT * FROM create_table_view1;
  49. 1
  50. > SELECT * FROM create_table_view2;
  51. 2
  52. ! INSERT INTO create_table1 (f2) VALUES (NULL);
  53. contains: null value in column
  54. > INSERT INTO create_table1 (f1) VALUES (999);
  55. > SELECT f2 FROM create_table1 WHERE f2 = 1234;
  56. 1234
  57. > DELETE FROM create_table1 WHERE f1 = 999;
  58. ! INSERT INTO create_table2 (f2) VALUES (NULL);
  59. contains: null value in column
  60. > INSERT INTO create_table2 (f1) VALUES (999);
  61. > SELECT f2 FROM create_table2 WHERE f2 = 1234;
  62. 1234
  63. > DELETE FROM create_table2 WHERE f1 = 999;
  64. ! INSERT INTO create_table3 (f2) VALUES (NULL);
  65. contains: null value in column
  66. > INSERT INTO create_table3 (f1) VALUES (999);
  67. > SELECT f2 FROM create_table3 WHERE f2 = 1234;
  68. 1234
  69. > DELETE FROM create_table3 WHERE f1 = 999;
  70. """
  71. )
  72. )