Skip to content

Commit

Permalink
GH-35188: [Go] Use AppendValueFromString for extension types in CSV R…
Browse files Browse the repository at this point in the history
…eader (#35189)

Rather than adding quotes and using `json.NewDecoder` to decode extension types, we should use `AppendValueFromString` which provides the opposite operation to `ValueStr`.

Closes #35188
* Closes: #35188

Authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
  • Loading branch information
hermanschaaf committed Apr 18, 2023
1 parent ccc9d2c commit c3d610d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions go/arrow/csv/reader.go
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/apache/arrow/go/v12/arrow/decimal256"
"github.com/apache/arrow/go/v12/arrow/internal/debug"
"github.com/apache/arrow/go/v12/arrow/memory"
"github.com/goccy/go-json"
)

// Reader wraps encoding/csv.Reader and creates array.Records from a schema.
Expand Down Expand Up @@ -783,8 +782,7 @@ func (r *Reader) parseExtension(field array.Builder, str string) {
field.AppendNull()
return
}
dec := json.NewDecoder(strings.NewReader(`"` + str + `"`))
if err := field.UnmarshalOne(dec); err != nil {
if err := field.AppendValueFromString(str); err != nil {
r.err = err
return
}
Expand Down
13 changes: 13 additions & 0 deletions go/internal/types/extension_types.go
Expand Up @@ -117,6 +117,19 @@ func (b *UUIDBuilder) UnmarshalJSON(data []byte) error {
return b.Unmarshal(dec)
}

func (b *UUIDBuilder) AppendValueFromString(s string) error {
if s == array.NullValueStr {
b.AppendNull()
return nil
}
u, err := uuid.Parse(s)
if err != nil {
return fmt.Errorf("%w: invalid uuid: %v", arrow.ErrInvalid, err)
}
b.Append(u)
return nil
}

// UUIDArray is a simple array which is a FixedSizeBinary(16)
type UUIDArray struct {
array.ExtensionArrayBase
Expand Down

0 comments on commit c3d610d

Please sign in to comment.