Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added vitess_version as variable #7295

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this query supposed to work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works

SELECT @@version_comment;
+----------------------------------------------------------------------------------------------------------------------------------------------+
| @@version_comment                                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------------------------------+
| Version: 11.0.0-SNAPSHOT (Git revision  branch '') built on Fri Apr 30 16:22:55 UTC 2021 by root@buildkitsandbox using go1.15.11 linux/amd64 |
+----------------------------------------------------------------------------------------------------------------------------------------------+

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