Skip to content

Commit

Permalink
test: added reference test in e2e plan test
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Dec 23, 2024
1 parent 84625c7 commit 80523d3
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 72 deletions.
12 changes: 12 additions & 0 deletions go/test/endtoend/utils/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ func (mcmp *MySQLCompare) Exec(query string) *sqltypes.Result {
return vtQr
}

// ExecVitessAndMySQL executes Vitess and MySQL with the queries provided.
func (mcmp *MySQLCompare) ExecVitessAndMySQL(vtQ, mQ string) *sqltypes.Result {
mcmp.t.Helper()
vtQr, err := mcmp.VtConn.ExecuteFetch(vtQ, 1000, true)
require.NoError(mcmp.t, err, "[Vitess Error] for query: "+vtQ)

mysqlQr, err := mcmp.MySQLConn.ExecuteFetch(mQ, 1000, true)
require.NoError(mcmp.t, err, "[MySQL Error] for query: "+mQ)
compareVitessAndMySQLResults(mcmp.t, vtQ, mcmp.VtConn, vtQr, mysqlQr, CompareOptions{})
return vtQr
}

// ExecAssert is the same as Exec, but it only does assertions, it won't FailNow
func (mcmp *MySQLCompare) ExecAssert(query string) *sqltypes.Result {
mcmp.t.Helper()
Expand Down
5 changes: 3 additions & 2 deletions go/test/endtoend/vtgate/plan_tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql"
Expand Down Expand Up @@ -86,7 +87,7 @@ func TestMain(m *testing.M) {
// TODO: (@GuptaManan100/@systay): Also run the tests with normalizer on.
clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs,
"--normalize_queries=false",
"--schema_change_signal=false",
"--schema_change_signal=true",
)

// Start vtgate
Expand Down Expand Up @@ -178,7 +179,7 @@ func verifyTestExpectations(t *testing.T, pd engine.PrimitiveDescription, test p
// 1. Verify that the Join primitive sees atleast 1 row on the left side.
engine.WalkPrimitiveDescription(pd, func(description engine.PrimitiveDescription) {
if description.OperatorType == "Join" {
require.NotZero(t, description.Inputs[0].RowsReceived[0])
assert.NotZero(t, description.Inputs[0].RowsReceived[0])
}
})

Expand Down
18 changes: 16 additions & 2 deletions go/test/endtoend/vtgate/plan_tests/plan_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ package plan_tests
import (
"testing"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/endtoend/utils"
"vitess.io/vitess/go/vt/sqlparser"
)

func TestE2ECases(t *testing.T) {
e2eTestCaseFiles := []string{"select_cases.json", "filter_cases.json"}
err := utils.WaitForAuthoritative(t, "main", "source_of_ref", clusterInstance.VtgateProcess.ReadVSchema)
require.NoError(t, err)

e2eTestCaseFiles := []string{
"select_cases.json",
"filter_cases.json",
"reference_cases.json",
}
mcmp, closer := start(t)
defer closer()
loadSampleData(t, mcmp)
Expand All @@ -34,7 +44,11 @@ func TestE2ECases(t *testing.T) {
if test.SkipE2E {
mcmp.AsT().Skip(test.Query)
}
mcmp.Exec(test.Query)
stmt, err := sqlparser.NewTestParser().Parse(test.Query)
require.NoError(mcmp.AsT(), err)
sqlparser.RemoveKeyspaceIgnoreSysSchema(stmt)

mcmp.ExecVitessAndMySQL(test.Query, sqlparser.String(stmt))
pd := utils.ExecTrace(mcmp.AsT(), mcmp.VtConn, test.Query)
verifyTestExpectations(mcmp.AsT(), pd, test)
if mcmp.VtConn.IsClosed() {
Expand Down
19 changes: 19 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,25 @@ func RemoveKeyspace(in SQLNode) {
})
}

// RemoveKeyspaceIgnoreSysSchema removes the Qualifier.Qualifier on all ColNames and Qualifier on all TableNames in the AST
// except for the system schema.
func RemoveKeyspaceIgnoreSysSchema(in SQLNode) {
Rewrite(in, nil, func(cursor *Cursor) bool {
switch expr := cursor.Node().(type) {
case *ColName:
if expr.Qualifier.Qualifier.NotEmpty() && !SystemSchema(expr.Qualifier.Qualifier.String()) {
expr.Qualifier.Qualifier = NewIdentifierCS("")
}
case TableName:
if expr.Qualifier.NotEmpty() && !SystemSchema(expr.Qualifier.String()) {
expr.Qualifier = NewIdentifierCS("")
cursor.Replace(expr)
}
}
return true
})
}

func convertStringToInt(integer string) int {
val, _ := strconv.Atoi(integer)
return val
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/engine/plan_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func PrimitiveDescriptionFromMap(data map[string]any) (pd PrimitiveDescription,
}
}
if ttt, isPresent := data["TargetTabletType"]; isPresent {
pd.TargetTabletType = topodatapb.TabletType(ttt.(int))
pd.TargetTabletType = topodatapb.TabletType(topodatapb.TabletType_value[ttt.(string)])
}
if other, isPresent := data["Other"]; isPresent {
pd.Other = other.(map[string]any)
Expand Down
Loading

0 comments on commit 80523d3

Please sign in to comment.