join_implementations.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 DeltaJoin(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE delta_join_table1 (f1 INT, f2 INT);
  18. > CREATE INDEX delta_join_index1 ON delta_join_table1(f1);
  19. > INSERT INTO delta_join_table1 VALUES (1, 1);
  20. > CREATE TABLE delta_join_table2 (f3 INT, f4 INT);
  21. > CREATE INDEX delta_join_index2 ON delta_join_table2(f3);
  22. > INSERT INTO delta_join_table2 VALUES (1, 1);
  23. """
  24. )
  25. )
  26. def manipulate(self) -> list[Testdrive]:
  27. return [
  28. Testdrive(dedent(s))
  29. for s in [
  30. """
  31. > INSERT INTO delta_join_table1 VALUES (2, 2);
  32. > CREATE MATERIALIZED VIEW delta_join_view1 AS SELECT * FROM delta_join_table1, delta_join_table2 WHERE delta_join_table1.f1 = delta_join_table2.f3;
  33. > INSERT INTO delta_join_table2 VALUES (2, 2);
  34. """,
  35. """
  36. > INSERT INTO delta_join_table1 VALUES (3, 3);
  37. > CREATE MATERIALIZED VIEW delta_join_view2 AS SELECT * FROM delta_join_table1, delta_join_table2 WHERE delta_join_table1.f1 = delta_join_table2.f3;
  38. > INSERT INTO delta_join_table2 VALUES (3, 3);
  39. """,
  40. ]
  41. ]
  42. def validate(self) -> Testdrive:
  43. return Testdrive(
  44. dedent(
  45. """
  46. > SELECT * FROM delta_join_view1;
  47. 1 1 1 1
  48. 2 2 2 2
  49. 3 3 3 3
  50. > SELECT * FROM delta_join_view2;
  51. 1 1 1 1
  52. 2 2 2 2
  53. 3 3 3 3
  54. """
  55. )
  56. )
  57. class LinearJoin(Check):
  58. def initialize(self) -> Testdrive:
  59. return Testdrive(
  60. dedent(
  61. """
  62. > CREATE TABLE linear_join_table1 (f1 INT);
  63. > INSERT INTO linear_join_table1 VALUES (1);
  64. > CREATE TABLE linear_join_table2 (f2 INT);
  65. > INSERT INTO linear_join_table2 VALUES (1);
  66. """
  67. )
  68. )
  69. def manipulate(self) -> list[Testdrive]:
  70. return [
  71. Testdrive(dedent(s))
  72. for s in [
  73. """
  74. > INSERT INTO linear_join_table1 VALUES (2);
  75. > CREATE MATERIALIZED VIEW linear_join_view1 AS SELECT * FROM linear_join_table1, linear_join_table2 WHERE linear_join_table1.f1 = linear_join_table2.f2;
  76. > INSERT INTO linear_join_table2 VALUES (2);
  77. """,
  78. """
  79. > INSERT INTO linear_join_table1 VALUES (3);
  80. > CREATE MATERIALIZED VIEW linear_join_view2 AS SELECT * FROM linear_join_table1, linear_join_table2 WHERE linear_join_table1.f1 = linear_join_table2.f2;
  81. > INSERT INTO linear_join_table2 VALUES (3);
  82. """,
  83. ]
  84. ]
  85. def validate(self) -> Testdrive:
  86. return Testdrive(
  87. dedent(
  88. """
  89. > SELECT * FROM linear_join_view1;
  90. 1 1
  91. 2 2
  92. 3 3
  93. > SELECT * FROM linear_join_view2;
  94. 1 1
  95. 2 2
  96. 3 3
  97. """
  98. )
  99. )