02-source-setup.td 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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": "fish", "f2": 1000}
  27. {"key": "bird1"} {"f1":"goose", "f2": 1}
  28. {"key": "birdmore"} {"f1":"geese", "f2": 2}
  29. {"key": "mammal1"} {"f1": "moose", "f2": 1}
  30. {"key": "bird1"}
  31. {"key": "birdmore"} {"f1":"geese", "f2": 56}
  32. {"key": "mammalmore"} {"f1": "moose", "f2": 42}
  33. {"key": "mammal1"}
  34. {"key": "mammalmore"} {"f1":"moose", "f2": 2}
  35. > CREATE CONNECTION conn
  36. FOR KAFKA BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT
  37. > CREATE CONNECTION c_conn
  38. FOR CONFLUENT SCHEMA REGISTRY URL '${testdrive.schema-registry-url}'
  39. > CREATE SOURCE upsert
  40. IN CLUSTER storage_cluster
  41. FROM KAFKA CONNECTION conn (TOPIC
  42. 'testdrive-upsert-${testdrive.seed}'
  43. )
  44. > CREATE TABLE upsert_tbl FROM SOURCE upsert (REFERENCE "testdrive-upsert-${testdrive.seed}")
  45. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION c_conn
  46. ENVELOPE UPSERT
  47. > SELECT * from upsert_tbl
  48. key f1 f2
  49. ---------------------------
  50. fish fish 1000
  51. birdmore geese 56
  52. mammalmore moose 2
  53. # NOTE: These queries are slow to succeed because the default metrics scraping
  54. # interval is 30 seconds.
  55. #
  56. # Ensure that statistics are correctly updated
  57. > SELECT
  58. SUM(u.bytes_indexed) > 0,
  59. SUM(u.records_indexed),
  60. bool_and(u.rehydration_latency IS NOT NULL)
  61. FROM mz_tables t
  62. JOIN mz_internal.mz_source_statistics_raw u ON t.id = u.id
  63. WHERE t.name IN ('upsert_tbl')
  64. GROUP BY t.name
  65. ORDER BY t.name
  66. true 3 true
  67. # Write another part to test backpressure
  68. $ kafka-ingest format=avro topic=upsert key-format=avro key-schema=${keyschema} schema=${schema}
  69. {"key": "fish"} {"f1": "fish", "f2": 1001}
  70. > SELECT * from upsert_tbl
  71. key f1 f2
  72. ---------------------------
  73. fish fish 1001
  74. birdmore geese 56
  75. mammalmore moose 2