uuid.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 UUID(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE uuid_table (f1 UUID, f2 UUID, f3 STRING);
  18. > INSERT INTO uuid_table VALUES (uuid_generate_v5('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', 'bar'), 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12', 'baz');
  19. """
  20. )
  21. )
  22. def manipulate(self) -> list[Testdrive]:
  23. return [
  24. Testdrive(dedent(s))
  25. for s in [
  26. """
  27. > CREATE MATERIALIZED VIEW uuid_view1 AS SELECT
  28. f1,
  29. uuid_generate_v5(f2, f3) as f2,
  30. uuid_generate_v5('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a13', 'foobar') as f3
  31. FROM uuid_table;
  32. > INSERT INTO uuid_table VALUES (uuid_generate_v5(NULL, 'foo'), NULL, 'foo');
  33. """,
  34. """
  35. > CREATE MATERIALIZED VIEW uuid_view2 AS SELECT
  36. f1,
  37. uuid_generate_v5(f2, f3) as f2,
  38. uuid_generate_v5('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a13', 'foobar') as f3
  39. FROM uuid_table;
  40. > INSERT INTO uuid_table VALUES (uuid_generate_v5('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', NULL), 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', NULL);
  41. """,
  42. ]
  43. ]
  44. def validate(self) -> Testdrive:
  45. return Testdrive(
  46. dedent(
  47. """
  48. > SELECT * FROM uuid_view1;
  49. 0b259031-4bae-587c-870a-2f641fe621fe 9ab9ba37-d48e-5c94-bb56-2ccc3129f361 64feaf9e-0633-5eba-9bca-b5f1afd6b084
  50. <null> <null> 64feaf9e-0633-5eba-9bca-b5f1afd6b084
  51. <null> <null> 64feaf9e-0633-5eba-9bca-b5f1afd6b084
  52. > SELECT * FROM uuid_view2;
  53. 0b259031-4bae-587c-870a-2f641fe621fe 9ab9ba37-d48e-5c94-bb56-2ccc3129f361 64feaf9e-0633-5eba-9bca-b5f1afd6b084
  54. <null> <null> 64feaf9e-0633-5eba-9bca-b5f1afd6b084
  55. <null> <null> 64feaf9e-0633-5eba-9bca-b5f1afd6b084
  56. """
  57. )
  58. )