@@ -47,6 +47,8 @@ type loadDataIter struct {
4747 setExprs []sql.Expression
4848 userVars []sql.Expression
4949
50+ ignoreNum int64
51+
5052 fieldsTerminatedBy string
5153 fieldsEnclosedBy string
5254 fieldsEnclosedByOpt bool
@@ -56,21 +58,30 @@ type loadDataIter struct {
5658 linesTerminatedBy string
5759}
5860
59- func (l loadDataIter ) Next (ctx * sql.Context ) (returnRow sql.Row , returnErr error ) {
60- var exprs []sql.Expression
61+ var _ sql.RowIter = (* loadDataIter )(nil )
62+ var _ sql.Closer = (* loadDataIter )(nil )
63+
64+ func (l * loadDataIter ) Next (ctx * sql.Context ) (returnRow sql.Row , returnErr error ) {
65+ // skip first ignoreNum lines
6166 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 ()
70+ return nil , err
71+ }
72+ }
73+
6274 // If exprs is nil then this is a skipped line (see test cases). Keep skipping
6375 // until exprs != nil
76+ var exprs []sql.Expression
6477 for exprs == nil {
6578 if keepGoing := l .scanner .Scan (); ! keepGoing {
66- if l .scanner .Err () != nil {
67- return nil , l . scanner . Err ()
79+ if err = l .scanner .Err (); err != nil {
80+ return nil , err
6881 }
6982 return nil , io .EOF
7083 }
71-
72- line := l .scanner .Text ()
73- exprs , err = l .parseFields (ctx , line )
84+ exprs , err = l .parseFields (ctx , l .scanner .Text ())
7485 if err != nil {
7586 return nil , err
7687 }
@@ -101,12 +112,12 @@ func (l loadDataIter) Next(ctx *sql.Context) (returnRow sql.Row, returnErr error
101112 return sql .NewRow (row ... ), nil
102113}
103114
104- func (l loadDataIter ) Close (ctx * sql.Context ) error {
115+ func (l * loadDataIter ) Close (ctx * sql.Context ) error {
105116 return l .reader .Close ()
106117}
107118
108119// parseLinePrefix searches for the delim defined by linesStartingByDelim.
109- func (l loadDataIter ) parseLinePrefix (line string ) string {
120+ func (l * loadDataIter ) parseLinePrefix (line string ) string {
110121 if l .linesStartingBy == "" {
111122 return line
112123 }
@@ -121,7 +132,7 @@ func (l loadDataIter) parseLinePrefix(line string) string {
121132 }
122133}
123134
124- func (l loadDataIter ) parseFields (ctx * sql.Context , line string ) ([]sql.Expression , error ) {
135+ func (l * loadDataIter ) parseFields (ctx * sql.Context , line string ) ([]sql.Expression , error ) {
125136 // Step 1. Start by Searching for prefix if there is one
126137 line = l .parseLinePrefix (line )
127138 if line == "" {
0 commit comments