exactly-once-sink-before.td 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #
  10. # Test persistent kafka topics in the context of exactly-once sinks
  11. #
  12. $ set keyschema={
  13. "type": "record",
  14. "name": "Key",
  15. "fields": [
  16. {"name": "f1", "type": "long"}
  17. ]
  18. }
  19. $ set schema={
  20. "type" : "record",
  21. "name" : "test",
  22. "fields" : [
  23. {"name":"f2", "type":"long"}
  24. ]
  25. }
  26. $ kafka-create-topic topic=exactly-once
  27. $ kafka-ingest format=avro topic=exactly-once key-format=avro key-schema=${keyschema} schema=${schema} repeat=2
  28. {"f1": ${kafka-ingest.iteration}} {"f2": ${kafka-ingest.iteration}}
  29. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  30. > CREATE SOURCE exactly_once
  31. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-exactly-once-${testdrive.seed}')
  32. > CREATE TABLE exactly_once_tbl FROM SOURCE exactly_once (REFERENCE "testdrive-exactly-once-${testdrive.seed}")
  33. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  34. ENVELOPE UPSERT
  35. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  36. URL '${testdrive.schema-registry-url}'
  37. );
  38. > CREATE SINK exactly_once_sink FROM exactly_once_tbl
  39. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-exactly-once-sink-${testdrive.seed}')
  40. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  41. ENVELOPE DEBEZIUM;
  42. $ kafka-ingest format=avro topic=exactly-once key-format=avro key-schema=${keyschema} schema=${schema} repeat=2 start-iteration=10
  43. {"f1": ${kafka-ingest.iteration}} {"f2": ${kafka-ingest.iteration}}
  44. > SELECT COUNT(*) FROM exactly_once_tbl;
  45. 4
  46. $ kafka-ingest format=avro topic=exactly-once key-format=avro key-schema=${keyschema} schema=${schema} repeat=2 start-iteration=20
  47. {"f1": ${kafka-ingest.iteration}} {"f2": ${kafka-ingest.iteration}}
  48. $ kafka-ingest format=avro topic=exactly-once key-format=avro key-schema=${keyschema} schema=${schema} repeat=2 start-iteration=30
  49. {"f1": ${kafka-ingest.iteration}} {"f2": ${kafka-ingest.iteration}}
  50. # Make sure that we have produced stuff to the sink before we restart
  51. $ kafka-verify-data format=avro sink=materialize.public.exactly_once_sink sort-messages=true
  52. {"before":null,"after":{"row":{"f1":0,"f2":0}}}
  53. {"before":null,"after":{"row":{"f1":1,"f2":1}}}
  54. {"before":null,"after":{"row":{"f1":10,"f2":10}}}
  55. {"before":null,"after":{"row":{"f1":11,"f2":11}}}