-
Notifications
You must be signed in to change notification settings - Fork 109
Conversation
Finally it compiles after upgrading vitess. |
sql/parse/parse.go
Outdated
default: | ||
return nil, ErrUnsupportedFeature.New("qualifiers in set variable names other than @@session") | ||
name := strings.TrimSpace(e.Name.Lowered()) | ||
if strings.Contains(name, "autocommit") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ON/OFF only for autocommit on MySQL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there are different cases (I didn't investigate any other cases, just focused on this particular case), but the main issue here can be transformation. For some expressions Type()
panics.
I'm totally open to have the most generic solution transformation here.
@erizocosmico - I've made ON/OFF more generic (no autocommit checks). I just added extra if
in transformation and looks that it works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!
Some minor changes related with the makefile script that is already on another PR and questions about variables.
_scripts/go-vitess/Makefile
Outdated
@@ -1,56 +1,41 @@ | |||
# Tooling to create the package `gopkg.in/src-d/go-vitess.v0`. | |||
# Tooling to create the package `gopkg.in/src-d/go-vitess.v1`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to have this script separated in another PR as you did: #384
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it's already there
#384. I just didn't revert changes on this branch (so doesn't matter in what order we'll merge it, hopefully there will not be conflicts).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#384 is already merged. This file shouldn't be here now.
engine_test.go
Outdated
@@ -1081,7 +1081,7 @@ func TestSessionVariables(t *testing.T) { | |||
session := sql.NewBaseSession() | |||
ctx := sql.NewContext(context.Background(), sql.WithSession(session), sql.WithPid(1)) | |||
|
|||
_, _, err := e.Query(ctx, `set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')`) | |||
_, _, err := e.Query(ctx, `set autocommit=ON, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autocommit=1 should work too, so I would prefer to do not change this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I'll add another test.
@@ -1,65 +1,19 @@ | |||
module gopkg.in/src-d/go-mysql-server.v0 | |||
|
|||
require ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it normal that all that dependencies disappear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how vgo builds this dependency graph, but as you see everything what disappeared are indirect deps. The good thing is that it still builds.
@@ -654,14 +654,70 @@ var fixtures = map[string]sql.Node{ | |||
), | |||
`SET @@session.autocommit=1, foo="bar"`: plan.NewSet( | |||
plan.SetVariable{ | |||
Name: "autocommit", | |||
Name: "@@session.autocommit", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this means that we are adding session variables as global variables (but with a name @@session.blah
) now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change adding @@session.
? It should work without it too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because right now for SetExpr
we don't have Qualifiers
so in convertSet
we return what was passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we should trim that part as it was before. Only session variables should be saved with Set
sql/session.go
Outdated
@@ -51,13 +53,25 @@ func (s *BaseSession) Address() string { return s.addr } | |||
func (s *BaseSession) Set(key string, typ Type, value interface{}) { | |||
s.mu.Lock() | |||
defer s.mu.Unlock() | |||
|
|||
key = strings.TrimLeft(key, "@") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, all variables are set as session level? what happens when the user disconnects? per example autocommit=1
will disappear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autocommit is a session variable, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here what I only changed is checking if we have session prefix and remove them before set. Because right now we don't have Qualifiers in SetExpr
, so if you try sth, like:
SET @autocommit = 1
SELECT @@session.autocommit
we'll set in s.config["autocommit"]=1
but for select we'll try to get s.config["session.autocommit"]
what is not there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's why the session.
should be removed in the select
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, makes sense. I've moved that logic from session.Get/Set to
analyzer.resolveColumns
and to plan.(*Set)RowIter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to fix TestResolveColumnsSession
. I think right now it wasn't right (correct me if I'm wrong):
it looked like:
node := plan.NewProject(
[]sql.Expression{
expression.NewUnresolvedColumn("@@foo_bar"),
expression.NewUnresolvedColumn("@@bar_baz"),
},
plan.NewResolvedTable(dualTable),
)
result, err := resolveColumns(ctx, NewDefault(nil), node)
require.NoError(err)
expected := plan.NewProject(
[]sql.Expression{
expression.NewGetSessionField("@@foo_bar", sql.Int64, int64(42)), // <-- @@-
expression.NewGetSessionField("@@bar_baz", sql.Null, nil), // <-- @@
},
plan.NewResolvedTable(dualTable),
)
I assumed that in session we don't keep fields prefixed by @
, because:
- if you take a look into session config:
func defaultSessionConfig() map[string]typedValue {
return map[string]typedValue{
"auto_increment_increment": typedValue{Int64, int64(1)},
"time_zone": typedValue{Text, time.Local.String()},
"system_time_zone": typedValue{Text, time.Local.String()},
"max_allowed_packet": typedValue{Int32, math.MaxInt32},
"sql_mode": typedValue{Text, ""},
}
}
- and also
func (f *GetSessionField) String() string { return "@@" + f.name }
already prefixes with "@".
@kuba-- could you rebase please? |
@ajnavarro - done. |
@ajnavarro - hmm I've rebased again and I don't see Makefile in changes. |
sql/session.go
Outdated
@@ -51,13 +51,15 @@ func (s *BaseSession) Address() string { return s.addr } | |||
func (s *BaseSession) Set(key string, typ Type, value interface{}) { | |||
s.mu.Lock() | |||
defer s.mu.Unlock() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that file shouldn't be modified on that PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just session.go minor change and LGTM
hmm, we are testing with session columns, and that line appears that never is true: https://codecov.io/gh/src-d/go-mysql-server/compare/7f8e182c469e77663f886baa8170a5662733d185...645a95d0855995f7b623c4d4b862e835478d57e4/src/sql/analyzer/resolve_columns.go#L71 |
Signed-off-by: kuba-- <kuba@sourced.tech> Add more parser tests. Handle also true/false. Signed-off-by: kuba-- <kuba@sourced.tech>
@ajnavarro - I've added many tests (even to test this particular line), but I'm not sure why this cover tool still complains. |
@kuba-- I don't know if this is the case but coverage by default only counts coverage in files from the same package as the test. If that code path is used with a test from another package it's not counted. |
@jfontan - I think it's not the case. I extended |
Signed-off-by: kuba-- kuba@sourced.tech
It closes #374