protobuf-repeated.td 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. # Test that repeated fields in a Protobuf message are decoded correctly.
  11. $ file-append path=repeated.proto
  12. syntax = "proto3";
  13. message Repeated {
  14. enum Enum {
  15. ENUM0 = 0;
  16. ENUM1 = 1;
  17. }
  18. message Message {
  19. int32 m1 = 1;
  20. int32 m2 = 2;
  21. }
  22. repeated bool bool = 1;
  23. repeated int32 int32 = 2;
  24. repeated int64 int64 = 3;
  25. repeated float float = 4;
  26. repeated double double = 5;
  27. repeated bytes bytes = 6;
  28. repeated string string = 7;
  29. repeated Enum enum = 8;
  30. repeated Message message = 9;
  31. }
  32. $ protobuf-compile-descriptors inputs=repeated.proto output=repeated.pb set-var=repeated-schema
  33. $ kafka-create-topic topic=repeated partitions=1
  34. $ kafka-ingest topic=repeated format=protobuf descriptor-file=repeated.pb message=Repeated
  35. {"bool": [true, false], "int32": [2, 1], "int64": [2, 1], "float": [3.2, 1.0], "double": [3.2, 1.0], "bytes": ["YmJi", "YWFh"], "string": ["bbb", "aaa"], "enum": ["ENUM1", "ENUM0"], "message": [{"m1": 4, "m2": 2}, {"m1": 2, "m2": 4}]}
  36. {}
  37. > CREATE CONNECTION kafka_conn
  38. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  39. > CREATE SOURCE repeated
  40. IN CLUSTER ${arg.single-replica-cluster}
  41. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-repeated-${testdrive.seed}')
  42. FORMAT PROTOBUF MESSAGE '.Repeated' USING SCHEMA '${repeated-schema}'
  43. > SHOW COLUMNS FROM repeated
  44. name nullable type comment
  45. ----------------------------------
  46. bool false list ""
  47. int32 false list ""
  48. int64 false list ""
  49. float false list ""
  50. double false list ""
  51. bytes false list ""
  52. string false list ""
  53. enum false list ""
  54. message false list ""
  55. > SELECT bool::text, int32::text, int64::text, float::text, double::text, string::text, bytes::text, enum::text, message::text FROM repeated
  56. bool int32 int64 float double string bytes enum message
  57. ----
  58. {t,f} {2,1} {2,1} {3.2,1} {3.2,1} {bbb,aaa} "{\"\\\\x626262\",\"\\\\x616161\"}" {ENUM1,ENUM0} "{\"(4,2)\",\"(2,4)\"}"
  59. {} {} {} {} {} {} {} {} {}