Skip to content

Commit

Permalink
Merge #40345
Browse files Browse the repository at this point in the history
40345: importccl: fix mysqqoutfile import bug r=spaskob a=spaskob

When importing from csv if the number of fields is less than the columns
in the schema the server will panic. Added a check for this case.

Tested: Note that the test currently skipped. I added a test case and ran tests successfully locally.

Touches 39820.

Release note: None

Co-authored-by: Spas Bojanov <spas@cockroachlabs.com>
  • Loading branch information
craig[bot] and Spas Bojanov committed Sep 1, 2019
2 parents bc3342e + bb576d9 commit d51fa78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 8 additions & 1 deletion pkg/ccl/importccl/import_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,19 @@ d

// MySQL OUTFILE
{
name: "unexpected number of columns",
name: "too many imported columns",
create: `i int8`,
typ: "MYSQLOUTFILE",
data: "1\t2",
err: "row 1: too many columns, expected 1",
},
{
name: "unexpected number of columns",
create: `a string, b string`,
typ: "MYSQLOUTFILE",
data: "1,2",
err: "row 1: unexpected number of columns, expected 2 got 1",
},
{
name: "unmatched field enclosure",
create: `i int8`,
Expand Down
7 changes: 4 additions & 3 deletions pkg/ccl/importccl/read_import_mysqlout.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (d *mysqloutfileReader) readFile(
return nil
}
addRow := func() error {
if len(row) != len(d.conv.VisibleCols) {
return makeRowErr(inputName, count, pgcode.Syntax,
"unexpected number of columns, expected %d got %d: %#v", len(d.conv.VisibleCols), len(row), row)
}
copy(d.conv.Datums, row)
if err := d.conv.Row(ctx, inputIdx, count); err != nil {
return wrapRowErr(err, inputName, count, pgcode.Uncategorized, "")
Expand Down Expand Up @@ -148,9 +152,6 @@ func (d *mysqloutfileReader) readFile(
return err
}
}
}

if finished {
break
}

Expand Down

0 comments on commit d51fa78

Please sign in to comment.