-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
55816: sql: allow parsing of DROP OWNED BY r=otan a=angelapwen Part 1 of addressing #55381. Add parsing and telemetry support for DROP OWNED BY command. Includes small refactors of the related REASSIGN OWNED BY command such as appending "_by" to some instances of "reassign_owned" for readability. Plan to follow up with implementation of DROP OWNED BY for feature parity with PostgresQL, which will resolve the issue linked. Note that this command is also making use of `role_spec_list` which as noted in #54696 does not properly parse `CURRENT_USER` or `SESSION_USER` and uses strings for roles/usernames rather than expressions. This issue is out of scope for this PR and will be resolved separately. Release note: None Co-authored-by: angelapwen <angelaw@cockroachlabs.com>
- Loading branch information
Showing
14 changed files
with
183 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package sql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/server/telemetry" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry" | ||
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" | ||
) | ||
|
||
// dropOwnedByNode represents a DROP OWNED BY <role(s)> statement. | ||
type dropOwnedByNode struct { | ||
// TODO(angelaw): Uncomment when implementing - commenting out due to linting error. | ||
// n *tree.DropOwnedBy | ||
} | ||
|
||
func (p *planner) DropOwnedBy(ctx context.Context) (planNode, error) { | ||
telemetry.Inc(sqltelemetry.CreateDropOwnedByCounter()) | ||
// TODO(angelaw): Implementation. | ||
return nil, unimplemented.NewWithIssue(55381, "drop owned by is not yet implemented") | ||
} | ||
|
||
func (n *dropOwnedByNode) startExec(params runParams) error { | ||
// TODO(angelaw): Implementation. | ||
return nil | ||
} | ||
func (n *dropOwnedByNode) Next(runParams) (bool, error) { return false, nil } | ||
func (n *dropOwnedByNode) Values() tree.Datums { return tree.Datums{} } | ||
func (n *dropOwnedByNode) Close(context.Context) {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package tree | ||
|
||
// DropOwnedBy represents a DROP OWNED BY command. | ||
type DropOwnedBy struct { | ||
Roles []string | ||
DropBehavior DropBehavior | ||
} | ||
|
||
var _ Statement = &DropOwnedBy{} | ||
|
||
// Format implements the NodeFormatter interface. | ||
func (node *DropOwnedBy) Format(ctx *FmtCtx) { | ||
ctx.WriteString("DROP OWNED BY ") | ||
for i := range node.Roles { | ||
if i > 0 { | ||
ctx.WriteString(", ") | ||
} | ||
ctx.FormatNameP(&node.Roles[i]) | ||
} | ||
if node.DropBehavior != DropDefault { | ||
ctx.WriteString(" ") | ||
ctx.WriteString(node.DropBehavior.String()) | ||
} | ||
} |
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,18 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package sqltelemetry | ||
|
||
import "github.com/cockroachdb/cockroach/pkg/server/telemetry" | ||
|
||
// CreateDropOwnedByCounter returns a counter to increment for the DROP OWNED BY command. | ||
func CreateDropOwnedByCounter() telemetry.Counter { | ||
return telemetry.GetCounter("sql.drop_owned_by") | ||
} |
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,19 @@ | ||
# This file contains telemetry tests for the sql.drop_owned_by counter. | ||
|
||
feature-allowlist | ||
sql.drop_owned_by.* | ||
---- | ||
|
||
exec | ||
CREATE ROLE testuser; | ||
CREATE TABLE t(); | ||
GRANT CREATE ON DATABASE defaultdb TO testuser; | ||
ALTER TABLE t OWNER TO testuser | ||
---- | ||
|
||
# TODO(angelaw): Remove unimplemented message after implementation. | ||
feature-usage | ||
DROP OWNED BY testuser | ||
---- | ||
error: pq: unimplemented: drop owned by is not yet implemented | ||
sql.drop_owned_by |
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