Skip to content

Commit

Permalink
Merge pull request cockroachdb#108314 from annrpom/backport23.1-107892
Browse files Browse the repository at this point in the history
release-23.1: sql: fix formatting of export and changefeed
  • Loading branch information
annrpom authored Aug 9, 2023
2 parents 779bf47 + 7ed0bda commit 0e8ff82
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 25 deletions.
6 changes: 3 additions & 3 deletions pkg/ccl/changefeedccl/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5155,15 +5155,15 @@ func TestChangefeedDescription(t *testing.T) {
}{
{
create: "CREATE CHANGEFEED FOR foo INTO $1 WITH updated, envelope = $2",
descr: `CREATE CHANGEFEED FOR TABLE foo INTO '` + redactedSink + `' WITH envelope = 'wrapped', updated`,
descr: `CREATE CHANGEFEED FOR TABLE foo INTO '` + redactedSink + `' WITH OPTIONS (envelope = 'wrapped', updated)`,
},
{
create: "CREATE CHANGEFEED FOR public.foo INTO $1 WITH updated, envelope = $2",
descr: `CREATE CHANGEFEED FOR TABLE public.foo INTO '` + redactedSink + `' WITH envelope = 'wrapped', updated`,
descr: `CREATE CHANGEFEED FOR TABLE public.foo INTO '` + redactedSink + `' WITH OPTIONS (envelope = 'wrapped', updated)`,
},
{
create: "CREATE CHANGEFEED FOR d.public.foo INTO $1 WITH updated, envelope = $2",
descr: `CREATE CHANGEFEED FOR TABLE d.public.foo INTO '` + redactedSink + `' WITH envelope = 'wrapped', updated`,
descr: `CREATE CHANGEFEED FOR TABLE d.public.foo INTO '` + redactedSink + `' WITH OPTIONS (envelope = 'wrapped', updated)`,
},
{
// TODO(#85143): remove schema_change_policy='stop' from this test.
Expand Down
10 changes: 5 additions & 5 deletions pkg/ccl/changefeedccl/scheduled_changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func TestSerializesScheduledChangefeedExecutionArgs(t *testing.T) {
query: "CREATE SCHEDULE FOR CHANGEFEED d.public.foo INTO 'webhook-https://0/changefeed?AWS_SECRET_ACCESS_KEY=nevershown' WITH initial_scan='only' RECURRING '@hourly'",
es: expectedSchedule{
nameRe: "CHANGEFEED .+",
changefeedStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed?AWS_SECRET_ACCESS_KEY=nevershown' WITH initial_scan = 'only'",
shownStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed?AWS_SECRET_ACCESS_KEY=redacted' WITH initial_scan = 'only'",
changefeedStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed?AWS_SECRET_ACCESS_KEY=nevershown' WITH OPTIONS (initial_scan = 'only')",
shownStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed?AWS_SECRET_ACCESS_KEY=redacted' WITH OPTIONS (initial_scan = 'only')",
period: time.Hour,
},
},
Expand All @@ -204,7 +204,7 @@ func TestSerializesScheduledChangefeedExecutionArgs(t *testing.T) {
query: "CREATE SCHEDULE FOR CHANGEFEED foo INTO 'webhook-https://0/changefeed' WITH initial_scan = 'only' RECURRING '@hourly'",
es: expectedSchedule{
nameRe: "CHANGEFEED .+",
changefeedStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed' WITH initial_scan = 'only'",
changefeedStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed' WITH OPTIONS (initial_scan = 'only')",
period: time.Hour,
},
},
Expand All @@ -220,8 +220,8 @@ func TestSerializesScheduledChangefeedExecutionArgs(t *testing.T) {
queryArgs: []interface{}{th.env.Now()},
es: expectedSchedule{
nameRe: "foo-changefeed",
changefeedStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed?AWS_SECRET_ACCESS_KEY=nevershown' WITH format = 'JSON', initial_scan = 'only'",
shownStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed?AWS_SECRET_ACCESS_KEY=redacted' WITH format = 'JSON', initial_scan = 'only'",
changefeedStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed?AWS_SECRET_ACCESS_KEY=nevershown' WITH OPTIONS (format = 'JSON', initial_scan = 'only')",
shownStmt: "CREATE CHANGEFEED FOR TABLE d.public.foo INTO 'webhook-https://0/changefeed?AWS_SECRET_ACCESS_KEY=redacted' WITH OPTIONS (format = 'JSON', initial_scan = 'only')",
period: time.Hour,
runsNow: true,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/changefeedccl/show_changefeed_jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func TestShowChangefeedJobsAlterChangefeed(t *testing.T) {
out = obtainJobRowFn()

require.Equal(t, jobID, out.id, "Expected id:%d but found id:%d", jobID, out.id)
require.Equal(t, "CREATE CHANGEFEED FOR TABLE d.public.bar INTO 'kafka://does.not.matter/' WITH resolved = '5s'", out.description, "Expected description:%s but found description:%s", "CREATE CHANGEFEED FOR TABLE bar INTO 'kafka://does.not.matter/ WITH resolved = '5s''", out.description)
require.Equal(t, "CREATE CHANGEFEED FOR TABLE d.public.bar INTO 'kafka://does.not.matter/' WITH OPTIONS (resolved = '5s')", out.description, "Expected description:%s but found description:%s", "CREATE CHANGEFEED FOR TABLE bar INTO 'kafka://does.not.matter/ WITH resolved = '5s''", out.description)
require.Equal(t, sinkURI, out.SinkURI, "Expected sinkUri:%s but found sinkUri:%s", sinkURI, out.SinkURI)
require.Equal(t, "bar", out.topics, "Expected topics:%s but found topics:%s", "bar", sortedTopics)
require.Equal(t, "{d.public.bar}", string(out.FullTableNames), "Expected fullTableNames:%s but found fullTableNames:%s", "{d.public.bar}", string(out.FullTableNames))
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/logictestccl/testdata/logic_test/changefeed
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ SELECT job_id FROM [SHOW CHANGEFEED JOBS] WHERE user_name = 'testuser'
query TT
SELECT user_name, description FROM [SHOW CHANGEFEED JOB $job_id]
----
testuser CREATE CHANGEFEED FOR TABLE t INTO 'null://sink' WITH initial_scan = 'only'
testuser CREATE CHANGEFEED FOR TABLE t INTO 'null://sink' WITH OPTIONS (initial_scan = 'only')

query TT
SELECT user_name, description FROM [SHOW CHANGEFEED JOBS]
----
testuser CREATE CHANGEFEED FOR TABLE t INTO 'null://sink' WITH initial_scan = 'only'
testuser CREATE CHANGEFEED FOR TABLE t INTO 'null://sink' WITH OPTIONS (initial_scan = 'only')
8 changes: 4 additions & 4 deletions pkg/sql/parser/testdata/changefeed
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ CREATE CHANGEFEED FOR TABLE _ INTO 'sink' -- identifiers removed
parse
CREATE CHANGEFEED FOR TABLE foo INTO 'sink' WITH bar = 'baz'
----
CREATE CHANGEFEED FOR TABLE foo INTO 'sink' WITH bar = 'baz'
CREATE CHANGEFEED FOR TABLE (foo) INTO ('sink') WITH bar = ('baz') -- fully parenthesized
CREATE CHANGEFEED FOR TABLE foo INTO '_' WITH bar = '_' -- literals removed
CREATE CHANGEFEED FOR TABLE _ INTO 'sink' WITH _ = 'baz' -- identifiers removed
CREATE CHANGEFEED FOR TABLE foo INTO 'sink' WITH OPTIONS (bar = 'baz') -- normalized!
CREATE CHANGEFEED FOR TABLE (foo) INTO ('sink') WITH OPTIONS (bar = ('baz')) -- fully parenthesized
CREATE CHANGEFEED FOR TABLE foo INTO '_' WITH OPTIONS (bar = '_') -- literals removed
CREATE CHANGEFEED FOR TABLE _ INTO 'sink' WITH OPTIONS (_ = 'baz') -- identifiers removed

parse
CREATE CHANGEFEED AS SELECT * FROM foo
Expand Down
16 changes: 8 additions & 8 deletions pkg/sql/parser/testdata/import_export
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ EXPORT INTO CSV 'a' FROM SELECT * FROM _ -- identifiers removed
parse
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH delimiter = '|' FROM TABLE a
----
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH delimiter = '|' FROM TABLE a
EXPORT INTO CSV ('s3://my/path/%part%.csv') WITH delimiter = ('|') FROM TABLE a -- fully parenthesized
EXPORT INTO CSV '_' WITH delimiter = '_' FROM TABLE a -- literals removed
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH _ = '|' FROM TABLE _ -- identifiers removed
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH OPTIONS(delimiter = '|') FROM TABLE a -- normalized!
EXPORT INTO CSV ('s3://my/path/%part%.csv') WITH OPTIONS(delimiter = ('|')) FROM TABLE a -- fully parenthesized
EXPORT INTO CSV '_' WITH OPTIONS(delimiter = '_') FROM TABLE a -- literals removed
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH OPTIONS(_ = '|') FROM TABLE _ -- identifiers removed

parse
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH delimiter = '|' FROM SELECT a, sum(b) FROM c WHERE d = 1 ORDER BY sum(b) DESC LIMIT 10
----
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH delimiter = '|' FROM SELECT a, sum(b) FROM c WHERE d = 1 ORDER BY sum(b) DESC LIMIT 10
EXPORT INTO CSV ('s3://my/path/%part%.csv') WITH delimiter = ('|') FROM SELECT (a), (sum((b))) FROM c WHERE ((d) = (1)) ORDER BY (sum((b))) DESC LIMIT (10) -- fully parenthesized
EXPORT INTO CSV '_' WITH delimiter = '_' FROM SELECT a, sum(b) FROM c WHERE d = _ ORDER BY sum(b) DESC LIMIT _ -- literals removed
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH _ = '|' FROM SELECT _, sum(_) FROM _ WHERE _ = 1 ORDER BY sum(_) DESC LIMIT 10 -- identifiers removed
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH OPTIONS(delimiter = '|') FROM SELECT a, sum(b) FROM c WHERE d = 1 ORDER BY sum(b) DESC LIMIT 10 -- normalized!
EXPORT INTO CSV ('s3://my/path/%part%.csv') WITH OPTIONS(delimiter = ('|')) FROM SELECT (a), (sum((b))) FROM c WHERE ((d) = (1)) ORDER BY (sum((b))) DESC LIMIT (10) -- fully parenthesized
EXPORT INTO CSV '_' WITH OPTIONS(delimiter = '_') FROM SELECT a, sum(b) FROM c WHERE d = _ ORDER BY sum(b) DESC LIMIT _ -- literals removed
EXPORT INTO CSV 's3://my/path/%part%.csv' WITH OPTIONS(_ = '|') FROM SELECT _, sum(_) FROM _ WHERE _ = 1 ORDER BY sum(_) DESC LIMIT 10 -- identifiers removed
3 changes: 2 additions & 1 deletion pkg/sql/sem/tree/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ func (node *CreateChangefeed) Format(ctx *FmtCtx) {
ctx.FormatNode(node.SinkURI)
}
if node.Options != nil {
ctx.WriteString(" WITH ")
ctx.WriteString(" WITH OPTIONS (")
ctx.FormatNode(&node.Options)
ctx.WriteString(")")
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/sem/tree/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func (node *Export) Format(ctx *FmtCtx) {
ctx.WriteString(" ")
ctx.FormatNode(node.File)
if node.Options != nil {
ctx.WriteString(" WITH ")
ctx.WriteString(" WITH OPTIONS(")
ctx.FormatNode(&node.Options)
ctx.WriteString(")")
}
ctx.WriteString(" FROM ")
ctx.FormatNode(node.Query)
Expand Down

0 comments on commit 0e8ff82

Please sign in to comment.