Skip to content

Commit

Permalink
lightning: not set pos to end if fail to ReadUntil (pingcap#40232)
Browse files Browse the repository at this point in the history
* fix: not set pos to end

* add it

* fix: return to prevPos

* fix: return err

* fix

* fix

* fix it

* fix

* fix: not exit when err

Co-authored-by: Zak Zhao <57036248+joccau@users.noreply.github.com>
  • Loading branch information
2 people authored and lance6716 committed Jun 1, 2023
1 parent 3c46ac7 commit fb3cf4e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion br/pkg/lightning/mydump/csv_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,18 @@ outside:

func (parser *CSVParser) readQuotedField() error {
for {
prevPos := parser.pos
content, terminator, err := parser.readUntil(&parser.quoteByteSet)
err = parser.replaceEOF(err, errUnterminatedQuotedField)
if err != nil {
if errors.Cause(err) == io.EOF {
// return the position of quote to the caller.
// because we return an error here, the parser won't
// use the `pos` again, so it's safe to modify it here.
parser.pos = prevPos - 1
// set buf to parser.buf in order to print err log
parser.buf = content
err = parser.replaceEOF(err, errUnterminatedQuotedField)
}
return err
}
parser.recordBuffer = append(parser.recordBuffer, content...)
Expand Down
1 change: 1 addition & 0 deletions br/tests/lightning_csv/errData/db-schema-create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create database if not exists db;
1 change: 1 addition & 0 deletions br/tests/lightning_csv/errData/db.test-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create table test(a int primary key, b int, c int, d int);
3 changes: 3 additions & 0 deletions br/tests/lightning_csv/errData/db.test.1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1,2,3,4
2,10,4,5
1111,",7,8
8 changes: 8 additions & 0 deletions br/tests/lightning_csv/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ for BACKEND in tidb local; do
check_not_contains 'id:'

done

set +e
run_lightning --backend local -d "tests/$TEST_NAME/errData" --log-file "$TEST_DIR/lightning-err.log" 2>/dev/null
set -e
# err content presented
grep ",7,8" "$TEST_DIR/lightning-err.log"
# pos should not set to end
grep "[\"syntax error\"] [pos=22]" "$TEST_DIR/lightning-err.log"

0 comments on commit fb3cf4e

Please sign in to comment.