zeroshade commented on a change in pull request #11359: URL: https://github.com/apache/arrow/pull/11359#discussion_r743092700
########## File path: go/arrow/array/decimal128.go ########## @@ -229,6 +253,67 @@ func (b *Decimal128Builder) newData() (data *Data) { return } +func (b *Decimal128Builder) unmarshalOne(dec *json.Decoder) error { + t, err := dec.Token() + if err != nil { + return err + } + + var out *big.Float + + switch v := t.(type) { + case float64: + out = big.NewFloat(v) + case string: + out, _, err = big.ParseFloat(v, 10, 0, big.ToNearestAway) Review comment: comments added ########## 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))) Review comment: comment added to document the truncation ########## File path: go/arrow/array/interval.go ########## @@ -86,6 +88,29 @@ func (a *MonthInterval) setData(data *Data) { } } +func (a *MonthInterval) getOneForMarshal(i int) interface{} { + if a.IsValid(i) { + return a.values[i] + } + return nil +} + +func (a *MonthInterval) MarshalJSON() ([]byte, error) { + if a.NullN() == 0 { + return json.Marshal(a.values) + } + vals := make([]interface{}, a.Len()) + for i := 0; i < a.Len(); i++ { + if a.IsValid(i) { + vals[i] = a.values[i] Review comment: done ########## File path: go/arrow/array/numeric.gen.go ########## @@ -80,6 +82,27 @@ func (a *Int64) setData(data *Data) { } } +func (a *Int64) getOneForMarshal(i int) interface{} { + if a.IsNull(i) { + return nil + } + + return float64(a.values[i]) // prevent uint8 from being seen as binary data Review comment: fixed ########## File path: go/arrow/array/numeric.gen.go ########## @@ -1085,6 +1377,22 @@ func (a *Duration) setData(data *Data) { } } +func (a *Duration) getOneForMarshal(i int) interface{} { + if a.IsNull(i) { + return nil + } + return fmt.Sprint(time.Duration(a.values[i]) * a.DataType().(*arrow.DurationType).Unit.Multiplier()) Review comment: fixed ########## File path: go/arrow/array/util.go ########## @@ -16,9 +16,178 @@ package array +import ( + "errors" + "fmt" + "io" + + "github.com/apache/arrow/go/arrow" + "github.com/apache/arrow/go/arrow/memory" + "github.com/goccy/go-json" +) + func min(a, b int) int { if a < b { return a } return b } + +type fromJSONCfg struct { + multiDocument bool + startOffset int64 +} + +type FromJSONOption func(*fromJSONCfg) + +func WithMultipleDocs() FromJSONOption { + return func(c *fromJSONCfg) { + c.multiDocument = true + } +} + +// WithStartOffset attempts to start decoding from the reader at the offset +// passed in. If using this option the reader must fulfill the io.ReadSeeker +// interface, or else an error will be returned. +// +// It will call Seek(off, io.SeekStart) on the reader +func WithStartOffset(off int64) FromJSONOption { + return func(c *fromJSONCfg) { + c.startOffset = off + } +} + +// FromJSON creates an array.Interface from a corresponding JSON stream and defined data type. If the types in the +// json do not match the type provided, it will return errors. This is *not* the integration test format +// and should not be used as such. This intended to be used by consumers more similarly to the current exposing of +// the csv reader/writer. It also returns the input offset in the reader where it finished decoding since buffering +// by the decoder could leave the reader's cursor past where the parsing finished if attempting to parse multiple json +// arrays from one stream. +// +// All the Array types implement json.Marshaller and thus can be written to json +// using the json.Marshal function +// +// The JSON provided must be formatted in one of two ways: +// Default: the top level of the json must be a list which matches the type specified exactly +// Example: `[1, 2, 3, 4, 5]` for any integer type or `[[...], null, [], .....]` for a List type +// Struct arrays are represented a list of objects: `[{"foo": 1, "bar": "moo"}, {"foo": 5, "bar": "baz"}]` Review comment: added documentation for those types -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org