From 8c31f9d216e51556ece03486a2b0536714fdc5ef Mon Sep 17 00:00:00 2001 From: Spencer Torres Date: Thu, 6 Feb 2025 02:21:54 -0500 Subject: [PATCH] fix json serializer detection --- lib/column/json.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/column/json.go b/lib/column/json.go index ebc62ca906..07628397aa 100644 --- a/lib/column/json.go +++ b/lib/column/json.go @@ -323,6 +323,9 @@ func (c *JSON) Append(v any) (nulls []uint8, err error) { case []*chcol.JSON: c.serializationVersion = JSONObjectSerializationVersion return c.appendObject(v) + case []chcol.JSONSerializer: + c.serializationVersion = JSONObjectSerializationVersion + return c.appendObject(v) } var err error @@ -357,6 +360,15 @@ func (c *JSON) appendObject(v any) (nulls []uint8, err error) { } } + return nil, nil + case []chcol.JSONSerializer: + for i, obj := range vv { + err := c.AppendRow(obj) + if err != nil { + return nil, fmt.Errorf("failed to AppendRow at index %d: %w", i, err) + } + } + return nil, nil } @@ -403,6 +415,9 @@ func (c *JSON) AppendRow(v any) error { case *chcol.JSON: c.serializationVersion = JSONObjectSerializationVersion return c.appendRowObject(v) + case chcol.JSONSerializer: + c.serializationVersion = JSONObjectSerializationVersion + return c.appendRowObject(v) } var err error @@ -414,7 +429,7 @@ func (c *JSON) AppendRow(v any) error { return nil } - return fmt.Errorf("unsupported type \"%s\" for JSON column, must use string, []byte, struct, map, or *%s: %w", reflect.TypeOf(v).String(), scanTypeJSON.String(), err) + return fmt.Errorf("unsupported type \"%s\" for JSON column, must use string, []byte, *struct, map, or *clickhouse.JSON: %w", reflect.TypeOf(v).String(), err) } }