Skip to content

Commit

Permalink
Merge pull request #7463 from dolthub/james/select-into
Browse files Browse the repository at this point in the history
`SELECT ... INTO OUTFILE ...` tests
  • Loading branch information
Hydrocharged authored Feb 9, 2024
2 parents c3a8ac2 + 476c04e commit d391bcf
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 8 deletions.
4 changes: 2 additions & 2 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/dolthub/fslock v0.0.3
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
github.com/dolthub/vitess v0.0.0-20240207121055-c057d2347007
github.com/dolthub/vitess v0.0.0-20240207220624-0c2d2128fb7b
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.13.0
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568
Expand Down Expand Up @@ -57,7 +57,7 @@ require (
github.com/cespare/xxhash v1.1.0
github.com/creasty/defaults v1.6.0
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-mysql-server v0.17.1-0.20240208021948-8c7762d0d825
github.com/dolthub/go-mysql-server v0.17.1-0.20240209083513-50fb2b2ef1a7
github.com/dolthub/swiss v0.1.0
github.com/goccy/go-json v0.10.2
github.com/google/go-github/v57 v57.0.0
Expand Down
8 changes: 4 additions & 4 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y=
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
github.com/dolthub/go-mysql-server v0.17.1-0.20240208021948-8c7762d0d825 h1:uVLs1DxzXXbi7sS2f48EoZ/CRoUmYsHlKU1C5QuIvM4=
github.com/dolthub/go-mysql-server v0.17.1-0.20240208021948-8c7762d0d825/go.mod h1:ANK0a6tyjrZ2cOzDJT3nFsDp80xksI4UfeijFlvnjwE=
github.com/dolthub/go-mysql-server v0.17.1-0.20240209083513-50fb2b2ef1a7 h1:YyhYrsvSYQStE/lRlaVCHNzVq3i4NwFBsMeIh9kyvs0=
github.com/dolthub/go-mysql-server v0.17.1-0.20240209083513-50fb2b2ef1a7/go.mod h1:mTI9ftDXUsfPREJW+U6OINfw+wzU7fyH3HGc2caW2rg=
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488 h1:0HHu0GWJH0N6a6keStrHhUAK5/o9LVfkh44pvsV4514=
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488/go.mod h1:ehexgi1mPxRTk0Mok/pADALuHbvATulTh6gzr7NzZto=
github.com/dolthub/jsonpath v0.0.2-0.20240201003050-392940944c15 h1:sfTETOpsrNJPDn2KydiCtDgVu6Xopq8k3JP8PjFT22s=
Expand All @@ -195,8 +195,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9X
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
github.com/dolthub/vitess v0.0.0-20240207121055-c057d2347007 h1:MvFoe0FnHhxQLyp4Ldw0HRj1yu83YErbtbr7XxhaIFk=
github.com/dolthub/vitess v0.0.0-20240207121055-c057d2347007/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dolthub/vitess v0.0.0-20240207220624-0c2d2128fb7b h1:7Sxjtwd7Cm2ilQDFvyXPfCkNkJMK//2GBGb3aM9ht7k=
github.com/dolthub/vitess v0.0.0-20240207220624-0c2d2128fb7b/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
Expand Down
6 changes: 6 additions & 0 deletions go/libraries/doltcore/sqle/enginetest/dolt_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,12 @@ func TestLoadDataErrors(t *testing.T) {
enginetest.TestLoadDataErrors(t, h)
}

func TestSelectIntoFile(t *testing.T) {
h := newDoltHarness(t)
defer h.Close()
enginetest.TestSelectIntoFile(t, h)
}

func TestJsonScripts(t *testing.T) {
h := newDoltHarness(t)
defer h.Close()
Expand Down
103 changes: 103 additions & 0 deletions integration-tests/bats/sql-export.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash

setup() {
setup_common
dolt sql <<SQL
create table t (i int, j int, k int);
insert into t (i, j, k) values (1, 2, 3), (4, 5, 6), (7, 8, 9);
create table emptytbl (i int, j int, k int);
SQL
}

teardown() {
assert_feature_version
teardown_common
}

@test "sql-export: basic outfile" {
run dolt sql -q "select * from t order by i, j, k into outfile './outfile.out';"
[ "$status" -eq 0 ]
[ -f outfile.out ]

run cat outfile.out
[ "$status" -eq 0 ]
[[ "${#lines[@]}" = "3" ]] || false
[[ "${lines[0]}" =~ "1 2 3" ]] || false
[[ "${lines[1]}" =~ "4 5 6" ]] || false
[[ "${lines[2]}" =~ "7 8 9" ]] || false
}

@test "sql-export: basic dumpfile" {
run dolt sql -q "select * from t order by i, j, k limit 1 into dumpfile './dumpfile.out';"
[ "$status" -eq 0 ]
[ -f dumpfile.out ]

run cat dumpfile.out
[ "$status" -eq 0 ]
[[ "${#lines[@]}" = "1" ]] || false
[[ "${lines[0]}" =~ "123" ]] || false
}

@test "sql-export: test abs path outfile" {
CURR_DIR=$(pwd)
run dolt sql -q "select * from t order by i, j, k into outfile '$CURR_DIR/outfile.out';"
[ "$status" -eq 0 ]
[ -f outfile.out ]

run cat outfile.out
[ "$status" -eq 0 ]
[[ "${#lines[@]}" = "3" ]] || false
[[ "${lines[0]}" =~ "1 2 3" ]] || false
[[ "${lines[1]}" =~ "4 5 6" ]] || false
[[ "${lines[2]}" =~ "7 8 9" ]] || false
}

@test "sql-export: test abs path dumpfile" {
CURR_DIR=$(pwd)
run dolt sql -q "select * from t order by i, j, k limit 1 into dumpfile '$CURR_DIR/dumpfile.out';"
[ "$status" -eq 0 ]
[ -f dumpfile.out ]

run cat dumpfile.out
[ "$status" -eq 0 ]
[[ "${#lines[@]}" = "1" ]] || false
[[ "${lines[0]}" =~ "123" ]] || false
}

@test "sql-export: empty outfile" {
run dolt sql -q "select * from emptytbl into outfile './outfile.out';"
[ "$status" -eq 0 ]
[ -f outfile.out ]

run cat outfile.out
[ "$status" -eq 0 ]
[[ "${#lines[@]}" = "0" ]] || false
}

@test "sql-export: empty dumpfile" {
run dolt sql -q "select * from emptytbl into dumpfile './dumpfile.out';"
[ "$status" -eq 0 ]
[ -f dumpfile.out ]

run cat dumpfile.out
[ "$status" -eq 0 ]
[[ "${#lines[@]}" = "0" ]] || false
}

@test "sql-export: fails with existing files" {
touch exists.out
run dolt sql -q "select * from t order by i, j, k into outfile './exists.out';"
[ "$status" -eq 1 ]
[[ "$output" =~ "already exists" ]] || false

run dolt sql -q "select * from t order by i, j, k limit 1 into dumpfile './exists.out';"
[ "$status" -eq 1 ]
[[ "$output" =~ "already exists" ]] || false
}

@test "sql-export: dumpfile fails with too many rows" {
run dolt sql -q "select * from t order by i, j, k limit 3 into dumpfile './dumpfile.out';"
[ "$status" -eq 1 ]
[[ "$output" =~ "Result consisted of more than one row" ]] || false
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ tests:
rows: [["NULL"]]
- exec: "create table loaded (contents text)"
- exec: "load data infile \"config.yaml\" into table loaded"
error_match: "LOAD DATA is unable to open file: open /dev/null/config.yaml"
error_match: "LOAD DATA is unable to open file: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement"
- exec: "load data infile \"/config.yaml\" into table loaded"
error_match: "LOAD DATA is unable to open file: open /dev/null/config.yaml"
error_match: "LOAD DATA is unable to open file: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement"
- name: secure_file_priv set to empty strings allows loading files
repos:
- name: repo1
Expand Down

0 comments on commit d391bcf

Please sign in to comment.