Skip to content

Commit

Permalink
modified sysvarIgnore op to store expr string than plan value
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Apr 15, 2020
1 parent b56705b commit 470a63c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
19 changes: 14 additions & 5 deletions go/test/endtoend/vtgate/setstatement/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ func TestSetSysVar(t *testing.T) {
Port: clusterInstance.VtgateMySQLPort,
}
type queriesWithExpectations struct {
query string
expectedRows string
rowsAffected int
errMsg string
query string
expectedRows string
rowsAffected int
errMsg string
expectedWarning string
}

queries := []queriesWithExpectations{{
query: `set @@debug = 'T'`,
query: `set @@default_storage_engine = INNODB`,
expectedRows: ``, rowsAffected: 0,
expectedWarning: "[[VARCHAR(\"Warning\") UINT16(1235) VARCHAR(\"Ignored inapplicable SET default_storage_engine = INNODB\")]]",
}, {
query: `set @@sql_mode = @@sql_mode`,
expectedRows: ``, rowsAffected: 0,
Expand Down Expand Up @@ -74,6 +76,13 @@ func TestSetSysVar(t *testing.T) {
t.Errorf("%s\nfor query: %s", diff, q.query)
}
}
if q.expectedWarning != "" {
qr, err := exec(t, conn, "show warnings")
require.NoError(t, err)
if got, want := fmt.Sprintf("%v", qr.Rows), q.expectedWarning; got != want {
t.Errorf("select:\n%v want\n%v", got, want)
}
}
}
})
}
Expand Down
10 changes: 3 additions & 7 deletions go/vt/vtgate/engine/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ type (

// SysVarIgnore implements the SetOp interface to ignore the settings.
SysVarIgnore struct {
Name string
PlanValue sqltypes.PlanValue
Name string
Expr string
}

// SysVarCheckAndIgnore implements the SetOp interface to check underlying setting and ignore if same.
Expand Down Expand Up @@ -163,11 +163,7 @@ func (svi *SysVarIgnore) VariableName() string {

//Execute implements the SetOp interface method.
func (svi *SysVarIgnore) Execute(vcursor VCursor, bindVars map[string]*querypb.BindVariable) error {
value, err := svi.PlanValue.ResolveValue(bindVars)
if err != nil {
return err
}
vcursor.Session().RecordWarning(&querypb.QueryWarning{Code: mysql.ERNotSupportedYet, Message: fmt.Sprintf("Ignored inapplicable SET %v = %v", svi.Name, value.String())})
vcursor.Session().RecordWarning(&querypb.QueryWarning{Code: mysql.ERNotSupportedYet, Message: fmt.Sprintf("Ignored inapplicable SET %v = %v", svi.Name, svi.Expr)})
return nil
}

Expand Down
12 changes: 4 additions & 8 deletions go/vt/vtgate/engine/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ func TestSetTable(t *testing.T) {
setOps: []SetOp{
&SysVarIgnore{
Name: "x",
PlanValue: sqltypes.PlanValue{
Value: sqltypes.NewInt64(42),
},
Expr: "42",
},
},
expectedWarning: []*querypb.QueryWarning{
{Code: 1235, Message: "Ignored inapplicable SET x = INT64(42)"},
{Code: 1235, Message: "Ignored inapplicable SET x = 42"},
},
},
{
Expand Down Expand Up @@ -144,9 +142,7 @@ func TestSetTable(t *testing.T) {
},
&SysVarIgnore{
Name: "y",
PlanValue: sqltypes.PlanValue{
Value: sqltypes.NewInt64(2),
},
Expr: "2",
},
&SysVarCheckAndIgnore{
Name: "z",
Expand All @@ -164,7 +160,7 @@ func TestSetTable(t *testing.T) {
`ExecuteMultiShard ks.-20: dummy_query {} false false`,
},
expectedWarning: []*querypb.QueryWarning{
{Code: 1235, Message: "Ignored inapplicable SET y = INT64(2)"},
{Code: 1235, Message: "Ignored inapplicable SET y = 2"},
},
qr: []*sqltypes.Result{sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
Expand Down
11 changes: 5 additions & 6 deletions go/vt/vtgate/planbuilder/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ func buildSetPlan(sql string, stmt *sqlparser.Set, vschema ContextVSchema) (engi
}

func buildSetOpIgnore(expr *sqlparser.SetExpr, _ ContextVSchema) (engine.SetOp, error) {
pv, err := sqlparser.NewPlanValue(expr.Expr)
if err != nil {
return nil, err
}
buf := sqlparser.NewTrackedBuffer(nil)
buf.Myprintf("%v", expr.Expr)

return &engine.SysVarIgnore{
Name: expr.Name.Lowered(),
PlanValue: pv,
Name: expr.Name.Lowered(),
Expr: buf.String(),
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/testdata/set_sysvar_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"Type": "SysVarIgnore",
"Name": "default_storage_engine",
"PlanValue": "DONOTCHANGEME"
"Expr": "'DONOTCHANGEME'"
}
]
}
Expand Down

0 comments on commit 470a63c

Please sign in to comment.