01-create-sources.td 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. # The main purpose of these tests is to make sure that we can correctly retract
  10. # key/value errors (mostly decoding errors) even after we have restarted a
  11. # materialize instance.
  12. # must be a subset of the keys in the rows
  13. $ set keyschema={
  14. "type": "record",
  15. "name": "Key",
  16. "fields": [
  17. {"name": "id", "type": "long"}
  18. ]
  19. }
  20. $ set schema={
  21. "type" : "record",
  22. "name" : "envelope",
  23. "fields" : [
  24. {
  25. "name": "before",
  26. "type": [
  27. {
  28. "name": "row",
  29. "type": "record",
  30. "fields": [
  31. {
  32. "name": "id",
  33. "type": "long"
  34. },
  35. {
  36. "name": "creature",
  37. "type": "string"
  38. }]
  39. },
  40. "null"
  41. ]
  42. },
  43. {
  44. "name": "after",
  45. "type": ["row", "null"]
  46. }
  47. ]
  48. }
  49. $ kafka-create-topic topic=dbzupsert-broken-key partitions=1
  50. $ kafka-ingest format=avro topic=dbzupsert-broken-key key-format=avro key-schema=${keyschema} schema=${schema}
  51. {"id": 1} {"before": null, "after": {"row": {"id": 1, "creature": "mudskipper"}}}
  52. {"id": 1} {"before": null, "after": {"row": {"id": 1, "creature": "salamander"}}}
  53. {"id": 1} {"before": null, "after": {"row": {"id": 1, "creature": "lizard"}}}
  54. $ kafka-create-topic topic=dbzupsert-broken-value partitions=1
  55. $ kafka-ingest format=avro topic=dbzupsert-broken-value key-format=avro key-schema=${keyschema} schema=${schema}
  56. {"id": 1} {"before": null, "after": {"row": {"id": 1, "creature": "mudskipper"}}}
  57. {"id": 1} {"before": null, "after": {"row": {"id": 1, "creature": "salamander"}}}
  58. {"id": 1} {"before": null, "after": {"row": {"id": 1, "creature": "lizard"}}}
  59. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  60. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  61. URL '${testdrive.schema-registry-url}'
  62. );
  63. # With these first two sources, we verify that we can retract key/value decoding errors.
  64. > CREATE SOURCE upsert_broken_key
  65. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-dbzupsert-broken-key-${testdrive.seed}')
  66. > CREATE TABLE upsert_broken_key_tbl FROM SOURCE upsert_broken_key (REFERENCE "testdrive-dbzupsert-broken-key-${testdrive.seed}")
  67. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  68. ENVELOPE DEBEZIUM
  69. > CREATE SOURCE upsert_broken_value
  70. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-dbzupsert-broken-value-${testdrive.seed}')
  71. > CREATE TABLE upsert_broken_value_tbl FROM SOURCE upsert_broken_value (REFERENCE "testdrive-dbzupsert-broken-value-${testdrive.seed}")
  72. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  73. ENVELOPE DEBEZIUM
  74. > SELECT * FROM upsert_broken_key_tbl
  75. id creature
  76. -----------
  77. 1 lizard
  78. # Ingest a broken key/value pair
  79. $ kafka-ingest format=bytes topic=dbzupsert-broken-key key-format=bytes
  80. broken-key:bar
  81. ! SELECT * FROM upsert_broken_key_tbl
  82. contains: Key decode
  83. # Ingest a broken value with a good key
  84. $ kafka-ingest format=bytes topic=dbzupsert-broken-value key-format=avro key-schema=${keyschema}
  85. {"id": 2}bar2
  86. ! SELECT * FROM upsert_broken_value_tbl
  87. contains: Value error
  88. # With this third source, we verify that we can retract NULL-key errors by
  89. # ingesting a NULL:NULL record (a record where both key and value are NULL).
  90. $ kafka-create-topic topic=upsert-nullkey partitions=1
  91. # A null key should result in an error decoding that row but not a panic
  92. $ kafka-ingest format=bytes topic=upsert-nullkey key-format=bytes key-terminator=:
  93. bird1:goose
  94. :geese
  95. > CREATE SOURCE upsert_nullkey
  96. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-upsert-nullkey-${testdrive.seed}')
  97. > CREATE TABLE upsert_nullkey_tbl FROM SOURCE upsert_nullkey (REFERENCE "testdrive-upsert-nullkey-${testdrive.seed}")
  98. KEY FORMAT TEXT
  99. VALUE FORMAT TEXT
  100. ENVELOPE UPSERT
  101. ! select * from upsert_nullkey_tbl
  102. contains: record with NULL key in UPSERT source