threshold.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 Threshold(Check):
  13. """Exercise the 'threshold' portion of a MFP plan"""
  14. def initialize(self) -> Testdrive:
  15. return Testdrive(
  16. dedent(
  17. """
  18. > CREATE TABLE threshold_table1 (f1 INT);
  19. > INSERT INTO threshold_table1 VALUES (0);
  20. > CREATE TABLE threshold_table2 (f1 INT);
  21. > INSERT INTO threshold_table2 VALUES (1);
  22. """
  23. )
  24. )
  25. def manipulate(self) -> list[Testdrive]:
  26. return [
  27. Testdrive(dedent(s))
  28. for s in [
  29. """
  30. > INSERT INTO threshold_table1 VALUES (1);
  31. > CREATE MATERIALIZED VIEW threshold_view1 AS SELECT * FROM threshold_table1 EXCEPT SELECT * FROM threshold_table2;
  32. > INSERT INTO threshold_table2 VALUES (2);
  33. """,
  34. """
  35. > INSERT INTO threshold_table1 VALUES (2);
  36. > CREATE MATERIALIZED VIEW threshold_view2 AS SELECT * FROM threshold_table2 EXCEPT ALL SELECT * FROM threshold_table1;
  37. > INSERT INTO threshold_table2 VALUES (3);
  38. """,
  39. ]
  40. ]
  41. def validate(self) -> Testdrive:
  42. return Testdrive(
  43. dedent(
  44. """
  45. > SELECT * FROM threshold_view1;
  46. 0
  47. > SELECT * FROM threshold_view2;
  48. 3
  49. """
  50. )
  51. )