From c41592ca61bf4305d36f34f3e3aead0cc1982d74 Mon Sep 17 00:00:00 2001 From: Spencer Torres Date: Sun, 16 Feb 2025 05:23:32 -0500 Subject: [PATCH 1/2] fix(json): proper encoding for json arrays --- proto/col_json_str.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/proto/col_json_str.go b/proto/col_json_str.go index 1d23a3a..069a526 100644 --- a/proto/col_json_str.go +++ b/proto/col_json_str.go @@ -34,6 +34,8 @@ var ( _ Column = (*ColJSONStr)(nil) _ ColumnOf[string] = (*ColJSONStr)(nil) _ Arrayable[string] = (*ColJSONStr)(nil) + _ StateEncoder = (*ColJSONStr)(nil) + _ StateDecoder = (*ColJSONStr)(nil) ) // Type returns ColumnType of JSON. @@ -51,19 +53,18 @@ func (c *ColJSONStr) Reset() { c.Str.Reset() } -// EncodeColumn encodes String rows to *Buffer. -func (c ColJSONStr) EncodeColumn(b *Buffer) { +// EncodeState encodes the JSON serialization version +func (c *ColJSONStr) EncodeState(b *Buffer) { b.PutUInt64(JSONStringSerializationVersion) +} +// EncodeColumn encodes String rows to *Buffer. +func (c ColJSONStr) EncodeColumn(b *Buffer) { c.Str.EncodeColumn(b) } // WriteColumn writes JSON rows to *Writer. func (c ColJSONStr) WriteColumn(w *Writer) { - w.ChainBuffer(func(b *Buffer) { - b.PutUInt64(JSONStringSerializationVersion) - }) - c.Str.WriteColumn(w) } @@ -92,8 +93,8 @@ func (c ColJSONStr) ForEachBytes(f func(i int, b []byte) error) error { return c.Str.ForEachBytes(f) } -// DecodeColumn decodes String rows from *Reader. -func (c *ColJSONStr) DecodeColumn(r *Reader, rows int) error { +// DecodeState decodes the JSON serialization version +func (c *ColJSONStr) DecodeState(r *Reader) error { jsonSerializationVersion, err := r.UInt64() if err != nil { return errors.Wrap(err, "failed to read json serialization version") @@ -103,6 +104,11 @@ func (c *ColJSONStr) DecodeColumn(r *Reader, rows int) error { return errors.Errorf("received invalid JSON string serialization version %d. Setting \"output_format_native_write_json_as_string\" must be enabled.", jsonSerializationVersion) } + return nil +} + +// DecodeColumn decodes String rows from *Reader. +func (c *ColJSONStr) DecodeColumn(r *Reader, rows int) error { return c.Str.DecodeColumn(r, rows) } From c419d9c691d6c0e3ffa263c0cfeaf6f379e4fcab Mon Sep 17 00:00:00 2001 From: Spencer Torres Date: Sun, 16 Feb 2025 12:00:41 -0500 Subject: [PATCH 2/2] fix(json): update json tests --- proto/_golden/col_json_str.hex | 11 +++++------ proto/_golden/col_json_str.raw | Bin 88 -> 80 bytes proto/_golden/col_json_str_bytes.hex | 11 +++++------ proto/_golden/col_json_str_bytes.raw | Bin 88 -> 80 bytes proto/_golden/column_of_json_bytes.hex | 11 +++++------ proto/_golden/column_of_json_bytes.raw | Bin 88 -> 80 bytes 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/proto/_golden/col_json_str.hex b/proto/_golden/col_json_str.hex index 2e639c9..ff865f2 100644 --- a/proto/_golden/col_json_str.hex +++ b/proto/_golden/col_json_str.hex @@ -1,6 +1,5 @@ -00000000 01 00 00 00 00 00 00 00 11 7b 22 78 22 3a 20 35 |.........{"x": 5| -00000010 2c 20 22 79 22 3a 20 31 30 7d 1b 7b 22 61 22 3a |, "y": 10}.{"a":| -00000020 20 22 74 65 73 74 22 2c 20 22 62 22 3a 20 22 74 | "test", "b": "t| -00000030 65 73 74 32 22 7d 21 7b 22 61 22 3a 20 22 6f 62 |est2"}!{"a": "ob| -00000040 6a 20 74 65 73 74 22 2c 20 22 62 22 3a 20 7b 22 |j test", "b": {"| -00000050 63 22 3a 20 32 30 7d 7d |c": 20}}| +00000000 11 7b 22 78 22 3a 20 35 2c 20 22 79 22 3a 20 31 |.{"x": 5, "y": 1| +00000010 30 7d 1b 7b 22 61 22 3a 20 22 74 65 73 74 22 2c |0}.{"a": "test",| +00000020 20 22 62 22 3a 20 22 74 65 73 74 32 22 7d 21 7b | "b": "test2"}!{| +00000030 22 61 22 3a 20 22 6f 62 6a 20 74 65 73 74 22 2c |"a": "obj test",| +00000040 20 22 62 22 3a 20 7b 22 63 22 3a 20 32 30 7d 7d | "b": {"c": 20}}| diff --git a/proto/_golden/col_json_str.raw b/proto/_golden/col_json_str.raw index 9bdfa94ea8ea9d9b607fa39fcc471e353652cb89..81a700b8c9d39c68c936439fcb599b738113f940 100644 GIT binary patch delta 5 McmazDn8*