readysettech / readyset

Readyset is a MySQL and Postgres wire-compatible caching layer that sits in front of existing databases to speed up queries and horizontally scale read throughput. Under the hood, ReadySet caches the results of cached select statements and incrementally updates these results over time as the underlying data changes.
https://readyset.io
Other
4.54k stars 125 forks source link

Support for JSON opaque Values #1364

Closed altmannmarcelo closed 1 month ago

altmannmarcelo commented 2 months ago

Description

We need to add support for JSON opaque values. The current code assumed if we fail to serialize a json value to serde_json due to Opaque value, we would receive the opaque value as part of the error, which is not the case and we should manually parse each element of the json object and correctly serialize opaque values depending on their type.

DROP TABLE IF EXISTS j_test;
CREATE TABLE j_test (
  id INT NOT NULL AUTO_INCREMENT,
  j_field JSON NOT NULL,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO j_test (id, j_field, updated_at) VALUES (6, '{"order": {"orderId": 56789, "date": "2024-08-28", "items": [{"productId": 101, "quantity": 2, "price": 19.99}, {"productId": 202, "quantity": 1, "price": 49.99}], "totalAmount": 89.97}}', '2024-08-29 12:35:01');

-- snapshot
UPDATE j_test SET j_field = JSON_SET(j_field, '$.order.items[0].price', 24.99) WHERE id = 6;

Change in user-visible behavior

Requires documentation change