Skip to content

Commit

Permalink
sql: fix formatting of import, backup and create tenant
Browse files Browse the repository at this point in the history
Informs: cockroachdb#99185

This commit cherry-picked changes from cockroachdb#107723 and add fixes
for formatting `EXPORT` options.

Release note: None
  • Loading branch information
chengxiong-ruan authored and mgartner committed Aug 28, 2023
1 parent f01f04f commit 88dfbd2
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ func TestBackupAndRestoreJobDescription(t *testing.T) {
sqlDB.Exec(t, "BACKUP TO ($1,$2,$3) INCREMENTAL FROM $4", append(incrementals, backups[0])...)
sqlDB.Exec(t, "BACKUP INTO ($1, $2, $3)", collections...)
sqlDB.Exec(t, "BACKUP INTO LATEST IN ($1, $2, $3)", collections...)
sqlDB.Exec(t, "BACKUP INTO LATEST IN ($1, $2, $3) WITH incremental_location = ($4, $5, $6)",
sqlDB.Exec(t, "BACKUP INTO LATEST IN ($1, $2, $3) WITH OPTIONS (incremental_location = ($4, $5, $6))",
append(collections, incrementals...)...)

sqlDB.ExpectErr(t, "the incremental_location option must contain the same number of locality",
Expand Down
6 changes: 3 additions & 3 deletions pkg/ccl/changefeedccl/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4348,15 +4348,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
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 @@ -418,7 +418,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
2 changes: 1 addition & 1 deletion pkg/sql/importer/import_csv_mark_redaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestMarkRedactionCCLStatement(t *testing.T) {
expected string
}{
{
"IMPORT CSV 'file' WITH delimiter = 'foo'",
"IMPORT CSV 'file' WITH OPTIONS (delimiter = 'foo')",
"IMPORT CSV ‹'file'› WITH OPTIONS (delimiter = ‹'foo'›)",
},
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/importer/import_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,7 @@ func TestImportCSVStmt(t *testing.T) {
`CREATE TABLE t (a int8 primary key, b string, index (b), index (a, b))`,
`IMPORT INTO t CSV DATA (%s) WITH decompress = 'none'`,
testFiles.gzipFiles,
` WITH decompress = 'none'`,
` WITH OPTIONS (decompress = 'none')`,
// This returns different errors for `make test` and `make testrace` but
// field is in both error messages.
`field`,
Expand All @@ -2291,7 +2291,7 @@ func TestImportCSVStmt(t *testing.T) {
`CREATE TABLE t (a int8 primary key, b string, index (b), index (a, b))`,
`IMPORT INTO t CSV DATA (%s) WITH decompress = 'gzip'`,
testFiles.files,
` WITH decompress = 'gzip'`,
` WITH OPTIONS (decompress = 'gzip')`,
"gzip: invalid header",
},
{
Expand Down Expand Up @@ -3123,7 +3123,7 @@ func TestImportIntoCSV(t *testing.T) {
"import-into-no-decompress-gzip",
`IMPORT INTO t (a, b) CSV DATA (%s) WITH decompress = 'none'`,
testFiles.gzipFiles,
` WITH decompress = 'none'`,
` WITH OPTIONS (decompress = 'none')`,
// This returns different errors for `make test` and `make testrace` but
// field is in both error messages.
"field",
Expand All @@ -3132,21 +3132,21 @@ func TestImportIntoCSV(t *testing.T) {
"import-into-no-decompress-gzip",
`IMPORT INTO t (a, b) CSV DATA (%s) WITH decompress = 'gzip'`,
testFiles.files,
` WITH decompress = 'gzip'`,
` WITH OPTIONS (decompress = 'gzip')`,
"gzip: invalid header",
},
{
"import-no-files-match-wildcard",
`IMPORT INTO t (a, b) CSV DATA (%s) WITH decompress = 'auto'`,
[]string{`'nodelocal://0/data-[0-9][0-9]*'`},
` WITH decompress = 'auto'`,
` WITH OPTIONS (decompress = 'auto')`,
`pq: no files matched`,
},
{
"import-into-no-glob-wildcard",
`IMPORT INTO t (a, b) CSV DATA (%s) WITH disable_glob_matching`,
testFiles.filesUsingWildcard,
` WITH disable_glob_matching`,
` WITH OPTIONS (disable_glob_matching)`,
"pq: (.+)no such file or directory: nodelocal storage file does not exist:",
},
} {
Expand Down
16 changes: 12 additions & 4 deletions pkg/sql/parser/testdata/changefeed
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ EXPLAIN CREATE CHANGEFEED FOR TABLE (foo) INTO ('sink') -- fully parenthesized
EXPLAIN CREATE CHANGEFEED FOR TABLE foo INTO '_' -- literals removed
EXPLAIN CREATE CHANGEFEED FOR TABLE _ INTO 'sink' -- identifiers removed

parse
EXPERIMENTAL CHANGEFEED FOR TABLE foo WITH OPTIONS (BUCKET_COUNT = 'string', 'string')
----
EXPERIMENTAL CHANGEFEED FOR TABLE foo WITH OPTIONS (bucket_count = 'string', "string") -- normalized!
EXPERIMENTAL CHANGEFEED FOR TABLE (foo) WITH OPTIONS (bucket_count = ('string'), "string") -- fully parenthesized
EXPERIMENTAL CHANGEFEED FOR TABLE foo WITH OPTIONS (bucket_count = '_', "string") -- literals removed
EXPERIMENTAL CHANGEFEED FOR TABLE _ WITH OPTIONS (_ = 'string', _) -- identifiers removed

parse
CREATE CHANGEFEED FOR foo INTO 'sink'
----
Expand Down Expand Up @@ -62,10 +70,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: 16 additions & 0 deletions pkg/sql/parser/testdata/show
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ SHOW PUBLIC CLUSTER SETTINGS FOR TENANT ($1) -- fully parenthesized
SHOW PUBLIC CLUSTER SETTINGS FOR TENANT $1 -- literals removed
SHOW PUBLIC CLUSTER SETTINGS FOR TENANT $1 -- identifiers removed

parse
SHOW PUBLIC CLUSTER SETTINGS FOR TENANT INTERVAL 'string' DAY TO HOUR
----
SHOW PUBLIC CLUSTER SETTINGS FOR TENANT ('string'::INTERVAL DAY TO HOUR) -- normalized!
SHOW PUBLIC CLUSTER SETTINGS FOR TENANT ((('string')::INTERVAL DAY TO HOUR)) -- fully parenthesized
SHOW PUBLIC CLUSTER SETTINGS FOR TENANT ('_'::INTERVAL DAY TO HOUR) -- literals removed
SHOW PUBLIC CLUSTER SETTINGS FOR TENANT ('string'::INTERVAL DAY TO HOUR) -- identifiers removed

parse
SHOW CLUSTER SETTING a FOR TENANT INTERVAL 'string' MONTH
----
Expand Down Expand Up @@ -978,6 +986,14 @@ SHOW STATISTICS FOR TABLE d.t -- fully parenthesized
SHOW STATISTICS FOR TABLE d.t -- literals removed
SHOW STATISTICS FOR TABLE _._ -- identifiers removed

parse
SHOW STATISTICS FOR TABLE d.t WITH OPTIONS (BUCKET_COUNT, SETTING, 'string', 'string' = LOW)
----
SHOW STATISTICS FOR TABLE d.t WITH OPTIONS (bucket_count, setting, "string", "string" = 'low') -- normalized!
SHOW STATISTICS FOR TABLE d.t WITH OPTIONS (bucket_count, setting, "string", "string" = ('low')) -- fully parenthesized
SHOW STATISTICS FOR TABLE d.t WITH OPTIONS (bucket_count, setting, "string", "string" = '_') -- literals removed
SHOW STATISTICS FOR TABLE _._ WITH OPTIONS (_, _, _, _ = 'low') -- identifiers removed

parse
SHOW HISTOGRAM 123
----
Expand Down
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/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,9 @@ func (node *ShowTableStats) Format(ctx *FmtCtx) {
ctx.WriteString("FOR TABLE ")
ctx.FormatNode(node.Table)
if len(node.Options) > 0 {
ctx.WriteString(" WITH ")
ctx.WriteString(" WITH OPTIONS (")
ctx.FormatNode(&node.Options)
ctx.WriteString(")")
}
}

Expand Down

0 comments on commit 88dfbd2

Please sign in to comment.