Skip to content

Commit

Permalink
sql: make the output columns of SHOW TENANT lowercase
Browse files Browse the repository at this point in the history
All the SHOW statements report status-like data in lowercase.
SHOW TENANT(s) should not be different.

Release note: None
  • Loading branch information
knz committed Jan 21, 2023
1 parent f7ff204 commit b2b2fac
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ func TestTenantStreamingShowTenant(t *testing.T) {
require.Equal(t, "destination", rowStr[0][1])
if rowStr[0][3] == "NULL" {
// There is no source yet, therefore the replication is not fully initialized.
require.Equal(t, "INITIALIZING REPLICATION", rowStr[0][2])
require.Equal(t, "initializing replication", rowStr[0][2])
}

jobutils.WaitForJobToRun(c.T, c.SrcSysSQL, jobspb.JobID(producerJobID))
Expand Down Expand Up @@ -937,8 +937,8 @@ func TestTenantStreamingShowTenant(t *testing.T) {
row.Scan(&id, &dest, &status, &serviceMode, &source, &sourceUri, &jobId, &maxReplTime, &protectedTime, &cutoverTime)
require.Equal(t, 2, id)
require.Equal(t, "destination", dest)
require.Equal(t, "REPLICATING", status)
require.Equal(t, "NONE", serviceMode)
require.Equal(t, "replicating", status)
require.Equal(t, "none", serviceMode)
require.Equal(t, "source", source)
require.Equal(t, c.SrcURL.String(), sourceUri)
require.Equal(t, ingestionJobID, jobId)
Expand Down
8 changes: 4 additions & 4 deletions pkg/ccl/streamingccl/streamingest/testdata/simple
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ IMPORT INTO d.x CSV DATA ('userfile:///dx/export*-n*.0.csv');
query-sql as=source-system
SHOW TENANTS
----
1 system READY EXTERNAL
10 source READY NONE
1 system ready external
10 source ready none

query-sql as=destination-system
SHOW TENANTS
----
1 system READY EXTERNAL
2 destination REPLICATING NONE
1 system ready external
2 destination replicating none

let $ts as=source-system
SELECT clock_timestamp()::timestamp::string
Expand Down
38 changes: 19 additions & 19 deletions pkg/sql/logictest/testdata/logic_test/tenant
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,40 @@ query ITTT colnames
SHOW TENANT system
----
id name data_status service_mode
1 system READY EXTERNAL
1 system ready external

query ITTT colnames
SHOW TENANT "tenant-one"
----
id name data_status service_mode
2 tenant-one READY NONE
2 tenant-one ready none

query ITTT colnames
SHOW TENANT "two"
----
id name data_status service_mode
3 two READY NONE
3 two ready none

query ITTT colnames
SHOW TENANT two
----
id name data_status service_mode
3 two READY NONE
3 two ready none

query ITTT colnames
SHOW TENANT three
----
id name data_status service_mode
4 three READY NONE
4 three ready none

query ITTT colnames
SHOW TENANTS
----
id name data_status service_mode
1 system READY EXTERNAL
2 tenant-one READY NONE
3 two READY NONE
4 three READY NONE
1 system ready external
2 tenant-one ready none
3 two ready none
4 three ready none

statement error tenant name cannot be empty
ALTER TENANT [4] RENAME TO ""
Expand All @@ -101,7 +101,7 @@ query ITTT colnames
SELECT * FROM [SHOW TENANTS] WHERE id = 4
----
id name data_status service_mode
4 blix READY NONE
4 blix ready none

statement ok
ALTER TENANT blix RENAME TO three
Expand All @@ -110,7 +110,7 @@ query ITTT colnames
SELECT * FROM [SHOW TENANTS] WHERE id = 4
----
id name data_status service_mode
4 three READY NONE
4 three ready none

statement error tenant "seven" does not exist
SHOW TENANT seven
Expand Down Expand Up @@ -251,11 +251,11 @@ query ITTT colnames
SHOW TENANTS
----
id name data_status service_mode
1 system READY EXTERNAL
2 tenant-one READY NONE
3 two READY NONE
4 three READY NONE
8 to-be-reclaimed READY NONE
9 1 READY NONE
10 a-b READY NONE
11 hello-100 READY NONE
1 system ready external
2 tenant-one ready none
3 two ready none
4 three ready none
8 to-be-reclaimed ready none
9 1 ready none
10 a-b ready none
11 hello-100 ready none
21 changes: 12 additions & 9 deletions pkg/sql/show_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package sql
import (
"context"
"fmt"
"strings"
"time"

"github.com/cockroachdb/cockroach/pkg/jobs"
Expand All @@ -31,12 +32,12 @@ import (
type tenantStatus string

const (
initReplication tenantStatus = "INITIALIZING REPLICATION"
replicating tenantStatus = "REPLICATING"
replicationPaused tenantStatus = "REPLICATION PAUSED"
cuttingOver tenantStatus = "REPLICATION CUTTING OVER"
initReplication tenantStatus = "initializing replication"
replicating tenantStatus = "replicating"
replicationPaused tenantStatus = "replication paused"
cuttingOver tenantStatus = "replication cutting over"
// Users should not see this status normally.
replicationUnknownFormat tenantStatus = "REPLICATION UNKNOWN (%s)"
replicationUnknownFormat tenantStatus = "replication unknown (%s)"
)

type tenantValues struct {
Expand Down Expand Up @@ -176,7 +177,8 @@ func (n *showTenantNode) getTenantValues(
if n.withReplication {
return nil, errors.Newf("tenant %q does not have an active replication job", tenantInfo.Name)
}
values.tenantStatus = tenantStatus(values.tenantInfo.DataState.String())
dataState := strings.ToLower(values.tenantInfo.DataState.String())
values.tenantStatus = tenantStatus(dataState)
return &values, nil
}

Expand Down Expand Up @@ -206,9 +208,10 @@ func (n *showTenantNode) getTenantValues(

values.tenantStatus = getTenantStatus(job.Status(), values.replicationInfo)
case descpb.TenantInfo_READY, descpb.TenantInfo_DROP:
values.tenantStatus = tenantStatus(values.tenantInfo.DataState.String())
dataState := strings.ToLower(values.tenantInfo.DataState.String())
values.tenantStatus = tenantStatus(dataState)
default:
return nil, errors.Newf("tenant %q state is unknown: %s", tenantInfo.Name, values.tenantInfo.DataState.String())
return nil, errors.Newf("tenant %q state is unknown: %s", tenantInfo.Name, values.tenantInfo.DataState)
}
return &values, nil
}
Expand Down Expand Up @@ -239,7 +242,7 @@ func (n *showTenantNode) Values() tree.Datums {
tree.NewDInt(tree.DInt(tenantInfo.ID)),
tree.NewDString(string(tenantInfo.Name)),
tree.NewDString(string(v.tenantStatus)),
tree.NewDString(tenantInfo.ServiceMode.String()),
tree.NewDString(strings.ToLower(tenantInfo.ServiceMode.String())),
}

if n.withReplication {
Expand Down

0 comments on commit b2b2fac

Please sign in to comment.