Skip to content

Commit

Permalink
use list like for building
Browse files Browse the repository at this point in the history
  • Loading branch information
candiduslynx committed May 8, 2024
1 parent b4f49b2 commit 1f00588
Showing 1 changed file with 10 additions and 45 deletions.
55 changes: 10 additions & 45 deletions go/arrow/csv/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,13 @@ func (r *Reader) initFieldConverter(bldr array.Builder) func(string) {
return func(str string) {
r.parseDecimal256(bldr, str, dt.Precision, dt.Scale)
}
case *arrow.ListType:
return func(s string) {
r.parseList(bldr, s)
}
case *arrow.LargeListType:
case *arrow.FixedSizeListType:
return func(s string) {
r.parseLargeList(bldr, s)
r.parseFixedSizeList(bldr.(*array.FixedSizeListBuilder), s, int(dt.Len()))
}
case *arrow.FixedSizeListType:
case arrow.ListLikeType:
return func(s string) {
r.parseFixedSizeList(bldr, s, int(dt.Len()))
r.parseListLike(bldr.(array.ListLikeBuilder), s)
}
case *arrow.BinaryType:
return func(s string) {
Expand Down Expand Up @@ -804,36 +800,7 @@ func (r *Reader) parseDecimal256(field array.Builder, str string, prec, scale in
field.(*array.Decimal256Builder).Append(val)
}

func (r *Reader) parseList(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, "{}")
listBldr := field.(*array.ListBuilder)
listBldr.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 := listBldr.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) parseLargeList(field array.Builder, str string) {
func (r *Reader) parseListLike(field array.ListLikeBuilder, str string) {
if r.isNull(str) {
field.AppendNull()
return
Expand All @@ -843,14 +810,13 @@ func (r *Reader) parseLargeList(field array.Builder, str string) {
return
}
str = strings.Trim(str, "{}")
largeListBldr := field.(*array.LargeListBuilder)
largeListBldr.Append(true)
field.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()
valueBldr := field.ValueBuilder()
reader := csv.NewReader(strings.NewReader(str))
items, err := reader.Read()
if err != nil {
Expand All @@ -862,7 +828,7 @@ func (r *Reader) parseLargeList(field array.Builder, str string) {
}
}

func (r *Reader) parseFixedSizeList(field array.Builder, str string, n int) {
func (r *Reader) parseFixedSizeList(field *array.FixedSizeListBuilder, str string, n int) {
if r.isNull(str) {
field.AppendNull()
return
Expand All @@ -872,14 +838,13 @@ func (r *Reader) parseFixedSizeList(field array.Builder, str string, n int) {
return
}
str = strings.Trim(str, "{}")
fixedSizeListBldr := field.(*array.FixedSizeListBuilder)
fixedSizeListBldr.Append(true)
field.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()
valueBldr := field.ValueBuilder()
reader := csv.NewReader(strings.NewReader(str))
items, err := reader.Read()
if err != nil {
Expand Down

0 comments on commit 1f00588

Please sign in to comment.