Skip to content

Commit 85546d5

Browse files
committed
sql,externalconn: add ALTER EXTERNAL CONNECTION Parser
Add AST parser support for the new SQL command ALTER EXTERNAL CONNECTION, allowing users to modify existing external connections. Fixes #98610
1 parent 9dd8ce2 commit 85546d5

File tree

13 files changed

+101
-6
lines changed

13 files changed

+101
-6
lines changed

docs/generated/sql/bnf/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ FILES = [
2525
"alter_database_to_schema_stmt",
2626
"alter_ddl_stmt",
2727
"alter_default_privileges_stmt",
28+
"alter_external_connection_stmt",
2829
"alter_func_stmt",
2930
"alter_func_options_stmt",
3031
"alter_func_rename_stmt",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
alter_external_connection_stmt ::=
2+
'ALTER' 'EXTERNAL' 'CONNECTION' label_spec 'AS' string_or_placeholder
3+
| 'ALTER' 'EXTERNAL' 'CONNECTION' 'IF' 'EXISTS' label_spec 'AS' string_or_placeholder
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
alter_stmt ::=
22
alter_ddl_stmt
3+
| alter_external_connection_stmt
34
| alter_role_stmt
45
| alter_virtual_cluster_stmt

docs/generated/sql/bnf/stmt_block.bnf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ legacy_end_stmt ::=
193193

194194
alter_stmt ::=
195195
alter_ddl_stmt
196+
| alter_external_connection_stmt
196197
| alter_role_stmt
197198
| alter_virtual_cluster_stmt
198199

@@ -560,6 +561,10 @@ alter_ddl_stmt ::=
560561
| alter_policy_stmt
561562
| alter_job_stmt
562563

564+
alter_external_connection_stmt ::=
565+
'ALTER' 'EXTERNAL' 'CONNECTION' label_spec 'AS' string_or_placeholder
566+
| 'ALTER' 'EXTERNAL' 'CONNECTION' 'IF' 'EXISTS' label_spec 'AS' string_or_placeholder
567+
563568
alter_role_stmt ::=
564569
'ALTER' role_or_group_or_user role_spec opt_role_options
565570
| 'ALTER' role_or_group_or_user 'IF' 'EXISTS' role_spec opt_role_options
@@ -1803,6 +1808,10 @@ alter_policy_stmt ::=
18031808
alter_job_stmt ::=
18041809
'ALTER' 'JOB' a_expr 'OWNER' 'TO' role_spec
18051810

1811+
label_spec ::=
1812+
string_or_placeholder
1813+
| 'IF' 'NOT' 'EXISTS' string_or_placeholder
1814+
18061815
role_or_group_or_user ::=
18071816
'ROLE'
18081817
| 'USER'
@@ -1935,10 +1944,6 @@ target_list ::=
19351944
changefeed_target_expr ::=
19361945
insert_target
19371946

1938-
label_spec ::=
1939-
string_or_placeholder
1940-
| 'IF' 'NOT' 'EXISTS' string_or_placeholder
1941-
19421947
logical_replication_resources ::=
19431948
'TABLE' db_object_name
19441949
| 'TABLES' '(' logical_replication_resources_list ')'

pkg/gen/bnf.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ BNF_SRCS = [
2525
"//docs/generated/sql/bnf:alter_database_to_schema_stmt.bnf",
2626
"//docs/generated/sql/bnf:alter_ddl_stmt.bnf",
2727
"//docs/generated/sql/bnf:alter_default_privileges_stmt.bnf",
28+
"//docs/generated/sql/bnf:alter_external_connection_stmt.bnf",
2829
"//docs/generated/sql/bnf:alter_func_dep_extension_stmt.bnf",
2930
"//docs/generated/sql/bnf:alter_func_options_stmt.bnf",
3031
"//docs/generated/sql/bnf:alter_func_owner_stmt.bnf",

pkg/gen/diagrams.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ DIAGRAMS_SRCS = [
2626
"//docs/generated/sql/bnf:alter_database_to_schema.html",
2727
"//docs/generated/sql/bnf:alter_ddl.html",
2828
"//docs/generated/sql/bnf:alter_default_privileges.html",
29+
"//docs/generated/sql/bnf:alter_external_connection.html",
2930
"//docs/generated/sql/bnf:alter_func.html",
3031
"//docs/generated/sql/bnf:alter_func_dep_extension.html",
3132
"//docs/generated/sql/bnf:alter_func_options.html",

pkg/gen/docs.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ DOCS_SRCS = [
3535
"//docs/generated/sql/bnf:alter_database_to_schema_stmt.bnf",
3636
"//docs/generated/sql/bnf:alter_ddl_stmt.bnf",
3737
"//docs/generated/sql/bnf:alter_default_privileges_stmt.bnf",
38+
"//docs/generated/sql/bnf:alter_external_connection_stmt.bnf",
3839
"//docs/generated/sql/bnf:alter_func_dep_extension_stmt.bnf",
3940
"//docs/generated/sql/bnf:alter_func_options_stmt.bnf",
4041
"//docs/generated/sql/bnf:alter_func_owner_stmt.bnf",

pkg/sql/parser/help_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestContextualHelp(t *testing.T) {
3535
{`ALTER CHANGEFEED ??`, `ALTER CHANGEFEED`},
3636
{`ALTER CHANGEFEED 123 ADD ??`, `ALTER CHANGEFEED`},
3737
{`ALTER CHANGEFEED 123 DROP ??`, `ALTER CHANGEFEED`},
38-
38+
{`ALTER EXTERNAL CONNECTION ??`, `ALTER EXTERNAL CONNECTION`},
3939
{`ALTER BACKUP foo ADD NEW_KMS=bar WITH OLD_KMS=foobar ??`, `ALTER BACKUP`},
4040

4141
{`ALTER JOB ??`, `ALTER JOB`},

pkg/sql/parser/sql.y

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,7 @@ func (u *sqlSymUnion) doBlockOption() tree.DoBlockOption {
12581258
%type <tree.Statement> create_database_stmt
12591259
%type <tree.Statement> create_extension_stmt
12601260
%type <tree.Statement> create_external_connection_stmt
1261+
%type <tree.Statement> alter_external_connection_stmt
12611262
%type <tree.Statement> create_index_stmt
12621263
%type <tree.Statement> create_role_stmt
12631264
%type <tree.Statement> create_schedule_for_backup_stmt
@@ -1925,9 +1926,10 @@ stmt_without_legacy_transaction:
19251926

19261927
// %Help: ALTER
19271928
// %Category: Group
1928-
// %Text: ALTER TABLE, ALTER INDEX, ALTER VIEW, ALTER SEQUENCE, ALTER DATABASE, ALTER USER, ALTER ROLE, ALTER DEFAULT PRIVILEGES
1929+
// %Text: ALTER TABLE, ALTER INDEX, ALTER VIEW, ALTER SEQUENCE, ALTER DATABASE, ALTER USER, ALTER ROLE, ALTER DEFAULT PRIVILEGES,ALTER EXTERNAL CONNECTION
19291930
alter_stmt:
19301931
alter_ddl_stmt // help texts in sub-rule
1932+
| alter_external_connection_stmt // EXTEND WITH HELP: ALTER EXTERNAL CONNECTION
19311933
| alter_role_stmt // EXTEND WITH HELP: ALTER ROLE
19321934
| alter_virtual_cluster_stmt /* SKIP DOC */
19331935
| alter_unsupported_stmt
@@ -3813,6 +3815,36 @@ opt_with_schedule_options:
38133815
$$.val = nil
38143816
}
38153817

3818+
// %Help: ALTER EXTERNAL CONNECTION - alter an existing external connection
3819+
// %Category: Misc
3820+
// %Text:
3821+
// ALTER EXTERNAL CONNECTION [IF EXISTS] <name> AS <endpoint>
3822+
//
3823+
// Name:
3824+
// Name of the created external connection
3825+
//
3826+
// Endpoint:
3827+
// Endpoint of the resource that the external connection represents.
3828+
alter_external_connection_stmt:
3829+
ALTER EXTERNAL CONNECTION /*$4=*/label_spec AS /*$6=*/string_or_placeholder
3830+
{
3831+
$$.val = &tree.AlterExternalConnection{
3832+
IfExists: false,
3833+
ConnectionLabelSpec: *($4.labelSpec()),
3834+
As: $6.expr(),
3835+
}
3836+
}
3837+
| ALTER EXTERNAL CONNECTION IF EXISTS /*$6=*/label_spec AS /*$8=*/string_or_placeholder
3838+
{
3839+
$$.val = &tree.AlterExternalConnection{
3840+
IfExists: true,
3841+
ConnectionLabelSpec: *($6.labelSpec()),
3842+
As: $8.expr(),
3843+
}
3844+
}
3845+
| ALTER EXTERNAL CONNECTION error // SHOW HELP: ALTER EXTERNAL CONNECTION
3846+
3847+
38163848

38173849
// %Help: CREATE EXTERNAL CONNECTION - create a new external connection
38183850
// %Category: Misc
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
parse
2+
ALTER EXTERNAL CONNECTION 'foo' AS 'bar'
3+
----
4+
ALTER EXTERNAL CONNECTION 'foo' AS '*****' -- normalized!
5+
ALTER EXTERNAL CONNECTION ('foo') AS ('*****') -- fully parenthesized
6+
ALTER EXTERNAL CONNECTION '_' AS '_' -- literals removed
7+
ALTER EXTERNAL CONNECTION 'foo' AS '*****' -- identifiers removed
8+
ALTER EXTERNAL CONNECTION 'foo' AS 'bar' -- passwords exposed
9+
10+
parse
11+
ALTER EXTERNAL CONNECTION IF EXISTS 'foo' AS 'bar'
12+
----
13+
ALTER EXTERNAL CONNECTION IF EXISTS 'foo' AS '*****' -- normalized!
14+
ALTER EXTERNAL CONNECTION IF EXISTS ('foo') AS ('*****') -- fully parenthesized
15+
ALTER EXTERNAL CONNECTION IF EXISTS '_' AS '_' -- literals removed
16+
ALTER EXTERNAL CONNECTION IF EXISTS 'foo' AS '*****' -- identifiers removed
17+
ALTER EXTERNAL CONNECTION IF EXISTS 'foo' AS 'bar' -- passwords exposed

0 commit comments

Comments
 (0)