steady-state-source-statistics.td 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. > CREATE TABLE upsert_tbl FROM SOURCE upsert (REFERENCE "testdrive-upsert-${testdrive.seed}")
  54. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  55. INCLUDE OFFSET
  56. ENVELOPE UPSERT
  57. > CREATE SOURCE counter
  58. IN CLUSTER ${arg.single-replica-cluster}
  59. FROM LOAD GENERATOR COUNTER (UP TO 100);
  60. # Adding a select here so that the ingests after this
  61. # triggers lookup from the upsert state
  62. > SELECT key, f1, f2 FROM upsert_tbl
  63. key f1 f2
  64. ------------------------
  65. fish fish 1000
  66. birdmore geese 56
  67. mammalmore moose 2
  68. > SELECT
  69. s.name,
  70. SUM(u.offset_known) > 0,
  71. SUM(u.offset_known) = SUM(u.offset_committed)
  72. FROM mz_sources s
  73. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  74. WHERE s.name IN ('upsert')
  75. GROUP BY s.name
  76. ORDER BY s.name
  77. upsert true true
  78. > SELECT
  79. s.name,
  80. SUM(u.offset_known) > 0,
  81. SUM(u.offset_committed) > 0
  82. FROM mz_sources s
  83. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  84. WHERE s.name IN ('counter')
  85. GROUP BY s.name
  86. ORDER BY s.name
  87. counter true true
  88. $ set-from-sql var=previous-offset-known
  89. SELECT
  90. (SUM(u.offset_known))::text
  91. FROM mz_sources s
  92. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  93. WHERE s.name IN ('upsert')
  94. $ kafka-ingest format=avro topic=upsert key-format=avro key-schema=${keyschema} schema=${schema}
  95. {"key": "mammalmore"}
  96. > SELECT key, f1, f2 FROM upsert_tbl
  97. key f1 f2
  98. ------------------------
  99. fish fish 1000
  100. birdmore geese 56
  101. > SELECT
  102. s.name,
  103. SUM(u.offset_known) > ${previous-offset-known},
  104. SUM(u.offset_known) = SUM(u.offset_committed)
  105. FROM mz_sources s
  106. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  107. WHERE s.name IN ('upsert')
  108. GROUP BY s.name
  109. ORDER BY s.name
  110. upsert true true
  111. > DROP SOURCE upsert CASCADE
  112. > DROP SOURCE counter CASCADE