Skip to content

Commit

Permalink
Merge pull request #3 from vitessio/vexplain
Browse files Browse the repository at this point in the history
add support for vexplain prefix and more subquery tests
  • Loading branch information
GuptaManan100 authored Jun 12, 2024
2 parents 5f290d8 + 2438913 commit a7824d2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/vitess-tester/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const (
Q_COMMENT_WITH_COMMAND
Q_EMPTY_LINE
Q_SKIP_IF_BELOW_VERSION
Q_VEXPLAIN
)

// ParseQueries parses an array of string into an array of query object.
Expand Down
19 changes: 19 additions & 0 deletions src/vitess-tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type tester struct {
skipBinary string
skipVersion int
skipNext bool
vexplain string

// check expected error, use --error before the statement
// we only care if an error is returned, not the exact error message.
Expand Down Expand Up @@ -131,6 +132,14 @@ func (t *tester) Run() error {
}
case Q_ERROR:
t.expectedErrs = true
case Q_VEXPLAIN:
strs := strings.Split(q.Query, " ")
if len(strs) != 2 {
t.reporter.AddFailure(fmt.Errorf("incorrect syntax for Q_VEXPLAIN in: %v", q.Query))
continue
}

t.vexplain = strs[1]
case Q_QUERY:
if t.skipNext {
t.skipNext = false
Expand All @@ -143,6 +152,16 @@ func (t *tester) Run() error {
continue
}
}
if t.vexplain != "" {
result, err := t.curr.VtConn.ExecuteFetch("vexplain "+t.vexplain+" "+q.Query, -1, false)
t.vexplain = ""
if err != nil {
t.reporter.AddFailure(err)
continue
}

t.reporter.AddFailure(fmt.Errorf("VExplain Output:\n %s\n", result.Rows[0][0].ToString()))
}
t.reporter.AddTestCase(q.Query, q.Line)
if err = t.execute(q); err != nil && !t.expectedErrs {
t.reporter.AddFailure(err)
Expand Down
1 change: 1 addition & 0 deletions src/vitess-tester/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var commandMap = map[string]CmdType{
"begin_concurrent": Q_BEGIN_CONCURRENT,
"end_concurrent": Q_END_CONCURRENT,
"skip_if_below_version": Q_SKIP_IF_BELOW_VERSION,
"vexplain": Q_VEXPLAIN,
}

func findType(cmdName string) CmdType {
Expand Down
16 changes: 15 additions & 1 deletion t/subqueries.test
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,18 @@ FROM
GROUP BY
id, name
ORDER BY
(SELECT SUM(LENGTH(extra_info)) FROM user_extra WHERE user_extra.user_id = user.id);
(SELECT SUM(LENGTH(extra_info)) FROM user_extra WHERE user_extra.user_id = user.id);

select max((select min(user_id) from user_extra))
from user
where id = 1;

select
max((select group_concat(id, name) from user where id = 1));

--skip this is buggy at the moment
select max((select max(name) from user u1 where u1.id = u2.id))
from user u2;

select count(distinct name, id)
from user;

0 comments on commit a7824d2

Please sign in to comment.