steady-state-source-statistics.td 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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-arg-default single-replica-cluster=quickstart
  10. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  11. ALTER SYSTEM SET storage_statistics_collection_interval = 1000
  12. ALTER SYSTEM SET storage_statistics_interval = 2000
  13. $ set keyschema={
  14. "type": "record",
  15. "name": "Key",
  16. "fields": [
  17. {"name": "key", "type": "string"}
  18. ]
  19. }
  20. $ set schema={
  21. "type" : "record",
  22. "name" : "test",
  23. "fields" : [
  24. {"name":"f1", "type":"string"},
  25. {"name":"f2", "type":"long"}
  26. ]
  27. }
  28. $ kafka-create-topic topic=upsert partitions=2
  29. $ kafka-ingest format=avro topic=upsert key-format=avro key-schema=${keyschema} schema=${schema}
  30. {"key": "fish"} {"f1": "fish", "f2": 1000}
  31. {"key": "bird1"} {"f1":"goose", "f2": 1}
  32. {"key": "birdmore"} {"f1":"geese", "f2": 2}
  33. {"key": "mammal1"} {"f1": "moose", "f2": 1}
  34. {"key": "bird1"}
  35. {"key": "birdmore"} {"f1":"geese", "f2": 56}
  36. {"key": "mammalmore"} {"f1": "moose", "f2": 42}
  37. {"key": "mammal1"}
  38. {"key": "mammalmore"} {"f1":"moose", "f2": 2}
  39. $ kafka-create-topic topic=metrics-test partitions=1
  40. $ kafka-ingest topic=metrics-test format=bytes
  41. jack,jill
  42. goofus,gallant
  43. > CREATE CONNECTION kafka_conn
  44. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  45. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  46. URL '${testdrive.schema-registry-url}'
  47. );
  48. > CREATE SOURCE upsert
  49. IN CLUSTER ${arg.single-replica-cluster}
  50. FROM KAFKA CONNECTION kafka_conn (TOPIC
  51. 'testdrive-upsert-${testdrive.seed}'
  52. )
  53. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  54. INCLUDE OFFSET
  55. ENVELOPE UPSERT
  56. > CREATE SOURCE counter
  57. IN CLUSTER ${arg.single-replica-cluster}
  58. FROM LOAD GENERATOR COUNTER (UP TO 100);
  59. # Adding a select here so that the ingests after this
  60. # triggers lookup from the upsert state
  61. > SELECT key, f1, f2 FROM upsert
  62. key f1 f2
  63. ------------------------
  64. fish fish 1000
  65. birdmore geese 56
  66. mammalmore moose 2
  67. > SELECT
  68. s.name,
  69. SUM(u.offset_known) > 0,
  70. SUM(u.offset_known) = SUM(u.offset_committed)
  71. FROM mz_sources s
  72. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  73. WHERE s.name IN ('upsert')
  74. GROUP BY s.name
  75. ORDER BY s.name
  76. upsert true true
  77. > SELECT
  78. s.name,
  79. SUM(u.offset_known) > 0,
  80. SUM(u.offset_committed) > 0
  81. FROM mz_sources s
  82. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  83. WHERE s.name IN ('counter')
  84. GROUP BY s.name
  85. ORDER BY s.name
  86. counter true true
  87. $ set-from-sql var=previous-offset-known
  88. SELECT
  89. (SUM(u.offset_known))::text
  90. FROM mz_sources s
  91. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  92. WHERE s.name IN ('upsert')
  93. $ kafka-ingest format=avro topic=upsert key-format=avro key-schema=${keyschema} schema=${schema}
  94. {"key": "mammalmore"}
  95. > SELECT key, f1, f2 FROM upsert
  96. key f1 f2
  97. ------------------------
  98. fish fish 1000
  99. birdmore geese 56
  100. > SELECT
  101. s.name,
  102. SUM(u.offset_known) > ${previous-offset-known},
  103. SUM(u.offset_known) = SUM(u.offset_committed)
  104. FROM mz_sources s
  105. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  106. WHERE s.name IN ('upsert')
  107. GROUP BY s.name
  108. ORDER BY s.name
  109. upsert true true
  110. > DROP SOURCE upsert CASCADE
  111. > DROP SOURCE counter CASCADE