zeroshade commented on code in PR #36142:
URL: https://github.com/apache/arrow/pull/36142#discussion_r1237276748
##########
go/arrow/csv/reader.go:
##########
@@ -783,6 +814,68 @@ func (r *Reader) parseList(field array.Builder, str
string) {
}
}
+func (r *Reader) parseLargeList(field array.Builder, str string) {
+ if r.isNull(str) {
+ field.AppendNull()
+ return
+ }
+ if !(strings.HasPrefix(str, "{") && strings.HasSuffix(str, "}")) {
+ r.err = errors.New("invalid list format. should start with '{'
and end with '}'")
+ return
+ }
+ str = strings.Trim(str, "{}")
+ largeListBldr := field.(*array.LargeListBuilder)
+ largeListBldr.Append(true)
+ if len(str) == 0 {
+ // we don't want to create the csv reader if we already know the
+ // string is empty
+ return
+ }
+ valueBldr := largeListBldr.ValueBuilder()
+ reader := csv.NewReader(strings.NewReader(str))
+ items, err := reader.Read()
+ if err != nil {
+ r.err = err
+ return
+ }
+ for _, str := range items {
+ r.initFieldConverter(valueBldr)(str)
+ }
+}
+
+func (r *Reader) parseFixedSizeList(field array.Builder, str string, n int) {
+ if r.isNull(str) {
+ field.AppendNull()
+ return
+ }
+ if !(strings.HasPrefix(str, "{") && strings.HasSuffix(str, "}")) {
+ r.err = errors.New("invalid list format. should start with '{'
and end with '}'")
+ return
+ }
+ str = strings.Trim(str, "{}")
+ fixedSizeListBldr := field.(*array.FixedSizeListBuilder)
+ fixedSizeListBldr.Append(true)
+ if len(str) == 0 {
+ // we don't want to create the csv reader if we already know the
+ // string is empty
+ return
+ }
+ valueBldr := fixedSizeListBldr.ValueBuilder()
+ reader := csv.NewReader(strings.NewReader(str))
+ items, err := reader.Read()
+ if err != nil {
+ r.err = err
+ return
+ }
+ if len(items) == n {
+ for _, str := range items {
+ r.initFieldConverter(valueBldr)(str)
+ }
+ } else {
+ r.err = errors.New("invalid fixed size list format. the length
of the items should be equal the length of the fixed size list")
Review Comment:
let's use `fmt.Errorf("%w: fixed size list items should match the fixed size
list length, expected %d, got %d", arrow.ErrInvalid, n, len(items))` to be more
informative in the error.
--
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]