@@ -16,8 +16,7 @@ package rowexec
1616
1717import (
1818 "bufio"
19- "bytes"
20- "fmt"
19+ "fmt"
2120 "io"
2221 "strings"
2322 "sync"
@@ -39,10 +38,8 @@ import (
3938)
4039
4140type loadDataIter struct {
42- scanner * bufio.Reader
41+ scanner * bufio.Scanner
4342 reader io.ReadCloser
44- buffer bytes.Buffer
45- hitEOF bool
4643
4744 destSch sql.Schema
4845 colCount int
@@ -64,38 +61,12 @@ type loadDataIter struct {
6461var _ sql.RowIter = (* loadDataIter )(nil )
6562var _ sql.Closer = (* loadDataIter )(nil )
6663
67- // readLine reads a line from the scanner. It does not include the delimiter.
68- func (l * loadDataIter ) readLine () ([]byte , error ) {
69- // return EOF on the call after EOF
70- if l .hitEOF {
71- return nil , io .EOF
72- }
73- delim := []byte (l .linesTerminatedBy )
74- delimDelim := delim [len (delim )- 1 ]
75- l .buffer .Reset ()
76- var buf []byte
77- for {
78- chunk , err := l .scanner .ReadBytes (delimDelim )
79- if err != nil && err != io .EOF {
80- return nil , err
81- }
82- l .buffer .Write (chunk )
83- buf = l .buffer .Bytes ()
84- if bytes .HasSuffix (buf , delim ) {
85- return buf [:len (buf )- len (delim )], nil
86- }
87- if err == io .EOF {
88- l .hitEOF = true
89- return buf , nil
90- }
91- }
92- }
93-
9464func (l * loadDataIter ) Next (ctx * sql.Context ) (returnRow sql.Row , returnErr error ) {
9565 // skip first ignoreNum lines
96- for ; l .ignoreNum > 0 ; l .ignoreNum -- {
97- _ , err := l .readLine ()
98- if err != nil {
66+ var err error
67+ for ; l .ignoreNum > 0 && l .scanner .Scan (); l .ignoreNum -- {
68+ if err = l .scanner .Err (); err != nil {
69+ l .reader .Close ()
9970 return nil , err
10071 }
10172 }
@@ -104,19 +75,20 @@ func (l *loadDataIter) Next(ctx *sql.Context) (returnRow sql.Row, returnErr erro
10475 // until exprs != nil
10576 var exprs []sql.Expression
10677 for exprs == nil {
107- line , err := l .readLine ()
108- if err != nil {
109- return nil , err
78+ if keepGoing := l .scanner .Scan (); ! keepGoing {
79+ if err = l .scanner .Err (); err != nil {
80+ return nil , err
81+ }
82+ return nil , io .EOF
11083 }
111- exprs , err = l .parseFields (ctx , string ( line ))
84+ exprs , err = l .parseFields (ctx , l . scanner . Text ( ))
11285 if err != nil {
11386 return nil , err
11487 }
11588 }
11689
11790 row := make (sql.Row , len (exprs ))
11891 var secondPass []int
119- var err error
12092 for i , expr := range exprs {
12193 if expr != nil {
12294 // Non-literal default values may reference other columns, so we need to evaluate them in a second pass.
0 commit comments