insert_select.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 InsertSelect(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE insert_select_destination (f1 STRING);
  18. > CREATE TABLE insert_select_source_table (f1 STRING);
  19. > INSERT INTO insert_select_source_table SELECT 'T1' || generate_series FROM generate_series(1,10000);
  20. """
  21. )
  22. )
  23. def manipulate(self) -> list[Testdrive]:
  24. return [
  25. Testdrive(dedent(s))
  26. for s in [
  27. """
  28. > INSERT INTO insert_select_source_table SELECT 'T2' || generate_series FROM generate_series(1, 10000);
  29. > INSERT INTO insert_select_destination SELECT * FROM insert_select_source_table;
  30. """,
  31. """
  32. > INSERT INTO insert_select_source_table SELECT 'T3' || generate_series FROM generate_series(1, 10000);
  33. > INSERT INTO insert_select_destination SELECT * FROM insert_select_source_table;
  34. """,
  35. ]
  36. ]
  37. def validate(self) -> Testdrive:
  38. return Testdrive(
  39. dedent(
  40. """
  41. > SELECT LEFT(f1, 2), COUNT(*), COUNT(DISTINCT f1) FROM insert_select_destination GROUP BY LEFT(f1, 2);
  42. T1 20000 10000
  43. T2 20000 10000
  44. T3 10000 10000
  45. """
  46. )
  47. )