emkornfield commented on a change in pull request #11359:
URL: https://github.com/apache/arrow/pull/11359#discussion_r741369397



##########
File path: go/arrow/array/float16_builder.go
##########
@@ -163,3 +168,59 @@ func (b *Float16Builder) newData() (data *Data) {
 
        return
 }
+
+func (b *Float16Builder) unmarshalOne(dec *json.Decoder) error {
+       t, err := dec.Token()
+       if err != nil {
+               return err
+       }
+
+       switch v := t.(type) {
+       case float64:
+               b.Append(float16.New(float32(v)))
+       case string:
+               f, err := strconv.ParseFloat(v, 32)
+               if err != nil {
+                       return err
+               }
+               b.Append(float16.New(float32(f)))
+       case json.Number:
+               f, err := v.Float64()
+               if err != nil {
+                       return err
+               }
+               b.Append(float16.New(float32(f)))
+       case nil:
+               b.AppendNull()
+       default:
+               return &json.UnmarshalTypeError{
+                       Value:  fmt.Sprint(t),
+                       Type:   reflect.TypeOf(float16.Num{}),
+                       Offset: dec.InputOffset(),
+               }
+       }
+       return nil
+}
+
+func (b *Float16Builder) unmarshal(dec *json.Decoder) error {
+       for dec.More() {
+               if err := b.unmarshalOne(dec); err != nil {
+                       return err
+               }
+       }
+       return nil
+}
+
+func (b *Float16Builder) UnmarshalJSON(data []byte) error {
+       dec := json.NewDecoder(bytes.NewReader(data))
+       t, err := dec.Token()
+       if err != nil {
+               return err
+       }
+
+       if delim, ok := t.(json.Delim); !ok || delim != '[' {
+               return fmt.Errorf("binary builder must unpack from json array, 
found %s", delim)

Review comment:
       check for copy and paste but in error messages?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to