mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-26 10:37:04 -06:00
290 lines
9.9 KiB
Bash
290 lines
9.9 KiB
Bash
#!/usr/bin/env bats
|
|
load $BATS_TEST_DIRNAME/helper/common.bash
|
|
|
|
setup() {
|
|
setup_common
|
|
}
|
|
|
|
teardown() {
|
|
teardown_common
|
|
}
|
|
|
|
@test "replace table using csv" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE test (
|
|
pk BIGINT NOT NULL COMMENT 'tag:0',
|
|
c1 BIGINT COMMENT 'tag:1',
|
|
c2 BIGINT COMMENT 'tag:2',
|
|
c3 BIGINT COMMENT 'tag:3',
|
|
c4 BIGINT COMMENT 'tag:4',
|
|
c5 BIGINT COMMENT 'tag:5',
|
|
PRIMARY KEY (pk)
|
|
);
|
|
SQL
|
|
run dolt table import -r test `batshelper 1pk5col-ints.csv`
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ "Rows Processed: 2, Additions: 2, Modifications: 0, Had No Effect: 0" ]] || false
|
|
[[ "$output" =~ "Import completed successfully." ]] || false
|
|
}
|
|
|
|
@test "replace table using csv with wrong schema" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE test (
|
|
pk BIGINT NOT NULL COMMENT 'tag:0',
|
|
c1 BIGINT COMMENT 'tag:1',
|
|
c2 BIGINT COMMENT 'tag:2',
|
|
c3 BIGINT COMMENT 'tag:3',
|
|
c4 BIGINT COMMENT 'tag:4',
|
|
c5 BIGINT COMMENT 'tag:5',
|
|
PRIMARY KEY (pk)
|
|
);
|
|
SQL
|
|
run dolt table import -r test `batshelper 2pk5col-ints.csv`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "Error replacing table" ]] || false
|
|
[[ "$output" =~ "cause: Schema from file does not match schema from existing table." ]] || false
|
|
}
|
|
|
|
@test "replace table using psv" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE test (
|
|
pk BIGINT NOT NULL COMMENT 'tag:0',
|
|
c1 BIGINT COMMENT 'tag:1',
|
|
c2 BIGINT COMMENT 'tag:2',
|
|
c3 BIGINT COMMENT 'tag:3',
|
|
c4 BIGINT COMMENT 'tag:4',
|
|
c5 BIGINT COMMENT 'tag:5',
|
|
PRIMARY KEY (pk)
|
|
);
|
|
SQL
|
|
run dolt table import -r test `batshelper 1pk5col-ints.psv`
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ "Rows Processed: 2, Additions: 2, Modifications: 0, Had No Effect: 0" ]] || false
|
|
[[ "$output" =~ "Import completed successfully." ]] || false
|
|
}
|
|
|
|
@test "replace table using psv with wrong schema" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE test (
|
|
pk1 BIGINT NOT NULL COMMENT 'tag:0',
|
|
pk2 BIGINT NOT NULL COMMENT 'tag:1',
|
|
c1 BIGINT COMMENT 'tag:2',
|
|
c2 BIGINT COMMENT 'tag:3',
|
|
c3 BIGINT COMMENT 'tag:4',
|
|
c4 BIGINT COMMENT 'tag:5',
|
|
c5 BIGINT COMMENT 'tag:6',
|
|
PRIMARY KEY (pk1,pk2)
|
|
);
|
|
SQL
|
|
run dolt table import -r test `batshelper 1pk5col-ints.psv`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "Error replacing table" ]] || false
|
|
[[ "$output" =~ "cause: Schema from file does not match schema from existing table." ]] || false
|
|
}
|
|
|
|
@test "replace table using schema with csv" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE test (
|
|
pk BIGINT NOT NULL COMMENT 'tag:0',
|
|
c1 BIGINT COMMENT 'tag:1',
|
|
c2 BIGINT COMMENT 'tag:2',
|
|
c3 BIGINT COMMENT 'tag:3',
|
|
c4 BIGINT COMMENT 'tag:4',
|
|
c5 BIGINT COMMENT 'tag:5',
|
|
PRIMARY KEY (pk)
|
|
);
|
|
SQL
|
|
run dolt table import -r -s `batshelper 1pk5col-ints-schema.json` test `batshelper 1pk5col-ints.csv`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "schema is not supported for update or replace operations" ]] || false
|
|
}
|
|
|
|
@test "replace table using json" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE employees (
|
|
\`id\` LONGTEXT NOT NULL COMMENT 'tag:0',
|
|
\`first name\` LONGTEXT COMMENT 'tag:1',
|
|
\`last name\` LONGTEXT COMMENT 'tag:2',
|
|
\`title\` LONGTEXT COMMENT 'tag:3',
|
|
\`start date\` LONGTEXT COMMENT 'tag:4',
|
|
\`end date\` LONGTEXT COMMENT 'tag:5',
|
|
PRIMARY KEY (id)
|
|
);
|
|
SQL
|
|
run dolt table import -r employees `batshelper employees-tbl.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 using json with wrong schema" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE employees (
|
|
\`idz\` LONGTEXT NOT NULL COMMENT 'tag:0',
|
|
\`first namez\` LONGTEXT COMMENT 'tag:1',
|
|
\`last namez\` LONGTEXT COMMENT 'tag:2',
|
|
\`titlez\` LONGTEXT COMMENT 'tag:3',
|
|
\`start datez\` LONGTEXT COMMENT 'tag:4',
|
|
\`end datez\` LONGTEXT COMMENT 'tag:5',
|
|
PRIMARY KEY (idz)
|
|
);
|
|
SQL
|
|
run dolt table import -r employees `batshelper employees-tbl.json`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "Error replacing table" ]] || false
|
|
[[ "$output" =~ "cause: Schema from file does not match schema from existing table." ]] || false
|
|
}
|
|
|
|
@test "replace table using schema with json" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE employees (
|
|
\`idz\` LONGTEXT NOT NULL COMMENT 'tag:0',
|
|
\`first namez\` LONGTEXT COMMENT 'tag:1',
|
|
\`last namez\` LONGTEXT COMMENT 'tag:2',
|
|
\`titlez\` LONGTEXT COMMENT 'tag:3',
|
|
\`start datez\` LONGTEXT COMMENT 'tag:4',
|
|
\`end datez\` LONGTEXT COMMENT 'tag:5',
|
|
PRIMARY KEY (idz)
|
|
);
|
|
SQL
|
|
run dolt table import -r -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "fatal: schema is not supported for update or replace operations" ]] || false
|
|
}
|
|
|
|
@test "replace table with json when table does not exist" {
|
|
run dolt table import -r employees `batshelper employees-tbl.json`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "The following table could not be found:" ]] || false
|
|
}
|
|
|
|
@test "replace table with existing data using json" {
|
|
run dolt table import -c -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json`
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ "Import completed successfully." ]] || false
|
|
run dolt table import -r employees `batshelper employees-tbl-new.json`
|
|
[ "$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 existing data with different schema" {
|
|
run dolt table import -c -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json`
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ "Import completed successfully." ]] || false
|
|
run dolt table import -r employees `batshelper employees-tbl-schema-wrong.json`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "Error replacing table" ]] || false
|
|
[[ "$output" =~ "cause: Schema from file does not match schema from existing table." ]] || false
|
|
}
|
|
|
|
@test "replace table with bad json" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE employees (
|
|
\`id\` LONGTEXT NOT NULL COMMENT 'tag:0',
|
|
\`first name\` LONGTEXT COMMENT 'tag:1',
|
|
\`last name\` LONGTEXT COMMENT 'tag:2',
|
|
\`title\` LONGTEXT COMMENT 'tag:3',
|
|
\`start date\` LONGTEXT COMMENT 'tag:4',
|
|
\`end date\` LONGTEXT COMMENT 'tag:5',
|
|
PRIMARY KEY (id)
|
|
);
|
|
SQL
|
|
run dolt table import -r employees `batshelper employees-tbl-bad.json`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "An error occurred moving data" ]] || false
|
|
}
|
|
|
|
@test "replace table using xlsx file" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE employees (
|
|
\`id\` LONGTEXT NOT NULL COMMENT 'tag:0',
|
|
\`first\` LONGTEXT COMMENT 'tag:1',
|
|
\`last\` LONGTEXT COMMENT 'tag:2',
|
|
\`title\` LONGTEXT COMMENT 'tag:3',
|
|
\`start date\` LONGTEXT COMMENT 'tag:4',
|
|
\`end date\` LONGTEXT COMMENT 'tag:5',
|
|
PRIMARY KEY (id)
|
|
);
|
|
SQL
|
|
run dolt table import -r employees `batshelper employees.xlsx`
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ "Rows Processed: 3, Additions: 3, Modifications: 0, Had No Effect: 0" ]] || false
|
|
[[ "$output" =~ "Import completed successfully." ]] || false
|
|
}
|
|
|
|
@test "replace table using xlsx file with wrong schema" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE employees (
|
|
\`id\` LONGTEXT NOT NULL COMMENT 'tag:0',
|
|
\`first name\` LONGTEXT COMMENT 'tag:1',
|
|
\`last name\` LONGTEXT COMMENT 'tag:2',
|
|
\`title\` LONGTEXT COMMENT 'tag:3',
|
|
\`start date\` LONGTEXT COMMENT 'tag:4',
|
|
\`end date\` LONGTEXT COMMENT 'tag:5',
|
|
PRIMARY KEY (id)
|
|
);
|
|
SQL
|
|
run dolt table import -r employees `batshelper employees.xlsx`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "Error replacing table" ]] || false
|
|
[[ "$output" =~ "cause: Schema from file does not match schema from existing table." ]] || false
|
|
}
|
|
|
|
@test "replace table with 2 primary keys with a csv with one primary key" {
|
|
run dolt table import -c --pk=pk1,pk2 test `batshelper 2pk5col-ints.csv`
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ "Import completed successfully." ]] || false
|
|
run dolt table import -r test `batshelper 1pk5col-ints.csv`
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" =~ "Error replacing table" ]] || false
|
|
[[ "$output" =~ "cause: Schema from file does not match schema from existing table." ]] || false
|
|
}
|
|
|
|
@test "replace table with 2 primary keys with a csv with 2 primary keys" {
|
|
run dolt table import -c --pk=pk1,pk2 test `batshelper 2pk5col-ints.csv`
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ "Import completed successfully." ]] || false
|
|
run dolt table import -r test `batshelper 2pk5col-ints.csv`
|
|
[ "$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" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE employees (
|
|
\`id\` LONGTEXT NOT NULL COMMENT 'tag:0',
|
|
\`first name\` LONGTEXT COMMENT 'tag:1',
|
|
\`last name\` LONGTEXT COMMENT 'tag:2',
|
|
\`title\` LONGTEXT COMMENT 'tag:3',
|
|
\`start date\` LONGTEXT COMMENT 'tag:4',
|
|
\`end date\` LONGTEXT COMMENT 'tag:5',
|
|
PRIMARY KEY (id)
|
|
);
|
|
SQL
|
|
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" {
|
|
dolt sql <<SQL
|
|
CREATE TABLE employees (
|
|
\`id\` LONGTEXT NOT NULL COMMENT 'tag:0',
|
|
\`first name\` LONGTEXT COMMENT 'tag:1',
|
|
\`last name\` LONGTEXT COMMENT 'tag:2',
|
|
\`title\` LONGTEXT COMMENT 'tag:3',
|
|
\`start date\` LONGTEXT COMMENT 'tag:4',
|
|
\`end date\` LONGTEXT COMMENT 'tag:5',
|
|
PRIMARY KEY (id)
|
|
);
|
|
SQL
|
|
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
|
|
}
|