From e40c7c95ba0e2d8088776c677e9086426a0392f6 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Sat, 9 May 2020 20:24:34 +0530 Subject: [PATCH] enable set statement test Signed-off-by: Harshit Gangal --- go/vt/vtgate/executor_set_test.go | 438 ++++++++++++++++-------------- 1 file changed, 233 insertions(+), 205 deletions(-) diff --git a/go/vt/vtgate/executor_set_test.go b/go/vt/vtgate/executor_set_test.go index dc65530dec2..71ba67650c6 100644 --- a/go/vt/vtgate/executor_set_test.go +++ b/go/vt/vtgate/executor_set_test.go @@ -19,6 +19,9 @@ package vtgate import ( "testing" + "vitess.io/vitess/go/mysql" + querypb "vitess.io/vitess/go/vt/proto/query" + "vitess.io/vitess/go/test/utils" "vitess.io/vitess/go/vt/vterrors" @@ -43,211 +46,201 @@ func TestExecutorSet(t *testing.T) { out *vtgatepb.Session err string }{{ - // in: "set autocommit = 1", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set @@autocommit = true", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set @@session.autocommit = true", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set @@session.`autocommit` = true", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set @@session.'autocommit' = true", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set @@session.\"autocommit\" = true", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set autocommit = true", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set autocommit = on", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set autocommit = ON", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set autocommit = 'on'", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set autocommit = `on`", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set autocommit = \"on\"", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set autocommit = false", - // out: &vtgatepb.Session{}, - //}, { - // in: "set autocommit = off", - // out: &vtgatepb.Session{}, - //}, { - // in: "set autocommit = OFF", - // out: &vtgatepb.Session{}, - //}, { - // in: "set AUTOCOMMIT = 0", - // out: &vtgatepb.Session{}, - //}, { - // in: "set AUTOCOMMIT = 'aa'", - // err: "unexpected value for autocommit: aa", - //}, { - // in: "set autocommit = 2", - // err: "unexpected value for autocommit: 2", - //}, { - // in: "set client_found_rows = 1", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{ClientFoundRows: true}}, - //}, { - // in: "set client_found_rows = true", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{ClientFoundRows: true}}, - //}, { - // in: "set client_found_rows = 0", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{}}, - //}, { - // in: "set client_found_rows = false", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{}}, - //}, { - // in: "set @@global.client_found_rows = 1", - // err: "unsupported in set: global", - //}, { - // in: "set global client_found_rows = 1", - // err: "unsupported in set: global", - //}, { - // in: "set global @@session.client_found_rows = 1", - // err: "cannot use scope and @@", - //}, { - // in: "set client_found_rows = 'aa'", - // err: "unexpected value type for client_found_rows: string", - //}, { - // in: "set client_found_rows = 2", - // err: "unexpected value for client_found_rows: 2", - //}, { - // in: "set transaction_mode = 'unspecified'", - // out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_UNSPECIFIED}, - //}, { - // in: "set transaction_mode = 'single'", - // out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_SINGLE}, - //}, { - // in: "set transaction_mode = 'multi'", - // out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_MULTI}, - //}, { - // in: "set transaction_mode = 'twopc'", - // out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_TWOPC}, - //}, { - // in: "set transaction_mode = twopc", - // out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_TWOPC}, - //}, { - // in: "set transaction_mode = 'aa'", - // err: "invalid transaction_mode: aa", - //}, { - // in: "set transaction_mode = 1", - // err: "unexpected value type for transaction_mode: int64", - //}, { - // in: "set workload = 'unspecified'", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{Workload: querypb.ExecuteOptions_UNSPECIFIED}}, - //}, { - // in: "set workload = 'oltp'", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{Workload: querypb.ExecuteOptions_OLTP}}, - //}, { - // in: "set workload = 'olap'", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{Workload: querypb.ExecuteOptions_OLAP}}, - //}, { - // in: "set workload = 'dba'", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{Workload: querypb.ExecuteOptions_DBA}}, - //}, { - // in: "set workload = 'aa'", - // err: "invalid workload: aa", - //}, { - // in: "set workload = 1", - // err: "unexpected value type for workload: int64", - //}, { - // in: "set transaction_mode = 'twopc', autocommit=1", - // out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_TWOPC}, - //}, { - // in: "set sql_select_limit = 5", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{SqlSelectLimit: 5}}, - //}, { - // in: "set sql_select_limit = DEFAULT", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{SqlSelectLimit: 0}}, - //}, { - // in: "set sql_select_limit = 'asdfasfd'", - // err: "unexpected string value for sql_select_limit: asdfasfd", - //}, { - // in: "set autocommit = 1+1", - // err: "invalid syntax: 1 + 1", - //}, { - // in: "set character_set_results=null", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set character_set_results='abcd'", - // err: "disallowed value for character_set_results: abcd", - //}, { - // in: "set foo = 1", - // err: "unsupported construct: set foo = 1", - //}, { - // in: "set names utf8", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set names ascii", - // err: "unexpected value for charset/names: ascii", - //}, { - // in: "set charset utf8", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set character set default", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set character set ascii", - // err: "unexpected value for charset/names: ascii", - //}, { - // in: "set net_write_timeout = 600", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set sql_mode = 'STRICT_ALL_TABLES'", - // out: &vtgatepb.Session{Autocommit: true, - // Warnings: []*querypb.QueryWarning{{ - // Code: mysql.ERNotSupportedYet, - // Message: "Ignored inapplicable SET sql_mode = 'STRICT_ALL_TABLES'", - // }}}, - //}, { - // in: "set net_read_timeout = 600", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set sql_quote_show_create = 1", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set foreign_key_checks = 0", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set unique_checks = 0", - // out: &vtgatepb.Session{Autocommit: true}, - //}, { - // in: "set skip_query_plan_cache = 1", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{SkipQueryPlanCache: true}}, - //}, { - // in: "set skip_query_plan_cache = 0", - // out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{}}, - //}, { - // in: "set sql_auto_is_null = 0", - // out: &vtgatepb.Session{Autocommit: true}, // no effect - //}, { - // in: "set sql_auto_is_null = 1", - // err: "sql_auto_is_null is not currently supported", - //}, { - // in: "set tx_read_only = 2", - // err: "unexpected value for tx_read_only: 2", - //}, { - // in: "set transaction_read_only = 2", - // err: "unexpected value for transaction_read_only: 2", - //}, { - // in: "set tx_isolation = 'invalid'", - // err: "unexpected value for tx_isolation: invalid", - //}, { - // in: "set sql_safe_updates = 2", - // err: "unexpected value for sql_safe_updates: 2", - //}, { + in: "set autocommit = 1", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set @@autocommit = true", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set @@session.autocommit = true", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set @@session.`autocommit` = true", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set @@session.'autocommit' = true", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set @@session.\"autocommit\" = true", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set autocommit = true", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set autocommit = on", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set autocommit = ON", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set autocommit = 'on'", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set autocommit = `on`", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set autocommit = \"on\"", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set autocommit = false", + out: &vtgatepb.Session{}, + }, { + in: "set autocommit = off", + out: &vtgatepb.Session{}, + }, { + in: "set autocommit = OFF", + out: &vtgatepb.Session{}, + }, { + in: "set AUTOCOMMIT = 0", + out: &vtgatepb.Session{}, + }, { + in: "set AUTOCOMMIT = 'aa'", + err: "unexpected value for autocommit: aa", + }, { + in: "set autocommit = 2", + err: "unexpected value for autocommit: 2", + }, { + in: "set client_found_rows = 1", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{ClientFoundRows: true}}, + }, { + in: "set client_found_rows = true", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{ClientFoundRows: true}}, + }, { + in: "set client_found_rows = 0", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{}}, + }, { + in: "set client_found_rows = false", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{}}, + }, { + in: "set @@global.client_found_rows = 1", + err: "unsupported in set: global", + }, { + in: "set global client_found_rows = 1", + err: "unsupported in set: global", + }, { + in: "set global @@session.client_found_rows = 1", + err: "cannot use scope and @@", + }, { + in: "set client_found_rows = 'aa'", + err: "unexpected value type for client_found_rows: string", + }, { + in: "set client_found_rows = 2", + err: "unexpected value for client_found_rows: 2", + }, { + in: "set transaction_mode = 'unspecified'", + out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_UNSPECIFIED}, + }, { + in: "set transaction_mode = 'single'", + out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_SINGLE}, + }, { + in: "set transaction_mode = 'multi'", + out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_MULTI}, + }, { + in: "set transaction_mode = 'twopc'", + out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_TWOPC}, + }, { + in: "set transaction_mode = twopc", + out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_TWOPC}, + }, { + in: "set transaction_mode = 'aa'", + err: "invalid transaction_mode: aa", + }, { + in: "set transaction_mode = 1", + err: "unexpected value type for transaction_mode: int64", + }, { + in: "set workload = 'unspecified'", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{Workload: querypb.ExecuteOptions_UNSPECIFIED}}, + }, { + in: "set workload = 'oltp'", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{Workload: querypb.ExecuteOptions_OLTP}}, + }, { + in: "set workload = 'olap'", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{Workload: querypb.ExecuteOptions_OLAP}}, + }, { + in: "set workload = 'dba'", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{Workload: querypb.ExecuteOptions_DBA}}, + }, { + in: "set workload = 'aa'", + err: "invalid workload: aa", + }, { + in: "set workload = 1", + err: "unexpected value type for workload: int64", + }, { + in: "set transaction_mode = 'twopc', autocommit=1", + out: &vtgatepb.Session{Autocommit: true, TransactionMode: vtgatepb.TransactionMode_TWOPC}, + }, { + in: "set sql_select_limit = 5", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{SqlSelectLimit: 5}}, + }, { + in: "set sql_select_limit = DEFAULT", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{SqlSelectLimit: 0}}, + }, { + in: "set sql_select_limit = 'asdfasfd'", + err: "unexpected string value for sql_select_limit: asdfasfd", + }, { + in: "set autocommit = 1+1", + err: "invalid syntax: 1 + 1", + }, { + in: "set character_set_results=null", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set character_set_results='abcd'", + err: "disallowed value for character_set_results: abcd", + }, { + in: "set foo = 1", + err: "unsupported construct: set foo = 1", + }, { + in: "set names utf8", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set names ascii", + err: "unexpected value for charset/names: ascii", + }, { + in: "set charset utf8", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set character set default", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set character set ascii", + err: "unexpected value for charset/names: ascii", + }, { + in: "set net_write_timeout = 600", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set net_read_timeout = 600", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set sql_quote_show_create = 1", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set foreign_key_checks = 0", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set unique_checks = 0", + out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set skip_query_plan_cache = 1", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{SkipQueryPlanCache: true}}, + }, { + in: "set skip_query_plan_cache = 0", + out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{}}, + }, { + in: "set sql_auto_is_null = 0", + out: &vtgatepb.Session{Autocommit: true}, // no effect + }, { + in: "set sql_auto_is_null = 1", + err: "sql_auto_is_null is not currently supported", + }, { + in: "set tx_read_only = 2", + err: "unexpected value for tx_read_only: 2", + }, { + in: "set transaction_read_only = 2", + err: "unexpected value for transaction_read_only: 2", + }, { + in: "set tx_isolation = 'invalid'", + err: "unexpected value for tx_isolation: invalid", + }, { in: "set @foo = 'bar'", out: &vtgatepb.Session{UserDefinedVariables: createMap([]string{"foo"}, []interface{}{"bar"}), Autocommit: true}, }, { @@ -294,6 +287,41 @@ func TestExecutorSet(t *testing.T) { } } +func TestExecutorSetOp(t *testing.T) { + executor, sbc1, _, _ := createExecutorEnv() + + testcases := []struct { + in string + warning []*querypb.QueryWarning + sysVars map[string]string + }{{ + in: "set sql_mode = 'STRICT_ALL_TABLES'", + warning: []*querypb.QueryWarning{{ + Code: mysql.ERNotSupportedYet, + Message: "Ignored inapplicable SET sql_mode = 'STRICT_ALL_TABLES'", + }}, + }, { + in: "set sql_safe_updates = 2", + sysVars: map[string]string{"sql_safe_updates": "2"}, + }} + for _, tcase := range testcases { + t.Run(tcase.in, func(t *testing.T) { + sbc1.SetResults([]*sqltypes.Result{{}}) + session := NewAutocommitSession(masterSession) + session.TargetString = KsTestUnsharded + _, err := executor.Execute( + context.Background(), + "TestExecute", + session, + tcase.in, + nil) + require.NoError(t, err) + utils.MustMatch(t, tcase.warning, session.Warnings, "") + utils.MustMatch(t, tcase.sysVars, session.SystemVariables, "") + }) + } +} + func TestExecutorSetMetadata(t *testing.T) { executor, _, _, _ := createExecutorEnv() session := NewSafeSession(&vtgatepb.Session{TargetString: "@master", Autocommit: true})