mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-28 03:08:53 -06:00
{go, bats}: Replace table works with file with schema in different order and added bats tests
This commit is contained in:
4
bats/helper/employees-tbl-schema-unordered.csv
Normal file
4
bats/helper/employees-tbl-schema-unordered.csv
Normal 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"
|
||||
|
28
bats/helper/employees-tbl-schema-unordered.json
Normal file
28
bats/helper/employees-tbl-schema-unordered.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user