avro-decode-mismatched-types.td 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. > CREATE TABLE avro_types_null2int_tbl FROM SOURCE avro_types_null2int (REFERENCE "testdrive-avro-types-null2int-${testdrive.seed}")
  37. FORMAT AVRO USING SCHEMA '${int}'
  38. ENVELOPE NONE
  39. ! SELECT * FROM avro_types_null2int_tbl
  40. contains:avro deserialization error: unable to decode row : IO error: UnexpectedEof
  41. #
  42. # boolean -> int
  43. #
  44. $ kafka-create-topic topic=avro-types-boolean2int
  45. $ kafka-ingest format=avro topic=avro-types-boolean2int schema=${boolean} timestamp=1
  46. {"f1": true}
  47. {"f1": false}
  48. > CREATE SOURCE avro_types_boolean2int
  49. IN CLUSTER ${arg.single-replica-cluster}
  50. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-boolean2int-${testdrive.seed}')
  51. > CREATE TABLE avro_types_boolean2int_tbl FROM SOURCE avro_types_boolean2int (REFERENCE "testdrive-avro-types-boolean2int-${testdrive.seed}")
  52. FORMAT AVRO USING SCHEMA '${int}'
  53. ENVELOPE NONE
  54. # Bogus result, but at least we do not panic
  55. > SELECT f1 FROM avro_types_boolean2int_tbl
  56. -1
  57. 0
  58. #
  59. # int -> long
  60. #
  61. $ kafka-create-topic topic=avro-types-int2long
  62. $ kafka-ingest format=avro topic=avro-types-int2long schema=${int} timestamp=1
  63. {"f1": 123}
  64. > CREATE SOURCE avro_types_int2long
  65. IN CLUSTER ${arg.single-replica-cluster}
  66. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-int2long-${testdrive.seed}')
  67. > CREATE TABLE avro_types_int2long_tbl FROM SOURCE avro_types_int2long (REFERENCE "testdrive-avro-types-int2long-${testdrive.seed}")
  68. FORMAT AVRO USING SCHEMA '${long}'
  69. ENVELOPE NONE
  70. > SELECT * FROM avro_types_int2long_tbl
  71. 123
  72. #
  73. # int -> float
  74. #
  75. $ kafka-create-topic topic=avro-types-int2float
  76. $ kafka-ingest format=avro topic=avro-types-int2float schema=${int} timestamp=1
  77. {"f1": 123}
  78. > CREATE SOURCE avro_types_int2float
  79. IN CLUSTER ${arg.single-replica-cluster}
  80. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-int2float-${testdrive.seed}')
  81. > CREATE TABLE avro_types_int2float_tbl FROM SOURCE avro_types_int2float (REFERENCE "testdrive-avro-types-int2float-${testdrive.seed}")
  82. FORMAT AVRO USING SCHEMA '${float}'
  83. ENVELOPE NONE
  84. ! SELECT * FROM avro_types_int2float_tbl
  85. contains:avro deserialization error: unable to decode row : IO error: UnexpectedEof
  86. #
  87. # long -> float
  88. #
  89. $ kafka-create-topic topic=avro-types-long2float
  90. $ kafka-ingest format=avro topic=avro-types-long2float schema=${long} timestamp=1
  91. {"f1": 992147483647}
  92. > CREATE SOURCE avro_types_long2float
  93. IN CLUSTER ${arg.single-replica-cluster}
  94. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-long2float-${testdrive.seed}')
  95. > CREATE TABLE avro_types_long2float_tbl FROM SOURCE avro_types_long2float (REFERENCE "testdrive-avro-types-long2float-${testdrive.seed}")
  96. FORMAT AVRO USING SCHEMA '${float}'
  97. ENVELOPE NONE
  98. ! SELECT * FROM avro_types_long2float_tbl
  99. contains:Unexpected bytes remaining
  100. #
  101. # long -> int
  102. #
  103. $ kafka-create-topic topic=avro-types-long2int
  104. $ kafka-ingest format=avro topic=avro-types-long2int schema=${long} timestamp=1
  105. {"f1": 992147483647}
  106. > CREATE SOURCE avro_types_long2int
  107. IN CLUSTER ${arg.single-replica-cluster}
  108. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-long2int-${testdrive.seed}')
  109. > CREATE TABLE avro_types_long2int_tbl FROM SOURCE avro_types_long2int (REFERENCE "testdrive-avro-types-long2int-${testdrive.seed}")
  110. FORMAT AVRO USING SCHEMA '${int}'
  111. ENVELOPE NONE
  112. ! SELECT * FROM avro_types_long2int_tbl
  113. contains:Decoding error: Expected i32, got: 992147483647
  114. #
  115. # float -> double
  116. #
  117. $ kafka-create-topic topic=avro-types-float2double
  118. $ kafka-ingest format=avro topic=avro-types-float2double schema=${float} timestamp=1
  119. {"f1": 123456789.123456789}
  120. > CREATE SOURCE avro_types_float2double
  121. IN CLUSTER ${arg.single-replica-cluster}
  122. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-float2double-${testdrive.seed}')
  123. > CREATE TABLE avro_types_float2double_tbl FROM SOURCE avro_types_float2double (REFERENCE "testdrive-avro-types-float2double-${testdrive.seed}")
  124. FORMAT AVRO USING SCHEMA '${double}'
  125. ENVELOPE NONE
  126. ! SELECT * FROM avro_types_float2double_tbl
  127. contains:avro deserialization error: unable to decode row : IO error: UnexpectedEof
  128. #
  129. # avro-typestion string -> bytes
  130. #
  131. $ kafka-create-topic topic=avro-types-string2bytes
  132. $ kafka-ingest format=avro topic=avro-types-string2bytes schema=${string} timestamp=1
  133. {"f1": "abc абц"}
  134. > CREATE SOURCE avro_types_string2bytes
  135. IN CLUSTER ${arg.single-replica-cluster}
  136. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-types-string2bytes-${testdrive.seed}')
  137. > CREATE TABLE avro_types_string2bytes_tbl FROM SOURCE avro_types_string2bytes (REFERENCE "testdrive-avro-types-string2bytes-${testdrive.seed}")
  138. FORMAT AVRO USING SCHEMA '${bytes}'
  139. ENVELOPE NONE
  140. > SELECT * FROM avro_types_string2bytes_tbl
  141. "abc \\xd0\\xb0\\xd0\\xb1\\xd1\\x86"