forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
131426: tablemetadata: track more job metrics and update job progress while running r=kyle-a-wong a=kyle-a-wong ### tablemetadatacache: update progress of update tmj updates the job progress value of the update table metadata job as it processes batches of tables. The progress will not be updated on every successful batch update, but will instead be updated every nth batch, where n is defined by `batchesPerProgressUpdate`. This is done because each batch executes relatively quickly, and it is unnecessary to provide such granular updates to the progress, each of which results in a write to the database. Part of: cockroachdb#130249 Epic: [CRDB-37558](https://cockroachlabs.atlassian.net/browse/CRDB-37558) Release note: None --- ### tablemetadatacache: add metrics to tmj Adds additional metrics to the update table metadata job: * UpdatedTables - The total number of table rows written to system.table_metadata * Errors - The total number of errors emitted from job runs * Duration - The time spent executing the job Part of: cockroachdb#130249 Epic: [CRDB-37558](https://cockroachlabs.atlassian.net/browse/CRDB-37558) Release note: None 131881: cli: fix double-quote escaping for JSON values with format=sql r=rafiss a=rafiss A previous commit (98f9c8a) made an attempt to fix how JSON values are escaped when they contain invalid UTF8 codes and are displayed in the CLI using the --format=sql flag (see cockroachdb#107518). That commit ended up breaking how JSON values are escaped when they contain double quotes. Luckily it turns out that both problems were actually caused by a long-lived mistake in the `clisqlexec.FormatVal` function. It shouldn't use `fmt.Sprintf("%+q", s)` to escape a string that has invalid characters, as that conflicts with how SQL strings are normally escaped. The proper way is to use `lexbase.EscapeSQLString(s)`. fixes cockroachdb#131257 Release note (bug fix): Fixed a bug where the CLI would not correctly escape JSON values that had double-quotes inside of a string when using the --format=sql flag. Co-authored-by: Kyle Wong <[email protected]> Co-authored-by: Rafi Shamim <[email protected]>
- Loading branch information
Showing
17 changed files
with
412 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the CockroachDB Software License | ||
// included in the /LICENSE file. | ||
|
||
package clisqlexec_test | ||
|
||
import "github.com/cockroachdb/cockroach/pkg/cli" | ||
|
||
func Example_json_sql_format() { | ||
c := cli.NewCLITest(cli.TestCLIParams{}) | ||
defer c.Cleanup() | ||
|
||
testData := []string{ | ||
`e'{"a": "bc"}'`, | ||
`e'{"a": "b\u0099c"}'`, | ||
`e'{"a": "b\\"c"}'`, | ||
`'"there are \"quotes\" in this json string"'`, | ||
`'""'`, | ||
`'{}'`, | ||
} | ||
|
||
for _, s := range testData { | ||
query := `SELECT ` + s + `::json` | ||
c.RunWithArgs([]string{"sql", "--format=sql", "-e", query}) | ||
} | ||
|
||
// Output: | ||
// sql --format=sql -e SELECT e'{"a": "bc"}'::json | ||
// CREATE TABLE results ( | ||
// jsonb STRING | ||
// ); | ||
// | ||
// INSERT INTO results VALUES ('{"a": "bc"}'); | ||
// -- 1 row | ||
// sql --format=sql -e SELECT e'{"a": "b\u0099c"}'::json | ||
// CREATE TABLE results ( | ||
// jsonb STRING | ||
// ); | ||
// | ||
// INSERT INTO results VALUES (e'{"a": "b\\u0099c"}'); | ||
// -- 1 row | ||
// sql --format=sql -e SELECT e'{"a": "b\\"c"}'::json | ||
// CREATE TABLE results ( | ||
// jsonb STRING | ||
// ); | ||
// | ||
// INSERT INTO results VALUES (e'{"a": "b\\"c"}'); | ||
// -- 1 row | ||
// sql --format=sql -e SELECT '"there are \"quotes\" in this json string"'::json | ||
// CREATE TABLE results ( | ||
// jsonb STRING | ||
// ); | ||
// | ||
// INSERT INTO results VALUES (e'"there are \\"quotes\\" in this json string"'); | ||
// -- 1 row | ||
// sql --format=sql -e SELECT '""'::json | ||
// CREATE TABLE results ( | ||
// jsonb STRING | ||
// ); | ||
// | ||
// INSERT INTO results VALUES ('""'); | ||
// -- 1 row | ||
// sql --format=sql -e SELECT '{}'::json | ||
// CREATE TABLE results ( | ||
// jsonb STRING | ||
// ); | ||
// | ||
// INSERT INTO results VALUES ('{}'); | ||
// -- 1 row | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.