123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- # Copyright Materialize, Inc. and contributors. All rights reserved.
- #
- # Use of this software is governed by the Business Source License
- # included in the LICENSE file at the root of this repository.
- #
- # As of the Change Date specified in that file, in accordance with
- # the Business Source License, use of this software will be governed
- # by the Apache License, Version 2.0.
- from textwrap import dedent
- from materialize.checks.actions import Testdrive
- from materialize.checks.checks import Check
- class CreateManagedCluster(Check):
- def manipulate(self) -> list[Testdrive]:
- return [
- Testdrive(dedent(s))
- for s in [
- """
- >[version>=13800] CREATE CLUSTER create_managed_cluster1 SIZE '2-2', REPLICATION FACTOR 2;
- >[version<13800] CREATE CLUSTER create_managed_cluster1 SIZE '2-2', REPLICATION FACTOR 1;
- """,
- """
- >[version>=13800] CREATE CLUSTER create_managed_cluster2 SIZE '2-2', REPLICATION FACTOR 2;
- >[version<13800] CREATE CLUSTER create_managed_cluster2 SIZE '2-2', REPLICATION FACTOR 1;
- """,
- ]
- ]
- def validate(self) -> Testdrive:
- return Testdrive(
- dedent(
- """
- > CREATE TABLE create_managed_cluster1_table (f1 INTEGER);
- > CREATE TABLE create_managed_cluster2_table (f1 INTEGER);
- > INSERT INTO create_managed_cluster1_table VALUES (123);
- > INSERT INTO create_managed_cluster2_table VALUES (234);
- > SET cluster=create_managed_cluster1
- > CREATE DEFAULT INDEX ON create_managed_cluster1_table;
- > CREATE MATERIALIZED VIEW create_managed_cluster1_view AS SELECT SUM(f1) FROM create_managed_cluster1_table;
- > SELECT * FROM create_managed_cluster1_table;
- 123
- > SELECT * FROM create_managed_cluster1_view;
- 123
- > SET cluster=create_managed_cluster2
- > CREATE DEFAULT INDEX ON create_managed_cluster2_table;
- > CREATE MATERIALIZED VIEW create_managed_cluster2_view AS SELECT SUM(f1) FROM create_managed_cluster2_table;
- > SELECT * FROM create_managed_cluster2_table;
- 234
- > SELECT * FROM create_managed_cluster2_view;
- 234
- > DROP TABLE create_managed_cluster1_table CASCADE;
- > DROP TABLE create_managed_cluster2_table CASCADE;
- """
- )
- )
- class DropManagedCluster(Check):
- def manipulate(self) -> list[Testdrive]:
- return [
- Testdrive(dedent(s))
- for s in [
- """
- > CREATE TABLE drop_managed_cluster1_table (f1 INTEGER);
- > CREATE TABLE drop_managed_cluster2_table (f1 INTEGER);
- > INSERT INTO drop_managed_cluster1_table VALUES (123);
- > INSERT INTO drop_managed_cluster2_table VALUES (234);
- >[version>=13800] CREATE CLUSTER drop_managed_cluster1 SIZE '2-2', REPLICATION FACTOR 2;
- >[version<13800] CREATE CLUSTER drop_managed_cluster1 SIZE '2-2', REPLICATION FACTOR 1;
- >[version>=13800] CREATE CLUSTER drop_managed_cluster2 SIZE '2-2', REPLICATION FACTOR 2;
- >[version<13800] CREATE CLUSTER drop_managed_cluster2 SIZE '2-2', REPLICATION FACTOR 1;
- > SET cluster=drop_managed_cluster1
- > CREATE DEFAULT INDEX ON drop_managed_cluster1_table;
- > CREATE MATERIALIZED VIEW drop_managed_cluster1_view AS SELECT SUM(f1) FROM drop_managed_cluster1_table;
- > SET cluster=drop_managed_cluster2
- > CREATE DEFAULT INDEX ON drop_managed_cluster2_table;
- > CREATE MATERIALIZED VIEW drop_managed_cluster2_view AS SELECT SUM(f1) FROM drop_managed_cluster2_table;
- > DROP CLUSTER drop_managed_cluster1 CASCADE;
- """,
- """
- > DROP CLUSTER drop_managed_cluster2 CASCADE;
- """,
- ]
- ]
- def validate(self) -> Testdrive:
- return Testdrive(
- dedent(
- """
- > SET cluster=drop_managed_cluster1
- > SET cluster=drop_managed_cluster2
- > SET cluster=default
- > SELECT * FROM drop_managed_cluster1_table;
- 123
- ! SELECT * FROM drop_managed_cluster1_view;
- contains: unknown catalog item 'drop_managed_cluster1_view'
- > SELECT * FROM drop_managed_cluster2_table;
- 234
- ! SELECT * FROM drop_managed_cluster2_view;
- contains: unknown catalog item 'drop_managed_cluster2_view'
- """
- )
- )
|