avro-registry-schema-selection.td 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 default-storage-size=1
  10. # Tests that precisely manipulate which schema to select from the
  11. # Confluent Schema Registry.
  12. $ kafka-create-topic topic=schema-strategy-test
  13. $ set first-writer-schema={"type": "record", "name": "row", "fields": [{"name": "a", "type": "long"}, {"name": "b", "type": "long"}]}
  14. $ set second-writer-schema={"type": "record", "name": "row", "fields": [{"name": "a", "type": "long"}, {"name": "b", "type": "long"}, {"name": "c", "type": ["null", "long"], "default": null}]}
  15. $ set reader-schema={"type": "record", "name": "row", "fields": [{"name": "a", "type": "long"}]}
  16. $ kafka-ingest format=avro topic=schema-strategy-test schema=${first-writer-schema} set-schema-id-var=id1
  17. {"a": 0, "b": 1}
  18. $ kafka-ingest format=avro topic=schema-strategy-test schema=${second-writer-schema} set-schema-id-var=id2
  19. {"a": 2, "b": 3, "c": {"long": 4}}
  20. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  21. URL '${testdrive.schema-registry-url}'
  22. );
  23. > CREATE CONNECTION kafka_conn
  24. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  25. > CREATE CLUSTER schema_strategy_test_inline_cluster SIZE '${arg.default-storage-size}';
  26. > CREATE SOURCE schema_strategy_test_inline
  27. IN CLUSTER schema_strategy_test_inline_cluster
  28. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-schema-strategy-test-${testdrive.seed}')
  29. > CREATE TABLE schema_strategy_test_inline_tbl FROM SOURCE schema_strategy_test_inline (REFERENCE "testdrive-schema-strategy-test-${testdrive.seed}")
  30. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  31. VALUE STRATEGY INLINE '${reader-schema}'
  32. ENVELOPE NONE
  33. > SELECT * FROM schema_strategy_test_inline_tbl
  34. a
  35. ---
  36. 0
  37. 2
  38. > CREATE CLUSTER schema_strategy_test_id_cluster SIZE '${arg.default-storage-size}';
  39. > CREATE SOURCE schema_strategy_test_id
  40. IN CLUSTER schema_strategy_test_id_cluster
  41. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-schema-strategy-test-${testdrive.seed}')
  42. > CREATE TABLE schema_strategy_test_id_tbl FROM SOURCE schema_strategy_test_id (REFERENCE "testdrive-schema-strategy-test-${testdrive.seed}")
  43. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  44. VALUE STRATEGY ID ${id1}
  45. ENVELOPE NONE
  46. > SELECT * FROM schema_strategy_test_id_tbl
  47. a b
  48. ---
  49. 0 1
  50. 2 3
  51. > CREATE CLUSTER schema_strategy_test_id2_cluster SIZE '${arg.default-storage-size}';
  52. > CREATE SOURCE schema_strategy_test_id2
  53. IN CLUSTER schema_strategy_test_id2_cluster
  54. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-schema-strategy-test-${testdrive.seed}')
  55. > CREATE TABLE schema_strategy_test_id2_tbl FROM SOURCE schema_strategy_test_id2 (REFERENCE "testdrive-schema-strategy-test-${testdrive.seed}")
  56. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  57. VALUE STRATEGY ID ${id2}
  58. ENVELOPE NONE
  59. > SELECT * FROM schema_strategy_test_id2_tbl
  60. a b c
  61. -----
  62. 0 1 <null>
  63. 2 3 4
  64. > CREATE CLUSTER schema_strategy_test_latest_cluster SIZE '${arg.default-storage-size}';
  65. > CREATE SOURCE schema_strategy_test_latest
  66. IN CLUSTER schema_strategy_test_latest_cluster
  67. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-schema-strategy-test-${testdrive.seed}')
  68. > CREATE TABLE schema_strategy_test_latest_tbl FROM SOURCE schema_strategy_test_latest (REFERENCE "testdrive-schema-strategy-test-${testdrive.seed}")
  69. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  70. VALUE STRATEGY LATEST
  71. ENVELOPE NONE
  72. > SELECT * FROM schema_strategy_test_latest_tbl
  73. a b c
  74. -----
  75. 0 1 <null>
  76. 2 3 4