multipart-key-before.td 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. # Ingest a topic with a multi-part key
  11. #
  12. $ set keyschema={
  13. "type": "record",
  14. "name": "Key",
  15. "fields": [
  16. {"name": "f1", "type": "string"},
  17. {"name": "f2", "type": "string"}
  18. ]
  19. }
  20. $ set schema={
  21. "type" : "record",
  22. "name" : "test",
  23. "fields" : [
  24. {"name":"f3", "type":"string"},
  25. {"name":"f4", "type":"string"}
  26. ]
  27. }
  28. $ kafka-create-topic topic=multipart-key
  29. # Ingest data where the first or the second part of the key has high cardinality
  30. $ kafka-ingest format=avro topic=multipart-key key-format=avro key-schema=${keyschema} schema=${schema} repeat=10000
  31. {"f1": "KEY1", "f2": "${kafka-ingest.iteration}"} {"f3": "KEY1", "f4": "${kafka-ingest.iteration}"}
  32. {"f1": "${kafka-ingest.iteration}", "f2": "KEY2"} {"f3": "${kafka-ingest.iteration}", "f4": "KEY2"}
  33. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  34. URL '${testdrive.schema-registry-url}'
  35. );
  36. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  37. > CREATE SOURCE multipart_key
  38. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-multipart-key-${testdrive.seed}');
  39. > CREATE TABLE multipart_key_tbl FROM SOURCE multipart_key (REFERENCE "testdrive-multipart-key-${testdrive.seed}")
  40. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  41. ENVELOPE UPSERT;
  42. > SELECT COUNT(*) FROM multipart_key_tbl;
  43. 20000