diff --git a/go/cmd/dolt/commands/tblcmds/import.go b/go/cmd/dolt/commands/tblcmds/import.go index e342962da0..42ae2ab864 100644 --- a/go/cmd/dolt/commands/tblcmds/import.go +++ b/go/cmd/dolt/commands/tblcmds/import.go @@ -500,6 +500,12 @@ func newImportSqlEngineMover(ctx context.Context, dEnv *env.DoltEnv, rdSchema sc return nil, &mvdata.DataMoverCreationError{ErrType: mvdata.SchemaErr, Cause: err} } + // Leave a warning if the import operation is operating on fewer columns than the relevant table's schema. + // This can certainly be intentional, but it is often due to typos in the header of a csv file. + if rowOperationSchema.GetAllCols().Size() < tableSchema.GetAllCols().Size() { + cli.PrintErrln(color.YellowString("Warning: There are fewer columns in the import file's schema than the table's schema.\nIf unintentional, check for any typos in the import file's header.")) + } + mv, err := mvdata.NewSqlEngineTableWriter(ctx, dEnv, tableSchema, rowOperationSchema, moveOps, importStatsCB) if err != nil { return nil, &mvdata.DataMoverCreationError{ErrType: mvdata.CreateWriterErr, Cause: err} diff --git a/integration-tests/bats/import-create-tables.bats b/integration-tests/bats/import-create-tables.bats index 3208307eb9..fcd8b25c40 100755 --- a/integration-tests/bats/import-create-tables.bats +++ b/integration-tests/bats/import-create-tables.bats @@ -112,6 +112,9 @@ teardown() { run dolt table import -c --pk=pk test people.csv [ "$status" -eq 0 ] [[ "$output" =~ "Import completed successfully." ]] || false + # Sanity Check + ! [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false + run dolt sql -q "select * from test" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 8 ] @@ -664,7 +667,7 @@ DELIM [ "${lines[1]}" = "0,1,2" ] } -@test "import-create-tables: csv files has less columns filled with default value" { +@test "import-create-tables: csv files has fewer columns filled with default value" { cat < schema.sql CREATE TABLE subset ( pk INT NOT NULL, @@ -680,6 +683,7 @@ DELIM run dolt table import -s schema.sql -c subset data.csv [ "$status" -eq 0 ] + [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false # schema argument subsets the data and adds empty column run dolt sql -r csv -q "select * from subset ORDER BY pk" diff --git a/integration-tests/bats/import-replace-tables.bats b/integration-tests/bats/import-replace-tables.bats index d3a2dcadec..86ba6bf1ee 100644 --- a/integration-tests/bats/import-replace-tables.bats +++ b/integration-tests/bats/import-replace-tables.bats @@ -336,6 +336,7 @@ DELIM run dolt table import -r test 1pk5col-ints-updt.csv [ "$status" -eq 0 ] + [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false [[ "$output" =~ "Rows Processed: 1, Additions: 1, Modifications: 0, Had No Effect: 0" ]] || false [[ "$output" =~ "Import completed successfully." ]] || false @@ -362,6 +363,7 @@ DELIM dolt sql -q "insert into subset values (1000, 100, 1000, 10000)" run dolt table import -r subset data.csv + ! [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false [ "$status" -eq 0 ] # schema argument subsets the data and adds empty column diff --git a/integration-tests/bats/import-update-tables.bats b/integration-tests/bats/import-update-tables.bats index 5d3a824d86..9b8956d1bc 100644 --- a/integration-tests/bats/import-update-tables.bats +++ b/integration-tests/bats/import-update-tables.bats @@ -118,6 +118,8 @@ teardown() { [ "$status" -eq 0 ] [[ "$output" =~ "Rows Processed: 2, Additions: 2, Modifications: 0, Had No Effect: 0" ]] || false [[ "$output" =~ "Import completed successfully." ]] || false + # Sanity check + ! [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false # Validate that a successful import with no bad rows does not print the following ! [[ "$output" =~ "The following rows were skipped:" ]] || false @@ -553,6 +555,7 @@ DELIM run dolt table import -u test 1pk5col-ints-updt.csv [ "$status" -eq 0 ] + [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false [[ "$output" =~ "Rows Processed: 1, Additions: 1, Modifications: 0, Had No Effect: 0" ]] || false [[ "$output" =~ "Import completed successfully." ]] || false @@ -573,6 +576,7 @@ DELIM run dolt table import -u test 1pk5col-ints-updt.csv [ "$status" -eq 0 ] + [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false [[ "$output" =~ "Rows Processed: 1, Additions: 1, Modifications: 0, Had No Effect: 0" ]] || false [[ "$output" =~ "Import completed successfully." ]] || false @@ -595,6 +599,7 @@ DELIM [ "$status" -eq 0 ] [[ "$output" =~ "Rows Processed: 1, Additions: 1, Modifications: 0, Had No Effect: 0" ]] || false [[ "$output" =~ "Import completed successfully." ]] || false + ! [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false run dolt sql -r csv -q "select * from test" [ "${lines[1]}" = "0,1,2,3,4,6" ] @@ -615,6 +620,7 @@ DELIM [ "$status" -eq 0 ] [[ "$output" =~ "Rows Processed: 1, Additions: 1, Modifications: 0, Had No Effect: 0" ]] || false [[ "$output" =~ "Import completed successfully." ]] || false + ! [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false run dolt sql -r csv -q "select * from test" [ "${lines[1]}" = "0,1,2,3,4,6" ] @@ -635,6 +641,7 @@ DELIM run dolt table import -u test 1pk5col-ints-updt.csv [ "$status" -eq 0 ] + [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false [[ "$output" =~ "Rows Processed: 1, Additions: 0, Modifications: 1, Had No Effect: 0" ]] || false [[ "$output" =~ "Import completed successfully." ]] || false @@ -674,6 +681,7 @@ DELIM run dolt table import -u keyless data.csv [ "$status" -eq 0 ] + [[ "$output" =~ "Warning: There are fewer columns in the import file's schema than the table's schema" ]] || false [[ "$output" =~ "Rows Processed: 1, Additions: 1, Modifications: 0, Had No Effect: 0" ]] || false [[ "$output" =~ "Import completed successfully." ]] || false