protobuf-basic.td 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 basic types in a Protobuf message are decoded correctly.
  11. $ file-append path=basic.proto
  12. syntax = "proto3";
  13. message Basic {
  14. enum Enum {
  15. ENUM0 = 0;
  16. ENUM1 = 1;
  17. }
  18. message Nested {
  19. bool bool = 1;
  20. int32 int32 = 2;
  21. int64 int64 = 3;
  22. sint32 sint32 = 4;
  23. sint64 sint64 = 5;
  24. sfixed32 sfixed32 = 6;
  25. sfixed64 sfixed64 = 7;
  26. uint32 uint32 = 8;
  27. uint64 uint64 = 9;
  28. fixed32 fixed32 = 10;
  29. fixed64 fixed64 = 11;
  30. float float = 12;
  31. double double = 13;
  32. bytes bytes = 14;
  33. string string = 15;
  34. Enum enum = 16;
  35. }
  36. bool bool = 1;
  37. int32 int32 = 2;
  38. int64 int64 = 3;
  39. sint32 sint32 = 4;
  40. sint64 sint64 = 5;
  41. sfixed32 sfixed32 = 6;
  42. sfixed64 sfixed64 = 7;
  43. uint32 uint32 = 8;
  44. uint64 uint64 = 9;
  45. fixed32 fixed32 = 10;
  46. fixed64 fixed64 = 11;
  47. float float = 12;
  48. double double = 13;
  49. bytes bytes = 14;
  50. string string = 15;
  51. Enum enum = 16;
  52. Nested message = 17;
  53. }
  54. $ protobuf-compile-descriptors inputs=basic.proto output=basic.pb set-var=basic-schema
  55. $ kafka-create-topic topic=basic partitions=1
  56. $ kafka-ingest topic=basic format=protobuf descriptor-file=basic.pb message=Basic
  57. {"bool": true, "int32": 1, "int64": 2, "sint32": -1, "sint64": -2, "sfixed32": -3, "sfixed64": -4, "uint32": 3, "uint64": 4, "fixed32": 5, "fixed64": 6, "float": 1.2, "double": 3.2, "bytes": "YWFh", "string": "bbb", "enum": "ENUM1", "message": {"bool": true, "int32": 1, "int64": 2, "sint32": -1, "sint64": -2, "sfixed32": -3, "sfixed64": -4, "uint32": 3, "uint64": 4, "fixed32": 5, "fixed64": 6, "float": 1.2, "double": 3.2, "bytes": "YWFh", "string": "bbb", "enum": "ENUM1"}}
  58. {}
  59. # Test the case where the nested message is explicitly set to all default
  60. # values. This previously crashed Materialize (see database-issues#2723).
  61. {"message": {}}
  62. > CREATE CONNECTION kafka_conn
  63. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  64. > CREATE SOURCE basic
  65. IN CLUSTER ${arg.single-replica-cluster}
  66. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-basic-${testdrive.seed}')
  67. > CREATE TABLE basic_tbl FROM SOURCE basic (REFERENCE "testdrive-basic-${testdrive.seed}")
  68. FORMAT PROTOBUF MESSAGE '.Basic' USING SCHEMA '${basic-schema}'
  69. > SHOW COLUMNS FROM basic_tbl
  70. name nullable type comment
  71. ------------------------------------------------
  72. bool false boolean ""
  73. int32 false integer ""
  74. int64 false bigint ""
  75. sint32 false integer ""
  76. sint64 false bigint ""
  77. sfixed32 false integer ""
  78. sfixed64 false bigint ""
  79. uint32 false uint4 ""
  80. uint64 false uint8 ""
  81. fixed32 false uint4 ""
  82. fixed64 false uint8 ""
  83. float false real ""
  84. double false "double precision" ""
  85. bytes false bytea ""
  86. string false text ""
  87. enum false text ""
  88. message true record ""
  89. > SELECT bool, int32, int64, sint32, sint64, sfixed32, sfixed64, uint32, uint64, fixed32, fixed64, float, double, bytes, string, enum, message::text FROM basic_tbl
  90. bool int32 int64 sint32 sint64 sfixed32 sfixed64 uint32 uint64 fixed32 fixed64 float double bytes string enum message
  91. ----
  92. true 1 2 -1 -2 -3 -4 3 4 5 6 1.2 3.2 aaa bbb ENUM1 "(t,1,2,-1,-2,-3,-4,3,4,5,6,1.2,3.2,\"\\\\x616161\",bbb,ENUM1)"
  93. false 0 0 0 0 0 0 0 0 0 0 0 0 "" "" ENUM0 <null>
  94. false 0 0 0 0 0 0 0 0 0 0 0 0 "" "" ENUM0 "(f,0,0,0,0,0,0,0,0,0,0,0,0,\"\\\\x\",\"\",ENUM0)"