source-format-json.td 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. # Verify behavior of FORMAT JSON
  11. $ kafka-create-topic topic=data partitions=1
  12. $ kafka-ingest format=bytes topic=data
  13. {"a":"b","c":"d"}
  14. > CREATE CONNECTION kafka_conn
  15. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  16. > CREATE SOURCE data
  17. IN CLUSTER ${arg.single-replica-cluster}
  18. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}');
  19. ! CREATE TABLE data_tbl FROM SOURCE data (REFERENCE "testdrive-data-${testdrive.seed}")
  20. FORMAT JSON ARRAY;
  21. contains:JSON ARRAY format in sources not yet supported
  22. > CREATE TABLE data_tbl FROM SOURCE data (REFERENCE "testdrive-data-${testdrive.seed}")
  23. FORMAT JSON;
  24. > SELECT DISTINCT pg_typeof(data) FROM data_tbl;
  25. jsonb
  26. > SELECT * FROM data_tbl
  27. "{\"a\":\"b\",\"c\":\"d\"}"
  28. # It's a dict so this is not just a string masquerading as JSON
  29. > SELECT data -> 'a' FROM data_tbl;
  30. "\"b\""
  31. $ kafka-ingest format=bytes topic=data
  32. [1,2,3]
  33. 1
  34. 1.23
  35. "hello"
  36. ""
  37. > SELECT * FROM data_tbl
  38. [1,2,3]
  39. 1
  40. 1.23
  41. "\"hello\""
  42. "\"\""
  43. "{\"a\":\"b\",\"c\":\"d\"}"
  44. $ kafka-ingest format=bytes topic=data
  45. { "@timestamp":"2015-06-03T22:20:44.000Z", "latitude":39.613658, "longitude":4.9E-324, "location":[-86.106653,39.613658] }
  46. ! SELECT * FROM data_tbl
  47. exact:Decode error: Failed to decode JSON: "4.9E-324" is out of range for type numeric: exceeds maximum precision 39 at line 1 column 85 (original text: { "@timestamp":"2015-06-03T22:20:44.000Z", "latitude":39.613658, "longitude":4.9E-324, "location":[-86.106653,39.613658] }, original bytes: "7b20224074696d657374616d70223a22323031352d30362d30335432323a32303a34342e3030305a222c20226c61746974756465223a33392e3631333635382c20226c6f6e676974756465223a342e39452d3332342c20226c6f636174696f6e223a5b2d38362e3130363635332c33392e3631333635385d207d")