Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
55831: sql - Implement SHOW REGIONS r=otan a=ajstorm

Previously, SHOW REGIONS was an unimplemented stub.  This
PR implements the SHOW REGIONS such that when issued, it
shows all of the regions available to the cluster.

Release note (sql change): Implement SHOW REGIONS so that
customers can easily see all of the regions available in their cluster.

example:

SHOW REGIONS

    region
---------------
  asia-east
  europe-east
  us-central
  us-east
  us-west
(5 rows)

Co-authored-by: Adam Storm <[email protected]>
  • Loading branch information
craig[bot] and ajstorm committed Oct 23, 2020
2 parents 4702643 + 99d6ed7 commit fe574bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pkg/sql/delegate/show_regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ package delegate
import (
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
)

// delegateShowRanges implements the SHOW REGIONS statement.
func (d *delegator) delegateShowRegions(n *tree.ShowRegions) (tree.Statement, error) {
sqltelemetry.IncrementShowCounter(sqltelemetry.Regions)
return nil, unimplemented.New("show regions", "implementation pending")
query := `SELECT
substring (locality, 'region=([^,]*)') AS region,
array_agg(COALESCE (substring (locality, 'az=([^,]*)'),
substring (locality, 'availability-zone=([^,]*)'))) AS availability_zones
FROM crdb_internal.gossip_nodes
group by region ORDER BY region`

return parse(query)
}
7 changes: 6 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ ALTER DATABASE new_db ADD REGION "us-west-1"
statement error implementation pending
ALTER DATABASE new_db DROP REGION "us-west-1"

statement error implementation pending
query TT colnames
SHOW REGIONS
----
region availability_zones
test1 {test1-az1,test1-az2,test1-az3}
test2 {test2-az1,test2-az2,test2-az3}
test3 {test3-az1,test3-az2,test3-az3}

0 comments on commit fe574bf

Please sign in to comment.