Add warning for partial imports (#3608)

This commit is contained in:
Vinai Rachakonda
2022-06-14 19:06:40 -04:00
committed by GitHub
parent b3338f36da
commit 85a3ece7e1
4 changed files with 21 additions and 1 deletions

View File

@@ -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}

View File

@@ -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 <<SQL > 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"

View File

@@ -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

View File

@@ -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