{go, bats}: Replace table works with file with schema in different order and added bats tests

This commit is contained in:
Taylor Bantle
2019-09-23 11:45:21 -07:00
parent fdd1e68ec0
commit 1c4bb87e3b
5 changed files with 78 additions and 7 deletions

View File

@@ -0,0 +1,4 @@
id, title, start date, end date, first name, last name
0, "ceo", "", "", "tim", "sehn"
1, "founder", "", "", "aaron", "son"
2, "founder", "", "", "brian", "hendriks"
1 id title start date end date first name last name
2 0 ceo tim sehn
3 1 founder aaron son
4 2 founder brian hendriks

View File

@@ -0,0 +1,28 @@
{
"rows": [
{
"id": 0,
"title": "ceo",
"start date": "",
"end date": "",
"first name": "tim",
"last name": "sehn"
},
{
"id": 1,
"title": "founder",
"start date": "",
"end date": "",
"first name": "aaron",
"last name": "son"
},
{
"id": 2,
"title": "founder",
"start date": "",
"end date": "",
"first name": "brian",
"last name": "hendricks"
}
]
}

View File

@@ -155,4 +155,23 @@ teardown() {
[ "$status" -eq 0 ]
[[ "$output" =~ "Rows Processed: 4, Additions: 4, Modifications: 0, Had No Effect: 0" ]] || false
[[ "$output" =~ "Import completed successfully." ]] || false
}
}
@test "replace table with a json with columns in different order" {
run dolt table create -s `batshelper employees-sch.json` employees
[ "$status" -eq 0 ]
run dolt table import -r employees `batshelper employees-tbl-schema-unordered.json`
[ "$status" -eq 0 ]
[[ "$output" =~ "Rows Processed: 3, Additions: 3, Modifications: 0, Had No Effect: 0" ]] || false
[[ "$output" =~ "Import completed successfully." ]] || false
}
@test "replace table with a csv with columns in different order" {
run dolt table create -s `batshelper employees-sch.json` employees
[ "$status" -eq 0 ]
run dolt table import -r employees `batshelper employees-tbl-schema-unordered.csv`
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" =~ "Rows Processed: 3, Additions: 3, Modifications: 0, Had No Effect: 0" ]] || false
[[ "$output" =~ "Import completed successfully." ]] || false
}

View File

@@ -77,4 +77,24 @@ teardown() {
run dolt table import -u employees `batshelper employees-tbl.json`
[ "$status" -eq 1 ]
[[ "$output" =~ "The following table could not be found:" ]] || false
}
}
@test "replace table with a json with columns in different order" {
run dolt table create -s `batshelper employees-sch.json` employees
[ "$status" -eq 0 ]
run dolt table import -u employees `batshelper employees-tbl-schema-unordered.json`
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" =~ "Rows Processed: 3, Additions: 3, Modifications: 0, Had No Effect: 0" ]] || false
[[ "$output" =~ "Import completed successfully." ]] || false
}
@test "replace table with a csv with columns in different order" {
run dolt table create -s `batshelper employees-sch.json` employees
[ "$status" -eq 0 ]
run dolt table import -u employees `batshelper employees-tbl-schema-unordered.csv`
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" =~ "Rows Processed: 3, Additions: 3, Modifications: 0, Had No Effect: 0" ]] || false
[[ "$output" =~ "Import completed successfully." ]] || false
}

View File

@@ -84,8 +84,8 @@ func SchemasAreEqual(sch1, sch2 Schema) (bool, error) {
return areEqual, nil
}
// VerifyInSchema tests that the incoming schema matches the schema from the original table.
// The test for column equality is more flexible than SchemasAreEqual.
// VerifyInSchema tests that the incoming schema matches the schema from the original table
// based on the presence of the column name in the original schema.
func VerifyInSchema(inSch, outSch Schema) (bool, error) {
inSchCols := inSch.GetAllCols()
outSchCols := outSch.GetAllCols()
@@ -95,10 +95,10 @@ func VerifyInSchema(inSch, outSch Schema) (bool, error) {
}
match := true
err := outSchCols.Iter(func(tag uint64, outCol Column) (stop bool, err error) {
inCol, ok := inSchCols.GetByTag(tag)
err := inSchCols.Iter(func(tag uint64, inCol Column) (stop bool, err error) {
_, isValid := outSchCols.GetByNameCaseInsensitive(inCol.Name)
if !ok || inCol.Name != outCol.Name || inCol.Tag != outCol.Tag {
if !isValid {
match = false
return true, nil
}