avro-decode-mismatched-types.td 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #
  11. # Make sure that reading an Avro buffer with a schema different from the one that was used
  12. # when it was written does not cause panics or anything like that.
  13. #
  14. # Note that this test uses inline Avro schemas and not the schema registry, so any
  15. # protections thus provided are not in force.
  16. #
  17. $ set null={"type": "record", "name": "field_null", "fields": [ {"name": "f1", "type": "null"} ] }
  18. $ set boolean={"type": "record", "name": "field_boolean", "fields": [ {"name": "f1", "type": "boolean"} ] }
  19. $ set int={"type": "record", "name": "field_int", "fields": [ {"name": "f1", "type": "int"} ] }
  20. $ set long={"type": "record", "name": "field_long", "fields": [ {"name": "f1", "type": "long"} ] }
  21. $ set float={"type": "record", "name": "field_float", "fields": [ {"name": "f1", "type": "float"} ] }
  22. $ set double={"type": "record", "name": "field_double", "fields": [ {"name": "f1", "type": "double"} ] }
  23. $ set bytes={"type": "record", "name": "field_bytes", "fields": [ {"name": "f1", "type": "bytes"} ] }
  24. $ set string={"type": "record", "name": "field_string", "fields": [ {"name": "f1", "type": "string"} ] }
  25. #
  26. # Null -> int
  27. #
  28. $ kafka-create-topic topic=avro-types-null2int
  29. $ kafka-ingest format=avro topic=avro-types-null2int schema=${null} timestamp=1
  30. {"f1": null}
  31. > CREATE CONNECTION kafka_conn
  32. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  33. > CREATE SOURCE avro_types_null2int
  34. IN CLUSTER ${arg.single-replica-cluster}
  35. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-null2int-${testdrive.seed}')
  36. FORMAT AVRO USING SCHEMA '${int}'
  37. ENVELOPE NONE
  38. ! SELECT * FROM avro_types_null2int
  39. contains:avro deserialization error: unable to decode row : IO error: UnexpectedEof
  40. #
  41. # boolean -> int
  42. #
  43. $ kafka-create-topic topic=avro-types-boolean2int
  44. $ kafka-ingest format=avro topic=avro-types-boolean2int schema=${boolean} timestamp=1
  45. {"f1": true}
  46. {"f1": false}
  47. > CREATE SOURCE avro_types_boolean2int
  48. IN CLUSTER ${arg.single-replica-cluster}
  49. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-boolean2int-${testdrive.seed}')
  50. FORMAT AVRO USING SCHEMA '${int}'
  51. ENVELOPE NONE
  52. # Bogus result, but at least we do not panic
  53. > SELECT f1 FROM avro_types_boolean2int
  54. -1
  55. 0
  56. #
  57. # int -> long
  58. #
  59. $ kafka-create-topic topic=avro-types-int2long
  60. $ kafka-ingest format=avro topic=avro-types-int2long schema=${int} timestamp=1
  61. {"f1": 123}
  62. > CREATE SOURCE avro_types_int2long
  63. IN CLUSTER ${arg.single-replica-cluster}
  64. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-int2long-${testdrive.seed}')
  65. FORMAT AVRO USING SCHEMA '${long}'
  66. ENVELOPE NONE
  67. > SELECT * FROM avro_types_int2long
  68. 123
  69. #
  70. # int -> float
  71. #
  72. $ kafka-create-topic topic=avro-types-int2float
  73. $ kafka-ingest format=avro topic=avro-types-int2float schema=${int} timestamp=1
  74. {"f1": 123}
  75. > CREATE SOURCE avro_types_int2float
  76. IN CLUSTER ${arg.single-replica-cluster}
  77. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-int2float-${testdrive.seed}')
  78. FORMAT AVRO USING SCHEMA '${float}'
  79. ENVELOPE NONE
  80. ! SELECT * FROM avro_types_int2float
  81. contains:avro deserialization error: unable to decode row : IO error: UnexpectedEof
  82. #
  83. # long -> float
  84. #
  85. $ kafka-create-topic topic=avro-types-long2float
  86. $ kafka-ingest format=avro topic=avro-types-long2float schema=${long} timestamp=1
  87. {"f1": 992147483647}
  88. > CREATE SOURCE avro_types_long2float
  89. IN CLUSTER ${arg.single-replica-cluster}
  90. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-long2float-${testdrive.seed}')
  91. FORMAT AVRO USING SCHEMA '${float}'
  92. ENVELOPE NONE
  93. ! SELECT * FROM avro_types_long2float
  94. contains:Unexpected bytes remaining
  95. #
  96. # long -> int
  97. #
  98. $ kafka-create-topic topic=avro-types-long2int
  99. $ kafka-ingest format=avro topic=avro-types-long2int schema=${long} timestamp=1
  100. {"f1": 992147483647}
  101. > CREATE SOURCE avro_types_long2int
  102. IN CLUSTER ${arg.single-replica-cluster}
  103. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-long2int-${testdrive.seed}')
  104. FORMAT AVRO USING SCHEMA '${int}'
  105. ENVELOPE NONE
  106. ! SELECT * FROM avro_types_long2int
  107. contains:Decoding error: Expected i32, got: 992147483647
  108. #
  109. # float -> double
  110. #
  111. $ kafka-create-topic topic=avro-types-float2double
  112. $ kafka-ingest format=avro topic=avro-types-float2double schema=${float} timestamp=1
  113. {"f1": 123456789.123456789}
  114. > CREATE SOURCE avro_types_float2double
  115. IN CLUSTER ${arg.single-replica-cluster}
  116. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-float2double-${testdrive.seed}')
  117. FORMAT AVRO USING SCHEMA '${double}'
  118. ENVELOPE NONE
  119. ! SELECT * FROM avro_types_float2double
  120. contains:avro deserialization error: unable to decode row : IO error: UnexpectedEof
  121. #
  122. # avro-typestion string -> bytes
  123. #
  124. $ kafka-create-topic topic=avro-types-string2bytes
  125. $ kafka-ingest format=avro topic=avro-types-string2bytes schema=${string} timestamp=1
  126. {"f1": "abc абц"}
  127. > CREATE SOURCE avro_types_string2bytes
  128. IN CLUSTER ${arg.single-replica-cluster}
  129. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-string2bytes-${testdrive.seed}')
  130. FORMAT AVRO USING SCHEMA '${bytes}'
  131. ENVELOPE NONE
  132. > SELECT * FROM avro_types_string2bytes
  133. "abc \\xd0\\xb0\\xd0\\xb1\\xd1\\x86"