kafka-debezium-sources-compound-key.td 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. # Must be a subset of the keys in the rows AND
  10. # in a different order than the value.
  11. $ set keyschema={
  12. "type": "record",
  13. "name": "Key",
  14. "fields": [
  15. {"name": "b", "type": "string"},
  16. {"name": "a", "type": "long"}
  17. ]
  18. }
  19. $ set schema={
  20. "type" : "record",
  21. "name" : "envelope",
  22. "fields" : [
  23. {
  24. "name": "before",
  25. "type": [
  26. {
  27. "name": "row",
  28. "type": "record",
  29. "fields": [
  30. {
  31. "name": "a",
  32. "type": "long"
  33. },
  34. {
  35. "name": "data",
  36. "type": "string"
  37. },
  38. {
  39. "name": "b",
  40. "type": "string"
  41. }]
  42. },
  43. "null"
  44. ]
  45. },
  46. {
  47. "name": "after",
  48. "type": ["row", "null"]
  49. }
  50. ]
  51. }
  52. > CREATE CONNECTION kafka_conn
  53. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  54. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  55. URL '${testdrive.schema-registry-url}'
  56. );
  57. $ kafka-create-topic topic=upsert-compound-key
  58. $ kafka-ingest format=avro topic=upsert-compound-key key-format=avro key-schema=${keyschema} schema=${schema}
  59. {"b": "bdata", "a": 1} {"before": null, "after": {"row": {"a": 1, "data": "fish1", "b": "bdata"}}}
  60. > CREATE CLUSTER upsert_cluster SIZE = '1', REPLICATION FACTOR = 1;
  61. > CREATE SOURCE upsert_compound_key
  62. IN CLUSTER upsert_cluster
  63. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-upsert-compound-key-${testdrive.seed}')
  64. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  65. ENVELOPE DEBEZIUM
  66. # Ingest the snapshot
  67. > SELECT * FROM upsert_compound_key
  68. 1 fish1 bdata
  69. # Stop the dataflow
  70. > ALTER CLUSTER upsert_cluster SET (REPLICATION FACTOR 0);
  71. # Ingest another update
  72. $ kafka-ingest format=avro topic=upsert-compound-key key-format=avro key-schema=${keyschema} schema=${schema}
  73. {"b": "bdata", "a": 1} {"before": {"row": {"a": 1, "data": "fish1", "b": "bdata"}}, "after": {"row": {"a": 1, "data": "fish2", "b": "bdata"}}}
  74. # Start the dataflow
  75. > ALTER CLUSTER upsert_cluster SET (REPLICATION FACTOR 1);
  76. # Verify result
  77. > SELECT * FROM upsert_compound_key
  78. 1 fish2 bdata