Skip to content

Commit

Permalink
Merge pull request #7295 from Akilan1999/version_variable_vitess
Browse files Browse the repository at this point in the history
added vitess_version as variable
  • Loading branch information
systay authored Jan 14, 2021
2 parents ae24394 + 8712908 commit da03789
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions go/vt/sqlparser/ast_rewriting.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ func (er *expressionRewriter) sysVarRewrite(cursor *Cursor, node *ColName) {
sysvars.SessionUUID.Name,
sysvars.ReadAfterWriteGTID.Name,
sysvars.ReadAfterWriteTimeOut.Name,
sysvars.VitessVersion.Name,
sysvars.SessionTrackGTIDs.Name:
cursor.Replace(bindVarExpression("__vt" + lowered))
er.bindVars.AddSysVar(lowered)
Expand Down
7 changes: 6 additions & 1 deletion go/vt/sqlparser/ast_rewriting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ type myTestCase struct {
ddlStrategy, sessionUUID bool
udv int
autocommit, clientFoundRows, skipQueryPlanCache bool
sqlSelectLimit, transactionMode, workload bool
sqlSelectLimit, transactionMode, workload, vitessVersion bool
}

func TestRewrites(in *testing.T) {
tests := []myTestCase{{
in: "SELECT 42",
expected: "SELECT 42",
// no bindvar needs
}, {
in: "SELECT @@vitess_version",
expected: "SELECT :__vtvitess_version as `@@vitess_version`",
vitessVersion: true,
}, {
in: "SELECT last_insert_id()",
expected: "SELECT :__lastInsertId as `last_insert_id()`",
Expand Down Expand Up @@ -198,6 +202,7 @@ func TestRewrites(in *testing.T) {
assert.Equal(tc.rawGTID, result.NeedsSysVar(sysvars.ReadAfterWriteGTID.Name), "should need rawGTID")
assert.Equal(tc.rawTimeout, result.NeedsSysVar(sysvars.ReadAfterWriteTimeOut.Name), "should need rawTimeout")
assert.Equal(tc.sessTrackGTID, result.NeedsSysVar(sysvars.SessionTrackGTIDs.Name), "should need sessTrackGTID")
assert.Equal(tc.vitessVersion, result.NeedsSysVar(sysvars.VitessVersion.Name), "should need Vitess version")
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion go/vt/sysvars/sysvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ var (
Names = SystemVariable{Name: "names", Default: utf8, IdentifierAsString: true}
SessionUUID = SystemVariable{Name: "session_uuid", IdentifierAsString: true}
// Online DDL
DDLStrategy = SystemVariable{Name: "ddl_strategy", IdentifierAsString: true}
DDLStrategy = SystemVariable{Name: "ddl_strategy", IdentifierAsString: true}
VitessVersion = SystemVariable{Name: "vitess_version", IdentifierAsString: true}

// Read After Write settings
ReadAfterWriteGTID = SystemVariable{Name: "read_after_write_gtid"}
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"sync"
"time"

"vitess.io/vitess/go/vt/servenv"

"vitess.io/vitess/go/vt/sysvars"

"context"
Expand Down Expand Up @@ -315,6 +317,8 @@ func (e *Executor) addNeededBindVars(bindVarNeeds *sqlparser.BindVarNeeds, bindV
}
})
bindVars[key] = sqltypes.StringBindVariable(v)
case sysvars.VitessVersion.Name:
bindVars[key] = sqltypes.StringBindVariable(servenv.AppVersion.String())
}
}

Expand Down

0 comments on commit da03789

Please sign in to comment.