comment.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 Comment(Check):
  13. """Test comments on types and tables, as well as the comment export as avro sink schema docs"""
  14. def initialize(self) -> Testdrive:
  15. return Testdrive(
  16. dedent(
  17. """
  18. > CREATE TYPE comment_type AS (x text, y int, z int)
  19. > CREATE TYPE comment_int4_list AS LIST (ELEMENT TYPE = int4)
  20. > CREATE TABLE comment_table (f1 comment_type, f2 comment_int4_list, f3 int)
  21. > CREATE SINK comment_sink1 FROM comment_table
  22. INTO KAFKA CONNECTION kafka_conn (TOPIC 'comment-sink1')
  23. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  24. ENVELOPE DEBEZIUM
  25. """
  26. )
  27. )
  28. def manipulate(self) -> list[Testdrive]:
  29. return [
  30. Testdrive(dedent(s))
  31. for s in [
  32. """
  33. > COMMENT ON TYPE comment_type IS 'comment on comment_type';
  34. > COMMENT ON COLUMN comment_type.x IS 'comment on comment_type.x';
  35. > COMMENT ON TYPE comment_int4_list IS 'comment on comment_type';
  36. > COMMENT ON TABLE comment_table IS 'comment on comment_table';
  37. > COMMENT ON COLUMN comment_table.f1 IS 'comment on comment_table.f1';
  38. > CREATE SINK comment_sink2 FROM comment_table
  39. INTO KAFKA CONNECTION kafka_conn (TOPIC 'comment-sink2')
  40. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  41. ENVELOPE DEBEZIUM
  42. """,
  43. """
  44. > COMMENT ON COLUMN comment_type.y IS 'comment on comment_type.y';
  45. > COMMENT ON COLUMN comment_table.f2 IS 'comment on comment_table.f2';
  46. > CREATE SINK comment_sink3 FROM comment_table
  47. INTO KAFKA CONNECTION kafka_conn (TOPIC 'comment-sink3')
  48. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  49. ENVELOPE DEBEZIUM
  50. """,
  51. ]
  52. ]
  53. def validate(self) -> Testdrive:
  54. return Testdrive(
  55. dedent(
  56. """
  57. > COMMENT ON COLUMN comment_type.z IS 'comment on comment_type.z';
  58. > COMMENT ON COLUMN comment_table.f3 IS 'comment on comment_table.f3';
  59. > SELECT name, object_type, object_sub_id, comment FROM mz_internal.mz_comments JOIN mz_objects ON mz_comments.id = mz_objects.id WHERE name LIKE 'comment_%';
  60. comment_table table 1 "comment on comment_table.f1"
  61. comment_table table 2 "comment on comment_table.f2"
  62. comment_table table 3 "comment on comment_table.f3"
  63. comment_table table <null> "comment on comment_table"
  64. comment_type type 1 "comment on comment_type.x"
  65. comment_type type 2 "comment on comment_type.y"
  66. comment_type type 3 "comment on comment_type.z"
  67. comment_type type <null> "comment on comment_type"
  68. comment_int4_list type <null> "comment on comment_type"
  69. $ schema-registry-verify schema-type=avro subject=comment-sink1-value
  70. {"type":"record","name":"envelope","fields":[{"name":"before","type":["null",{"type":"record","name":"row","fields":[{"name":"f1","type":["null",{"type":"record","name":"record0","namespace":"com.materialize.sink","fields":[{"name":"x","type":["null","string"]},{"name":"y","type":["null","int"]},{"name":"z","type":["null","int"]}]}]},{"name":"f2","type":["null",{"type":"array","items":["null","int"]}]},{"name":"f3","type":["null","int"]}]}]},{"name":"after","type":["null","row"]}]}
  71. $ schema-registry-verify schema-type=avro subject=comment-sink2-value
  72. {"type":"record","name":"envelope","fields":[{"name":"before","type":["null",{"type":"record","name":"row","doc":"comment on comment_table","fields":[{"name":"f1","type":["null",{"type":"record","name":"record0","namespace":"com.materialize.sink","doc":"comment on comment_type","fields":[{"name":"x","type":["null","string"],"doc":"comment on comment_type.x"},{"name":"y","type":["null","int"]},{"name":"z","type":["null","int"]}]}],"doc":"comment on comment_table.f1"},{"name":"f2","type":["null",{"type":"array","items":["null","int"]}]},{"name":"f3","type":["null","int"]}]}]},{"name":"after","type":["null","row"]}]}
  73. $ schema-registry-verify schema-type=avro subject=comment-sink3-value
  74. {"type":"record","name":"envelope","fields":[{"name":"before","type":["null",{"type":"record","name":"row","doc":"comment on comment_table","fields":[{"name":"f1","type":["null",{"type":"record","name":"record0","namespace":"com.materialize.sink","doc":"comment on comment_type","fields":[{"name":"x","type":["null","string"],"doc":"comment on comment_type.x"},{"name":"y","type":["null","int"],"doc":"comment on comment_type.y"},{"name":"z","type":["null","int"]}]}],"doc":"comment on comment_table.f1"},{"name":"f2","type":["null",{"type":"array","items":["null","int"]}],"doc":"comment on comment_table.f2"},{"name":"f3","type":["null","int"]}]}]},{"name":"after","type":["null","row"]}]}
  75. """
  76. )
  77. )