having.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 Having(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE having_table (f1 INTEGER, f2 INTEGER);
  18. > INSERT INTO having_table 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 MATERIALIZED VIEW having_view1 AS
  28. SELECT f1, SUM(f1) FROM having_table GROUP BY f1 HAVING SUM(f1) > 1 AND SUM(f1) < 3;
  29. > INSERT INTO having_table VALUES (2, 2);
  30. """,
  31. """
  32. > CREATE MATERIALIZED VIEW having_view2 AS
  33. SELECT f1, SUM(f1) FROM having_table GROUP BY f1 HAVING SUM(f1) > 1 AND SUM(f1) < 3;
  34. > INSERT INTO having_table VALUES (3, 3);
  35. """,
  36. ]
  37. ]
  38. def validate(self) -> Testdrive:
  39. return Testdrive(
  40. dedent(
  41. """
  42. > SELECT * FROM having_view1;
  43. 2 2
  44. > SELECT * FROM having_view2;
  45. 2 2
  46. """
  47. )
  48. )