01-setup.td 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 keyschema={
  10. "type": "record",
  11. "name": "Key",
  12. "fields": [
  13. {"name": "key", "type": "string"}
  14. ]
  15. }
  16. $ set schema={
  17. "type" : "record",
  18. "name" : "test",
  19. "fields" : [
  20. {"name":"f1", "type":"string"},
  21. {"name":"f2", "type":"long"}
  22. ]
  23. }
  24. $ kafka-create-topic topic=upsert
  25. $ kafka-ingest format=avro topic=upsert key-format=avro key-schema=${keyschema} schema=${schema}
  26. {"key": "fish"} {"f1": "MUCHMUCHMUCHLONGERVALUE", "f2": 1}
  27. > CREATE CONNECTION conn
  28. FOR KAFKA BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT
  29. > CREATE CONNECTION c_conn
  30. FOR CONFLUENT SCHEMA REGISTRY URL '${testdrive.schema-registry-url}'
  31. > CREATE CLUSTER upsert_cluster SIZE '1';
  32. > CREATE SOURCE upsert
  33. IN CLUSTER upsert_cluster
  34. FROM KAFKA CONNECTION conn (TOPIC
  35. 'testdrive-upsert-${testdrive.seed}'
  36. )
  37. > CREATE TABLE upsert_tbl FROM SOURCE upsert (REFERENCE "testdrive-upsert-${testdrive.seed}")
  38. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION c_conn
  39. ENVELOPE UPSERT
  40. > SELECT f2 from upsert_tbl
  41. 1
  42. $ kafka-ingest format=avro topic=upsert key-format=avro key-schema=${keyschema} schema=${schema}
  43. {"key": "fish"} {"f1": "s", "f2": 2}
  44. > SELECT f2 from upsert_tbl
  45. 2