Skip to content

Commit c8d811d

Browse files
authored
chore: use generic set/show parser for auto_batch_dml (#507)
Remove the regex-based statements for auto_batch_dml variables. This automatically causes them to fall back to the generic SET and SHOW statements, and reduces the amount of code needed. These statements are already covered by existing tests, which is why this change does not add any new tests for this.
1 parent 9eea142 commit c8d811d

File tree

2 files changed

+0
-136
lines changed

2 files changed

+0
-136
lines changed

client_side_statement.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,6 @@ func (s *statementExecutor) ShowRetryAbortsInternally(_ context.Context, c *conn
5656
return createRows(it, opts), nil
5757
}
5858

59-
func (s *statementExecutor) ShowAutoBatchDml(_ context.Context, c *conn, _ string, opts *ExecOptions, _ []driver.NamedValue) (driver.Rows, error) {
60-
it, err := createBooleanIterator("AutoBatchDml", c.AutoBatchDml())
61-
if err != nil {
62-
return nil, err
63-
}
64-
return createRows(it, opts), nil
65-
}
66-
67-
func (s *statementExecutor) ShowAutoBatchDmlUpdateCount(_ context.Context, c *conn, _ string, opts *ExecOptions, _ []driver.NamedValue) (driver.Rows, error) {
68-
it, err := createInt64Iterator("AutoBatchDmlUpdateCount", c.AutoBatchDmlUpdateCount())
69-
if err != nil {
70-
return nil, err
71-
}
72-
return createRows(it, opts), nil
73-
}
74-
75-
func (s *statementExecutor) ShowAutoBatchDmlUpdateCountVerification(_ context.Context, c *conn, opts *ExecOptions, _ string, _ []driver.NamedValue) (driver.Rows, error) {
76-
it, err := createBooleanIterator("AutoBatchDmlUpdateCountVerification", c.AutoBatchDmlUpdateCountVerification())
77-
if err != nil {
78-
return nil, err
79-
}
80-
return createRows(it, opts), nil
81-
}
82-
8359
func (s *statementExecutor) ShowAutocommitDmlMode(_ context.Context, c *conn, _ string, opts *ExecOptions, _ []driver.NamedValue) (driver.Rows, error) {
8460
it, err := createStringIterator("AutocommitDMLMode", c.AutocommitDMLMode().String())
8561
if err != nil {
@@ -123,46 +99,6 @@ func (s *statementExecutor) SetRetryAbortsInternally(_ context.Context, c *conn,
12399
return c.setRetryAbortsInternally(retry)
124100
}
125101

126-
func (s *statementExecutor) SetAutoBatchDml(_ context.Context, c *conn, params string, _ *ExecOptions, _ []driver.NamedValue) (driver.Result, error) {
127-
return setBoolVariable("AutoBatchDml", func(value bool) (driver.Result, error) {
128-
return driver.ResultNoRows, c.SetAutoBatchDml(value)
129-
}, params)
130-
}
131-
132-
func (s *statementExecutor) SetAutoBatchDmlUpdateCount(_ context.Context, c *conn, params string, _ *ExecOptions, _ []driver.NamedValue) (driver.Result, error) {
133-
return setInt64Variable("AutoBatchDmlUpdateCount", func(value int64) (driver.Result, error) {
134-
return driver.ResultNoRows, c.SetAutoBatchDmlUpdateCount(value)
135-
}, params)
136-
}
137-
138-
func (s *statementExecutor) SetAutoBatchDmlUpdateCountVerification(_ context.Context, c *conn, params string, _ *ExecOptions, _ []driver.NamedValue) (driver.Result, error) {
139-
return setBoolVariable("AutoBatchDmlUpdateCountVerification", func(value bool) (driver.Result, error) {
140-
return driver.ResultNoRows, c.SetAutoBatchDmlUpdateCountVerification(value)
141-
}, params)
142-
}
143-
144-
func setBoolVariable(name string, f func(value bool) (driver.Result, error), params string) (driver.Result, error) {
145-
if params == "" {
146-
return nil, spanner.ToSpannerError(status.Errorf(codes.InvalidArgument, "no value given for %s", name))
147-
}
148-
value, err := strconv.ParseBool(params)
149-
if err != nil {
150-
return nil, spanner.ToSpannerError(status.Errorf(codes.InvalidArgument, "invalid boolean value: %s", params))
151-
}
152-
return f(value)
153-
}
154-
155-
func setInt64Variable(name string, f func(value int64) (driver.Result, error), params string) (driver.Result, error) {
156-
if params == "" {
157-
return nil, spanner.ToSpannerError(status.Errorf(codes.InvalidArgument, "no value given for %s", name))
158-
}
159-
value, err := strconv.ParseInt(params, 10, 64)
160-
if err != nil {
161-
return nil, spanner.ToSpannerError(status.Errorf(codes.InvalidArgument, "invalid int64 value: %s", params))
162-
}
163-
return f(value)
164-
}
165-
166102
func (s *statementExecutor) SetAutocommitDmlMode(_ context.Context, c *conn, params string, _ *ExecOptions, _ []driver.NamedValue) (driver.Result, error) {
167103
if params == "" {
168104
return nil, spanner.ToSpannerError(status.Error(codes.InvalidArgument, "no value given for AutocommitDMLMode"))

client_side_statements_json.go

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,6 @@ var jsonFile = `{
2626
"exampleStatements": ["show variable retry_aborts_internally"],
2727
"examplePrerequisiteStatements": ["set readonly=false", "set autocommit=false"]
2828
},
29-
{
30-
"name": "SHOW VARIABLE AUTO_BATCH_DML",
31-
"executorName": "ClientSideStatementNoParamExecutor",
32-
"resultType": "RESULT_SET",
33-
"statementType": "SHOW_AUTO_BATCH_DML",
34-
"regex": "(?is)\\A\\s*show\\s+variable\\s+auto_batch_dml\\s*\\z",
35-
"method": "statementShowAutoBatchDml",
36-
"exampleStatements": ["show variable auto_batch_dml"]
37-
},
38-
{
39-
"name": "SHOW VARIABLE AUTO_BATCH_DML_UPDATE_COUNT",
40-
"executorName": "ClientSideStatementNoParamExecutor",
41-
"resultType": "RESULT_SET",
42-
"statementType": "SHOW_AUTO_BATCH_DML_UPDATE_COUNT",
43-
"regex": "(?is)\\A\\s*show\\s+variable\\s+auto_batch_dml_update_count\\s*\\z",
44-
"method": "statementShowAutoBatchDmlUpdateCount",
45-
"exampleStatements": ["show variable auto_batch_dml_update_count"]
46-
},
47-
{
48-
"name": "SHOW VARIABLE AUTO_BATCH_DML_UPDATE_COUNT_VERIFICATION",
49-
"executorName": "ClientSideStatementNoParamExecutor",
50-
"resultType": "RESULT_SET",
51-
"statementType": "SHOW_AUTO_BATCH_DML_UPDATE_COUNT_VERIFICATION",
52-
"regex": "(?is)\\A\\s*show\\s+variable\\s+auto_batch_dml_update_count_verification\\s*\\z",
53-
"method": "statementShowAutoBatchDmlUpdateCountVerification",
54-
"exampleStatements": ["show variable auto_batch_dml_update_count_verification"]
55-
},
5629
{
5730
"name": "SHOW VARIABLE AUTOCOMMIT_DML_MODE",
5831
"executorName": "ClientSideStatementNoParamExecutor",
@@ -118,51 +91,6 @@ var jsonFile = `{
11891
"converterName": "ClientSideStatementValueConverters$BooleanConverter"
11992
}
12093
},
121-
{
122-
"name": "SET AUTO_BATCH_DML = TRUE|FALSE",
123-
"executorName": "ClientSideStatementSetExecutor",
124-
"resultType": "NO_RESULT",
125-
"statementType": "SET_AUTO_BATCH_DML",
126-
"regex": "(?is)\\A\\s*set\\s+auto_batch_dml\\s*(?:=)\\s*(.*)\\z",
127-
"method": "statementSetAutoBatchDml",
128-
"exampleStatements": ["set auto_batch_dml = true", "set auto_batch_dml = false"],
129-
"setStatement": {
130-
"propertyName": "AUTO_BATCH_DML",
131-
"separator": "=",
132-
"allowedValues": "(TRUE|FALSE)",
133-
"converterName": "ClientSideStatementValueConverters$BooleanConverter"
134-
}
135-
},
136-
{
137-
"name": "SET AUTO_BATCH_DML_UPDATE_COUNT = <INT64>",
138-
"executorName": "ClientSideStatementSetExecutor",
139-
"resultType": "NO_RESULT",
140-
"statementType": "SET_AUTO_BATCH_DML_UPDATE_COUNT",
141-
"regex": "(?is)\\A\\s*set\\s+auto_batch_dml_update_count\\s*(?:=)\\s*(.*)\\z",
142-
"method": "statementSetAutoBatchDmlUpdateCount",
143-
"exampleStatements": ["set auto_batch_dml_update_count = 0", "set auto_batch_dml_update_count = 100"],
144-
"setStatement": {
145-
"propertyName": "AUTO_BATCH_DML_UPDATE_COUNT",
146-
"separator": "=",
147-
"allowedValues": "(\\d{1,19})",
148-
"converterName": "ClientSideStatementValueConverters$LongConverter"
149-
}
150-
},
151-
{
152-
"name": "SET AUTO_BATCH_DML_UPDATE_COUNT_VERIFICATION = TRUE|FALSE",
153-
"executorName": "ClientSideStatementSetExecutor",
154-
"resultType": "NO_RESULT",
155-
"statementType": "SET_AUTO_BATCH_DML_UPDATE_COUNT_VERIFICATION",
156-
"regex": "(?is)\\A\\s*set\\s+auto_batch_dml_update_count_verification\\s*(?:=)\\s*(.*)\\z",
157-
"method": "statementSetAutoBatchDmlUpdateCountVerification",
158-
"exampleStatements": ["set auto_batch_dml_update_count_verification = true", "set auto_batch_dml_update_count_verification = false"],
159-
"setStatement": {
160-
"propertyName": "AUTO_BATCH_DML_UPDATE_COUNT_VERIFICATION",
161-
"separator": "=",
162-
"allowedValues": "(TRUE|FALSE)",
163-
"converterName": "ClientSideStatementValueConverters$BooleanConverter"
164-
}
165-
},
16694
{
16795
"name": "SET AUTOCOMMIT_DML_MODE = 'PARTITIONED_NON_ATOMIC'|'TRANSACTIONAL'",
16896
"executorName": "ClientSideStatementSetExecutor",

0 commit comments

Comments
 (0)