Skip to content

Commit

Permalink
fix json serializer detection
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres committed Feb 6, 2025
1 parent dfd932e commit 8c31f9d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/column/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 8c31f9d

Please sign in to comment.