avro-decode-mismatched-columns.td 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. FORMAT AVRO USING SCHEMA '${2columns-nodefault}'
  29. ENVELOPE NONE
  30. ! SELECT * FROM decode_1to2_nodefault
  31. contains:avro deserialization error: unable to decode row : IO error: UnexpectedEof
  32. #
  33. # 1 column -> 2 columns with default
  34. #
  35. $ kafka-create-topic topic=decode-1to2-default
  36. $ kafka-ingest format=avro topic=decode-1to2-default schema=${1column} timestamp=1
  37. {"f1": 123}
  38. > CREATE SOURCE decode_1to2_default
  39. IN CLUSTER ${arg.single-replica-cluster}
  40. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-decode-1to2-default-${testdrive.seed}')
  41. FORMAT AVRO USING SCHEMA '${2columns-default}'
  42. ENVELOPE NONE
  43. ! SELECT * FROM decode_1to2_default
  44. contains:Decode error: avro deserialization error: unable to decode row : IO error: UnexpectedEof
  45. #
  46. # 2 columns -> 1 column
  47. #
  48. $ kafka-create-topic topic=decode-2to1
  49. $ kafka-ingest format=avro topic=decode-2to1 schema=${2columns-nodefault} timestamp=1
  50. {"f1": 123, "f2": 234}
  51. {"f2": 345, "f1": 456}
  52. > CREATE SOURCE decode_2to1
  53. IN CLUSTER ${arg.single-replica-cluster}
  54. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-decode-2to1-${testdrive.seed}')
  55. FORMAT AVRO USING SCHEMA '${1column}'
  56. ENVELOPE NONE
  57. ! SELECT * FROM decode_2to1
  58. contains:Unexpected bytes remaining