avro-decode-mismatched-columns.td 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $ set 1column={"type": "record", "name": "schema_1column", "fields": [ {"name": "f1", "type": "int"} ] }
  15. $ set 2columns-nodefault={"type": "record", "name": "schema_2columns_nodefault", "fields": [ {"name": "f1", "type": "int"} , {"name": "f2", "type": "int"} ] }
  16. $ set 2columns-default={"type": "record", "name": "schema_2columns_default", "fields": [ {"name": "f1", "type": "int"} , {"name": "f2", "type": "int", "default": "345"} ] }
  17. #
  18. # 1 column -> 2 columns with no default
  19. #
  20. $ kafka-create-topic topic=decode-1to2-nodefault
  21. $ kafka-ingest format=avro topic=decode-1to2-nodefault schema=${1column} timestamp=1
  22. {"f1": 123}
  23. > CREATE CONNECTION kafka_conn
  24. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  25. > CREATE SOURCE decode_1to2_nodefault
  26. IN CLUSTER ${arg.single-replica-cluster}
  27. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-decode-1to2-nodefault-${testdrive.seed}')
  28. > CREATE TABLE decode_1to2_nodefault_tbl FROM SOURCE decode_1to2_nodefault (REFERENCE "testdrive-decode-1to2-nodefault-${testdrive.seed}")
  29. FORMAT AVRO USING SCHEMA '${2columns-nodefault}'
  30. ENVELOPE NONE
  31. ! SELECT * FROM decode_1to2_nodefault_tbl
  32. contains:avro deserialization error: unable to decode row : IO error: UnexpectedEof
  33. #
  34. # 1 column -> 2 columns with default
  35. #
  36. $ kafka-create-topic topic=decode-1to2-default
  37. $ kafka-ingest format=avro topic=decode-1to2-default schema=${1column} timestamp=1
  38. {"f1": 123}
  39. > CREATE SOURCE decode_1to2_default
  40. IN CLUSTER ${arg.single-replica-cluster}
  41. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-decode-1to2-default-${testdrive.seed}')
  42. > CREATE TABLE decode_1to2_default_tbl FROM SOURCE decode_1to2_default (REFERENCE "testdrive-decode-1to2-default-${testdrive.seed}")
  43. FORMAT AVRO USING SCHEMA '${2columns-default}'
  44. ENVELOPE NONE
  45. ! SELECT * FROM decode_1to2_default_tbl
  46. contains:Decode error: avro deserialization error: unable to decode row : IO error: UnexpectedEof
  47. #
  48. # 2 columns -> 1 column
  49. #
  50. $ kafka-create-topic topic=decode-2to1
  51. $ kafka-ingest format=avro topic=decode-2to1 schema=${2columns-nodefault} timestamp=1
  52. {"f1": 123, "f2": 234}
  53. {"f2": 345, "f1": 456}
  54. > CREATE SOURCE decode_2to1
  55. IN CLUSTER ${arg.single-replica-cluster}
  56. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-decode-2to1-${testdrive.seed}')
  57. > CREATE TABLE decode_2to1_tbl FROM SOURCE decode_2to1 (REFERENCE "testdrive-decode-2to1-${testdrive.seed}")
  58. FORMAT AVRO USING SCHEMA '${1column}'
  59. ENVELOPE NONE
  60. ! SELECT * FROM decode_2to1_tbl
  61. contains:Unexpected bytes remaining