Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
96562: cli/sql: assorted CLI shell and autocompletion bug fixes r=ZhouXing19 a=knz

See the individual commits for details.

Epic: None

96660: sql: fix column_default in info_schema so literals are quoted r=e-mbrown a=rafiss

fixes #96098

In bc3fccd, the format flags were changed to use FmtPgWireText for
information_schema.columns(column_default). This does not work for string literals, since that format does not wrap literals in single quotes.

Now we've changed to FmtParsableNumerics, which does properly add quotes, and also avoids adding the `:::` type annotation as FmtPgWireText does.

No release note since this bug was never released.

Release note: None

96668: allocator: fix panic when accessing nil store descriptor r=kvoli a=aliher1911

Previously allocator was trying to update store descriptor counters on unitialized stores. Instead of checking if detail is nil which should never happen, it should check if descriptor in detail is not nil as it is only eventually populated by gossip.

Release note: None

Fixes #96654

Co-authored-by: Raphael 'kena' Poss <[email protected]>
Co-authored-by: Rafi Shamim <[email protected]>
Co-authored-by: Oleg Afanasyev <[email protected]>
  • Loading branch information
4 people committed Feb 6, 2023
4 parents c9dde80 + 30fd1b0 + ea3342d + 750f930 commit a0f8d9b
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 111 deletions.
12 changes: 6 additions & 6 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5123,20 +5123,20 @@ def go_deps():
name = "com_github_knz_bubbline",
build_file_proto_mode = "disable_global",
importpath = "github.com/knz/bubbline",
sha256 = "0da0560f0116618e6e8762810ffa3fb3f2373e2478bebac6e977ed9c23f7611e",
strip_prefix = "github.com/knz/[email protected]20230124184034-a0b62576595b",
sha256 = "0922c6fae4190a73e2023b1a56401347e29afddf1174990b8fd881433b9c75a9",
strip_prefix = "github.com/knz/[email protected]20230205122847-05558f88fdc4",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/bubbline/com_github_knz_bubbline-v0.0.0-20230124184034-a0b62576595b.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/bubbline/com_github_knz_bubbline-v0.0.0-20230205122847-05558f88fdc4.zip",
],
)
go_repository(
name = "com_github_knz_catwalk",
build_file_proto_mode = "disable_global",
importpath = "github.com/knz/catwalk",
sha256 = "7b44ddd491c68b186426e5f98fcb9410c4d26a5c4fa82205b3ff2797ffc3b51b",
strip_prefix = "github.com/knz/[email protected].2",
sha256 = "f422f7974090494e54226262586c7b34fe57b33ab7d668151ca55eba8e309c1e",
strip_prefix = "github.com/knz/[email protected].4",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/catwalk/com_github_knz_catwalk-v0.1.2.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/catwalk/com_github_knz_catwalk-v0.1.4.zip",
],
)
go_repository(
Expand Down
4 changes: 2 additions & 2 deletions build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/klauspost/cpuid/v2/com_github_klauspost_cpuid_v2-v2.0.9.zip": "52c716413296dce2b1698c6cdbc4c53927ce4aee2a60980daf9672e6b6a3b4cb",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/klauspost/crc32/com_github_klauspost_crc32-v0.0.0-20161016154125-cb6bfca970f6.zip": "6b632853a19f039138f251f94dbbdfdb72809adc3a02da08e4301d3d48275b06",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/klauspost/pgzip/com_github_klauspost_pgzip-v1.2.5.zip": "1143b6417d4bb46d26dc8e6223407b84b6cd5f32e5d705cd4a9fb142220ce4ba",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/bubbline/com_github_knz_bubbline-v0.0.0-20230124184034-a0b62576595b.zip": "0da0560f0116618e6e8762810ffa3fb3f2373e2478bebac6e977ed9c23f7611e",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/catwalk/com_github_knz_catwalk-v0.1.2.zip": "7b44ddd491c68b186426e5f98fcb9410c4d26a5c4fa82205b3ff2797ffc3b51b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/bubbline/com_github_knz_bubbline-v0.0.0-20230205122847-05558f88fdc4.zip": "0922c6fae4190a73e2023b1a56401347e29afddf1174990b8fd881433b9c75a9",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/catwalk/com_github_knz_catwalk-v0.1.4.zip": "f422f7974090494e54226262586c7b34fe57b33ab7d668151ca55eba8e309c1e",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/lipgloss-convert/com_github_knz_lipgloss_convert-v0.1.0.zip": "f9f9ffa12e7df4007cc60c87327d47ad42d1f71a80e360af4014674138de8bef",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/knz/strtime/com_github_knz_strtime-v0.0.0-20200318182718-be999391ffa9.zip": "c1e1b06c339798387413af1444f06f31a483d4f5278ab3a91b6cd5d7cd8d91a1",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/konsorten/go-windows-terminal-sequences/com_github_konsorten_go_windows_terminal_sequences-v1.0.3.zip": "429b01413b972b108ea86bbde3d5e660913f3e8099190d07ccfb2f186bc6d837",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ require (
github.com/kisielk/gotool v1.0.0
github.com/klauspost/compress v1.15.11
github.com/klauspost/pgzip v1.2.5
github.com/knz/bubbline v0.0.0-20230124184034-a0b62576595b
github.com/knz/bubbline v0.0.0-20230205122847-05558f88fdc4
github.com/knz/go-libedit v1.10.1
github.com/knz/strtime v0.0.0-20200318182718-be999391ffa9
github.com/kr/pretty v0.3.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1475,10 +1475,10 @@ github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH6
github.com/klauspost/pgzip v1.2.4/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/knz/bubbline v0.0.0-20230124184034-a0b62576595b h1:WkDRZUJ4jwXPpiwaprlozeoL2nULKk2BUW+7cc8MYLg=
github.com/knz/bubbline v0.0.0-20230124184034-a0b62576595b/go.mod h1:6A+ujZMesdx26uaMRz53ka0gtDTytz5+LXMxJefmUY0=
github.com/knz/catwalk v0.1.2 h1:sNLvF6WOXdvedeiCpqkpsHSGavOYxZwDsgdbKiu1IOc=
github.com/knz/catwalk v0.1.2/go.mod h1:Q+Yj4ny4AXgrOOyWyDGY/HJzmbGH8MFnsUqvCAiUT5s=
github.com/knz/bubbline v0.0.0-20230205122847-05558f88fdc4 h1:WT5NrWC3UParTXCijOl/PyfgZ9HhxCa2lAFfvxDxcIY=
github.com/knz/bubbline v0.0.0-20230205122847-05558f88fdc4/go.mod h1:ucXvyrucVy4jp/4afdKWNW1TVO73GMI72VNINzyT678=
github.com/knz/catwalk v0.1.4 h1:GgCxHbPp+nzyZBJcNL/CJd1aba4ACoeuI1lnsshAPkY=
github.com/knz/catwalk v0.1.4/go.mod h1:Q+Yj4ny4AXgrOOyWyDGY/HJzmbGH8MFnsUqvCAiUT5s=
github.com/knz/lipgloss-convert v0.1.0 h1:qUPUt6r8mqvi9DIV3nBPu3kEmFyHrZtXzv0BlPBPLNQ=
github.com/knz/lipgloss-convert v0.1.0/go.mod h1:S14GmtoiW/VAHqB7xEzuZOt0/G6GQ2dfjJN0fHpm30Q=
github.com/knz/strtime v0.0.0-20200318182718-be999391ffa9 h1:GQE1iatYDRrIidq4Zf/9ZzKWyrTk2sXOYc1JADbkAjQ=
Expand Down
9 changes: 9 additions & 0 deletions pkg/cli/clisqlshell/testdata/complete/composite_names
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ select "PG_CATALOG".@
complete 0 20
msg: ""
(no completions generated)

complete
select information_schema . _pg_index@
----
complete 0 37
msg: ""
completions:
- "functions":
"information_schema._pg_index_position(" (Not usable; exposed only for compatibility with PostgreSQL) -> "information_schema._pg_index_position(" (0, 30)
26 changes: 25 additions & 1 deletion pkg/cli/clisqlshell/testdata/complete/sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ completions:
"\"extract_duration\"(" ((from schema pg_catalog) Extracts `element` from `input`) -> "\"extract_duration\"(" (0, 0)
"\"family\"(" ((from schema pg_catalog) Extracts the IP family of the value; 4 for IPv4, 6 for IPv6) -> "\"family\"(" (0, 0)
"\"greatest\"(" ((from schema pg_catalog) Returns the element with the greatest value) -> "\"greatest\"(" (0, 0)
"\"information_schema._pg_char_max_length\"(" ((from schema pg_catalog) Not usable; exposed only for compatibility with PostgreSQL) -> "\"information_schema._pg_char_max_length\"(" (0, 0)
"\"least\"(" ((from schema pg_catalog) Returns the element with the lowest value) -> "\"least\"(" (0, 0)
... entries omitted ...
- "keyword":
"ABORT" (unreserved) -> "ABORT" (0, 0)
Expand All @@ -33,6 +33,10 @@ completions:
"ALL" (reserved) -> "ALL" (0, 0)
"ALTER" (unreserved) -> "ALTER" (0, 0)
... entries omitted ...
- "relation":
"geography_columns" (Shows all defined geography columns. Matches PostGIS' geography_columns function) -> "geography_columns" (0, 0)
"geometry_columns" (Shows all defined geometry columns. Matches PostGIS' geometry_columns functional) -> "geometry_columns" (0, 0)
"spatial_ref_sys" (Shows all defined Spatial Reference Identifiers (SRIDs). Matches PostGIS' spatia) -> "spatial_ref_sys" (0, 0)
- "schema":
"crdb_internal" () -> "crdb_internal" (0, 0)
"information_schema" () -> "information_schema" (0, 0)
Expand Down Expand Up @@ -112,3 +116,23 @@ completions:
- "functions":
"array_length(" ((from schema pg_catalog) Calculates the length of `input` on the provided `array_dimension`) -> "array_length(" (0, 7)
"array_lower(" ((from schema pg_catalog) Calculates the minimum value of `input` on the provided `array_dimension`) -> "array_lower(" (0, 7)

# Complete pg_catalog tables after a pg_catalog prefix.
complete
select * from pg_catalog.pg_pro@
----
complete 0 31
msg: ""
completions:
- "relation":
"pg_proc" (built-in functions (incomplete)) -> "pg_proc" (0, 6)

# Complete pg_catalog tables if the user has typed pg_ already.
complete
select * from pg_pro@
----
complete 0 20
msg: ""
completions:
- "relation":
"pg_proc" (built-in functions (incomplete)) -> "pg_proc" (0, 6)
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/allocator/storepool/store_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,14 @@ func (sp *StorePool) UpdateLocalStoreAfterRelocate(

updateTargets := func(targets []roachpb.ReplicationTarget) {
for _, target := range targets {
if toDetail := sp.GetStoreDetailLocked(target.StoreID); toDetail != nil {
if toDetail := sp.GetStoreDetailLocked(target.StoreID); toDetail.Desc != nil {
toDetail.Desc.Capacity.RangeCount++
}
}
}
updatePrevious := func(previous []roachpb.ReplicaDescriptor) {
for _, old := range previous {
if toDetail := sp.GetStoreDetailLocked(old.StoreID); toDetail != nil {
if toDetail := sp.GetStoreDetailLocked(old.StoreID); toDetail.Desc != nil {
toDetail.Desc.Capacity.RangeCount--
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ func TestAdminAPITableDetails(t *testing.T) {
name, dbName, tblName, pkName string
}{
{name: "lower", dbName: "test", tblName: "tbl", pkName: "tbl_pkey"},
{name: "lower", dbName: "test", tblName: `testschema.tbl`, pkName: "tbl_pkey"},
{name: "lower other schema", dbName: "test", tblName: `testschema.tbl`, pkName: "tbl_pkey"},
{name: "lower with space", dbName: "test test", tblName: `"tbl tbl"`, pkName: "tbl tbl_pkey"},
{name: "upper", dbName: "TEST", tblName: `"TBL"`, pkName: "TBL_pkey"}, // Regression test for issue #14056
} {
Expand Down Expand Up @@ -778,7 +778,7 @@ func TestAdminAPITableDetails(t *testing.T) {
{Name: "nulls_allowed", Type: "INT8", Nullable: true, DefaultValue: ""},
{Name: "nulls_not_allowed", Type: "INT8", Nullable: false, DefaultValue: "1000"},
{Name: "default2", Type: "INT8", Nullable: true, DefaultValue: "2"},
{Name: "string_default", Type: "STRING", Nullable: true, DefaultValue: "default_string"},
{Name: "string_default", Type: "STRING", Nullable: true, DefaultValue: "'default_string'"},
{Name: "rowid", Type: "INT8", Nullable: false, DefaultValue: "unique_rowid()", Hidden: true},
}
testutils.SortStructs(expColumns, "Name")
Expand Down
8 changes: 5 additions & 3 deletions pkg/sql/compengine/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ type Context interface {
// returned.
RelToken(pos int) scanner.InspectToken

// AtWord is equivalent to .RelMarker(0) == MarkIdentOrKeyword,
// and is provided for convenience.
AtWord() bool
// AtWordOrInSpaceFollowingWord is equivalent to .RelMarker(0) ==
// MarkIdentOrKeyword, and is provided for convenience. This returns
// true both when the cursor is _on_ an identifier/keyword, or _at
// any whitespace position afterwards_.
AtWordOrInSpaceFollowingWord() bool

// Query perform a SQL query.
Query(ctx context.Context, query string, args ...interface{}) (Rows, error)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/compengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ func (c *completions) RelToken(idx int) scanner.InspectToken {
return c.tokens[off]
}

// AtWord implements the Context interface.
func (c *completions) AtWord() bool {
// AtWordOrInSpaceFollowingWord implements the Context interface.
func (c *completions) AtWordOrInSpaceFollowingWord() bool {
return c.RelMarker(0) == MarkIdentOrKeyword
}

Expand Down
Loading

0 comments on commit a0f8d9b

Please sign in to comment.