mz-sources.td 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. $ set-arg-default default-storage-size=1
  10. # Verify that envelope types are correctly reported in mz_sources
  11. > CREATE CONNECTION kafka_conn
  12. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  13. > CREATE CONNECTION csr_conn TO CONFLUENT SCHEMA REGISTRY (
  14. URL '${testdrive.schema-registry-url}'
  15. );
  16. $ kafka-create-topic topic=none-topic partitions=1
  17. > CREATE CLUSTER none_source_cluster SIZE '${arg.default-storage-size}';
  18. > CREATE SOURCE none_source
  19. IN CLUSTER none_source_cluster
  20. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-none-topic-${testdrive.seed}')
  21. > CREATE TABLE none_source_tbl FROM SOURCE none_source (REFERENCE "testdrive-none-topic-${testdrive.seed}")
  22. KEY FORMAT TEXT
  23. VALUE FORMAT TEXT
  24. INCLUDE KEY
  25. ENVELOPE NONE
  26. > CREATE CLUSTER none_source_no_key_cluster SIZE '${arg.default-storage-size}';
  27. > CREATE SOURCE none_source_no_key
  28. IN CLUSTER none_source_no_key_cluster
  29. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-none-topic-${testdrive.seed}')
  30. > CREATE TABLE none_source_no_key_tbl FROM SOURCE none_source_no_key (REFERENCE "testdrive-none-topic-${testdrive.seed}")
  31. FORMAT TEXT
  32. ENVELOPE NONE
  33. $ set keyschema={
  34. "type": "record",
  35. "name": "Key",
  36. "fields": [
  37. {"name": "id", "type": "long"}
  38. ]
  39. }
  40. $ set schema={
  41. "type" : "record",
  42. "name" : "envelope",
  43. "fields" : [
  44. {
  45. "name": "before",
  46. "type": [
  47. {
  48. "name": "row",
  49. "type": "record",
  50. "fields": [
  51. {
  52. "name": "id",
  53. "type": "long"
  54. },
  55. {
  56. "name": "creature",
  57. "type": "string"
  58. }]
  59. },
  60. "null"
  61. ]
  62. },
  63. { "name": "op", "type": "string" },
  64. {
  65. "name": "after",
  66. "type": ["row", "null"]
  67. },
  68. {
  69. "name": "source",
  70. "type": {
  71. "type": "record",
  72. "name": "Source",
  73. "namespace": "io.debezium.connector.mysql",
  74. "fields": [
  75. {
  76. "name": "file",
  77. "type": "string"
  78. },
  79. {
  80. "name": "pos",
  81. "type": "long"
  82. },
  83. {
  84. "name": "row",
  85. "type": "int"
  86. },
  87. {
  88. "name": "snapshot",
  89. "type": [
  90. {
  91. "type": "boolean",
  92. "connect.default": false
  93. },
  94. "null"
  95. ],
  96. "default": false
  97. }
  98. ],
  99. "connect.name": "io.debezium.connector.mysql.Source"
  100. }
  101. }
  102. ]
  103. }
  104. $ kafka-create-topic topic=dbzupsert partitions=1
  105. $ kafka-ingest format=avro topic=dbzupsert key-format=avro key-schema=${keyschema} schema=${schema} timestamp=1
  106. {"id": 1} {"before": {"row": {"id": 1, "creature": "fish"}}, "after": {"row": {"id": 1, "creature": "mudskipper"}}, "op": "u", "source": {"file": "binlog1", "pos": 1, "row": 1, "snapshot": {"boolean": false}}}
  107. > CREATE CLUSTER debezium_source_cluster SIZE '${arg.default-storage-size}';
  108. > CREATE SOURCE debezium_source
  109. IN CLUSTER debezium_source_cluster
  110. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-dbzupsert-${testdrive.seed}')
  111. > CREATE TABLE debezium_source_tbl FROM SOURCE debezium_source (REFERENCE "testdrive-dbzupsert-${testdrive.seed}")
  112. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  113. ENVELOPE DEBEZIUM
  114. $ kafka-create-topic topic=upsert-topic
  115. $ set keyschema={
  116. "type": "record",
  117. "name": "Key",
  118. "fields": [
  119. {"name": "key", "type": "string"}
  120. ]
  121. }
  122. $ set schema={
  123. "type" : "record",
  124. "name" : "test",
  125. "fields" : [
  126. {"name":"f1", "type":"string"},
  127. {"name":"f2", "type":"long"}
  128. ]
  129. }
  130. $ kafka-ingest format=avro topic=upsert-topic key-format=avro key-schema=${keyschema} schema=${schema}
  131. {"key": "fish"} {"f1": "fish", "f2": 1000}
  132. > CREATE CLUSTER upsert_source_cluster SIZE '${arg.default-storage-size}';
  133. > CREATE SOURCE upsert_source
  134. IN CLUSTER upsert_source_cluster
  135. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-upsert-topic-${testdrive.seed}')
  136. > CREATE TABLE upsert_source_tbl FROM SOURCE upsert_source (REFERENCE "testdrive-upsert-topic-${testdrive.seed}")
  137. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  138. ENVELOPE UPSERT
  139. > CREATE TABLE table_with_other_format_and_envelope FROM SOURCE upsert_source (REFERENCE "testdrive-upsert-topic-${testdrive.seed}")
  140. FORMAT TEXT
  141. ENVELOPE NONE
  142. > SELECT topic, envelope_type, key_format, value_format FROM mz_internal.mz_kafka_source_tables
  143. "\"testdrive-none-topic-${testdrive.seed}\"" none <null> text
  144. "\"testdrive-upsert-topic-${testdrive.seed}\"" none <null> text
  145. "\"testdrive-none-topic-${testdrive.seed}\"" none text text
  146. "\"testdrive-dbzupsert-${testdrive.seed}\"" debezium avro avro
  147. "\"testdrive-upsert-topic-${testdrive.seed}\"" upsert avro avro