Skip to content

Commit aa2c22f

Browse files
author
James Cor
committed
return ok result for select into
1 parent 6ffe4b8 commit aa2c22f

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

enginetest/enginetests.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,15 +1017,17 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
10171017
})
10181018

10191019
tests := []struct {
1020-
file string
1021-
query string
1022-
exp string
1023-
err *errors.Kind
1024-
skip bool
1020+
file string
1021+
query string
1022+
exp string
1023+
expRows []sql.Row
1024+
err *errors.Kind
1025+
skip bool
10251026
}{
10261027
{
10271028
file: "outfile.txt",
10281029
query: "select * from mytable into outfile 'outfile.txt';",
1030+
expRows: []sql.Row{{types.NewOkResult(3)}},
10291031
exp: "" +
10301032
"1\tfirst row\n" +
10311033
"2\tsecond row\n" +
@@ -1034,11 +1036,13 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
10341036
{
10351037
file: "dumpfile.txt",
10361038
query: "select * from mytable limit 1 into dumpfile 'dumpfile.txt';",
1039+
expRows: []sql.Row{{types.NewOkResult(1)}},
10371040
exp: "1first row",
10381041
},
10391042
{
10401043
file: "outfile.txt",
10411044
query: "select * from mytable into outfile 'outfile.txt' fields terminated by ',';",
1045+
expRows: []sql.Row{{types.NewOkResult(3)}},
10421046
exp: "" +
10431047
"1,first row\n" +
10441048
"2,second row\n" +
@@ -1047,6 +1051,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
10471051
{
10481052
file: "outfile.txt",
10491053
query: "select * from mytable into outfile 'outfile.txt' fields terminated by '$$';",
1054+
expRows: []sql.Row{{types.NewOkResult(3)}},
10501055
exp: "" +
10511056
"1$$first row\n" +
10521057
"2$$second row\n" +
@@ -1055,6 +1060,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
10551060
{
10561061
file: "outfile.txt",
10571062
query: "select * from mytable into outfile 'outfile.txt' fields terminated by ',' optionally enclosed by '\"';",
1063+
expRows: []sql.Row{{types.NewOkResult(3)}},
10581064
exp: "" +
10591065
"1,\"first row\"\n" +
10601066
"2,\"second row\"\n" +
@@ -1073,6 +1079,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
10731079
{
10741080
file: "outfile.txt",
10751081
query: "select * from mytable into outfile 'outfile.txt' fields terminated by ',' enclosed by '\"';",
1082+
expRows: []sql.Row{{types.NewOkResult(3)}},
10761083
exp: "" +
10771084
"\"1\",\"first row\"\n" +
10781085
"\"2\",\"second row\"\n" +
@@ -1081,6 +1088,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
10811088
{
10821089
file: "outfile.txt",
10831090
query: "select * from mytable into outfile 'outfile.txt' fields terminated by ',' lines terminated by ';';",
1091+
expRows: []sql.Row{{types.NewOkResult(3)}},
10841092
exp: "" +
10851093
"1,first row;" +
10861094
"2,second row;" +
@@ -1089,6 +1097,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
10891097
{
10901098
file: "outfile.txt",
10911099
query: "select * from mytable into outfile 'outfile.txt' fields terminated by ',' lines terminated by 'r';",
1100+
expRows: []sql.Row{{types.NewOkResult(3)}},
10921101
exp: "" +
10931102
"1,fi\\rst \\rowr" +
10941103
"2,second \\rowr" +
@@ -1097,6 +1106,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
10971106
{
10981107
file: "outfile.txt",
10991108
query: "select * from mytable into outfile 'outfile.txt' fields terminated by ',' lines starting by 'r';",
1109+
expRows: []sql.Row{{types.NewOkResult(3)}},
11001110
exp: "" +
11011111
"r1,first row\n" +
11021112
"r2,second row\n" +
@@ -1105,6 +1115,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
11051115
{
11061116
file: "outfile.txt",
11071117
query: "select * from mytable into outfile 'outfile.txt' fields terminated by '';",
1118+
expRows: []sql.Row{{types.NewOkResult(3)}},
11081119
exp: "" +
11091120
"1\tfirst row\n" +
11101121
"2\tsecond row\n" +
@@ -1113,6 +1124,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
11131124
{
11141125
file: "outfile.txt",
11151126
query: "select * from mytable into outfile 'outfile.txt' fields terminated by ',' lines terminated by '';",
1127+
expRows: []sql.Row{{types.NewOkResult(3)}},
11161128
exp: "" +
11171129
"1,first row" +
11181130
"2,second row" +
@@ -1121,6 +1133,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
11211133
{
11221134
file: "outfile.txt",
11231135
query: "select * from niltable into outfile 'outfile.txt';",
1136+
expRows: []sql.Row{{types.NewOkResult(6)}},
11241137
exp: "1\t\\N\t\\N\t\\N\n" +
11251138
"2\t2\t1\t\\N\n" +
11261139
"3\t\\N\t0\t\\N\n" +
@@ -1131,6 +1144,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
11311144
{
11321145
file: "outfile.txt",
11331146
query: "select * from niltable into outfile 'outfile.txt' fields terminated by ',' enclosed by '\"';",
1147+
expRows: []sql.Row{{types.NewOkResult(6)}},
11341148
exp: "\"1\",\\N,\\N,\\N\n" +
11351149
"\"2\",\"2\",\"1\",\\N\n" +
11361150
"\"3\",\\N,\"0\",\\N\n" +
@@ -1141,6 +1155,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
11411155
{
11421156
file: "outfile.txt",
11431157
query: "select * from niltable into outfile 'outfile.txt' fields terminated by ',' escaped by '$';",
1158+
expRows: []sql.Row{{types.NewOkResult(6)}},
11441159
exp: "1,$N,$N,$N\n" +
11451160
"2,2,1,$N\n" +
11461161
"3,$N,0,$N\n" +
@@ -1151,6 +1166,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
11511166
{
11521167
file: "outfile.txt",
11531168
query: "select * from niltable into outfile 'outfile.txt' fields terminated by ',' escaped by '';",
1169+
expRows: []sql.Row{{types.NewOkResult(6)}},
11541170
exp: "1,NULL,NULL,NULL\n" +
11551171
"2,2,1,NULL\n" +
11561172
"3,NULL,0,NULL\n" +
@@ -1161,6 +1177,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
11611177
{
11621178
file: "./subdir/outfile.txt",
11631179
query: "select * from mytable into outfile './subdir/outfile.txt';",
1180+
expRows: []sql.Row{{types.NewOkResult(3)}},
11641181
exp: "" +
11651182
"1\tfirst row\n" +
11661183
"2\tsecond row\n" +
@@ -1198,7 +1215,7 @@ func TestSelectIntoFile(t *testing.T, harness Harness) {
11981215
}
11991216
// in case there are any residual files from previous runs
12001217
os.Remove(tt.file)
1201-
TestQueryWithContext(t, ctx, e, harness, tt.query, nil, nil, nil, nil)
1218+
TestQueryWithContext(t, ctx, e, harness, tt.query, tt.expRows, types.OkResultSchema, nil, nil)
12021219
res, err := os.ReadFile(tt.file)
12031220
require.NoError(t, err)
12041221
require.Equal(t, tt.exp, string(res))

enginetest/queries/script_queries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ CREATE TABLE tab3 (
16261626
// SELECT INTO has an empty result schema
16271627
// https://github.com/dolthub/dolt/issues/6105
16281628
Query: `SELECT 1 INTO @abc`,
1629-
Expected: []sql.Row{{}},
1629+
Expected: []sql.Row{{types.NewOkResult(1)}},
16301630
ExpectedColumns: nil,
16311631
},
16321632
{

sql/plan/into.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ package plan
1616

1717
import (
1818
"fmt"
19-
"strings"
19+
"github.com/dolthub/go-mysql-server/sql/types"
20+
"strings"
2021

2122
"github.com/dolthub/go-mysql-server/sql"
2223
)
@@ -79,7 +80,7 @@ var emptySch = make(sql.Schema, 0)
7980
func (i *Into) Schema() sql.Schema {
8081
// SELECT INTO does not return results directly (only through SQL vars or files),
8182
// so it's result schema is always empty.
82-
return emptySch
83+
return types.OkResultSchema
8384
}
8485

8586
func (i *Into) IsReadOnly() bool {

sql/rowexec/rel.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ func (b *BaseBuilder) buildInto(ctx *sql.Context, n *plan.Into, row sql.Row) (sq
630630
}
631631
file.WriteString(n.LinesTerminatedBy)
632632
}
633-
return sql.RowsToRowIter(sql.Row{}), nil
633+
return sql.RowsToRowIter(sql.Row{types.NewOkResult(len(rows))}), nil
634634
}
635635

636636
rowNum := len(rows)
@@ -652,12 +652,12 @@ func (b *BaseBuilder) buildInto(ctx *sql.Context, n *plan.Into, row sql.Row) (sq
652652
file.WriteString(fmt.Sprintf("%v", val))
653653
}
654654
}
655-
return sql.RowsToRowIter(sql.Row{}), nil
655+
return sql.RowsToRowIter(sql.Row{types.NewOkResult(rowNum)}), nil
656656
}
657657

658658
if rowNum == 0 {
659659
// a warning with error code 1329 occurs (No data), and make no change to variables
660-
return sql.RowsToRowIter(sql.Row{}), nil
660+
return sql.RowsToRowIter(sql.Row{types.NewOkResult(0)}), nil
661661
}
662662
if len(rows[0]) != len(n.IntoVars) {
663663
return nil, sql.ErrColumnNumberDoesNotMatch.New()
@@ -684,7 +684,7 @@ func (b *BaseBuilder) buildInto(ctx *sql.Context, n *plan.Into, row sql.Row) (sq
684684
}
685685
}
686686

687-
return sql.RowsToRowIter(sql.Row{}), nil
687+
return sql.RowsToRowIter(sql.Row{types.NewOkResult(1)}), nil
688688
}
689689

690690
func (b *BaseBuilder) buildExternalProcedure(ctx *sql.Context, n *plan.ExternalProcedure, row sql.Row) (sql.RowIter, error) {

0 commit comments

Comments
 (0)