diff --git a/pkg/sql/delegate/BUILD.bazel b/pkg/sql/delegate/BUILD.bazel index 6fea5a16e127..784079de690a 100644 --- a/pkg/sql/delegate/BUILD.bazel +++ b/pkg/sql/delegate/BUILD.bazel @@ -14,6 +14,7 @@ go_library( "show_default_privileges.go", "show_enums.go", "show_full_table_scans.go", + "show_function.go", "show_grants.go", "show_jobs.go", "show_partitions.go", diff --git a/pkg/sql/delegate/delegate.go b/pkg/sql/delegate/delegate.go index 6734984cb6ce..cfdb5fe95da4 100644 --- a/pkg/sql/delegate/delegate.go +++ b/pkg/sql/delegate/delegate.go @@ -58,6 +58,9 @@ func TryDelegate( case *tree.ShowCreate: return d.delegateShowCreate(t) + case *tree.ShowCreateFunction: + return d.delegateShowCreateFunction(t) + case *tree.ShowCreateAllSchemas: return d.delegateShowCreateAllSchemas() diff --git a/pkg/sql/delegate/show_function.go b/pkg/sql/delegate/show_function.go new file mode 100644 index 000000000000..7fc125eba8a3 --- /dev/null +++ b/pkg/sql/delegate/show_function.go @@ -0,0 +1,20 @@ +// Copyright 2022 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 delegate + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" + "github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" +) + +func (d *delegator) delegateShowCreateFunction(n *tree.ShowCreateFunction) (tree.Statement, error) { + return nil, unimplemented.New("SHOW CREATE FUNCTION", "this statement is not yet supported") +} diff --git a/pkg/sql/logictest/testdata/logic_test/show_create b/pkg/sql/logictest/testdata/logic_test/show_create index 0e4d21073240..4c2c1bc44b52 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_create +++ b/pkg/sql/logictest/testdata/logic_test/show_create @@ -140,3 +140,8 @@ CREATE TABLE public.t ( CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) ); COMMENT ON COLUMN public.t.c IS 'first comment' + +subtest show_create_function + +statement error this statement is not yet supported +SHOW CREATE FUNCTION lower diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index be076bb675e8..64636eea28dd 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -5679,8 +5679,9 @@ zone_value: // %Category: Group // %Text: // SHOW BACKUP, SHOW CLUSTER SETTING, SHOW COLUMNS, SHOW CONSTRAINTS, -// SHOW CREATE, SHOW CREATE SCHEDULES, SHOW DATABASES, SHOW ENUMS, SHOW HISTOGRAM, SHOW INDEXES, SHOW -// PARTITIONS, SHOW JOBS, SHOW STATEMENTS, SHOW RANGE, SHOW RANGES, SHOW REGIONS, SHOW SURVIVAL GOAL, +// SHOW CREATE, SHOW CREATE SCHEDULES, SHOW DATABASES, SHOW ENUMS, SHOW +// FUNCTION, SHOW HISTOGRAM, SHOW INDEXES, SHOW PARTITIONS, SHOW JOBS, SHOW +// STATEMENTS, SHOW RANGE, SHOW RANGES, SHOW REGIONS, SHOW SURVIVAL GOAL, // SHOW ROLES, SHOW SCHEMAS, SHOW SEQUENCES, SHOW SESSION, SHOW SESSIONS, // SHOW STATISTICS, SHOW SYNTAX, SHOW TABLES, SHOW TRACE, SHOW TRANSACTION, // SHOW TRANSACTIONS, SHOW TRANSFER, SHOW TYPES, SHOW USERS, SHOW LAST QUERY STATISTICS, @@ -6760,6 +6761,15 @@ show_create_stmt: /* SKIP DOC */ $$.val = &tree.ShowCreate{Mode: tree.ShowCreateModeDatabase, Name: $4.unresolvedObjectName()} } +| SHOW CREATE FUNCTION db_object_name + { + /* SKIP DOC */ + $$.val = &tree.ShowCreateFunction{ + Name: tree.ResolvableFunctionReference{ + FunctionReference: $4.unresolvedObjectName().ToUnresolvedName(), + }, + } + } | SHOW CREATE ALL SCHEMAS { $$.val = &tree.ShowCreateAllSchemas{} diff --git a/pkg/sql/parser/testdata/show b/pkg/sql/parser/testdata/show index 88a8f0d849aa..64d9eb6beac1 100644 --- a/pkg/sql/parser/testdata/show +++ b/pkg/sql/parser/testdata/show @@ -1754,3 +1754,27 @@ SHOW client_encoding -- normalized! SHOW client_encoding -- fully parenthesized SHOW client_encoding -- literals removed SHOW client_encoding -- identifiers removed + +parse +SHOW CREATE FUNCTION foo +---- +SHOW CREATE FUNCTION foo +SHOW CREATE FUNCTION foo -- fully parenthesized +SHOW CREATE FUNCTION foo -- literals removed +SHOW CREATE FUNCTION _ -- identifiers removed + +parse +SHOW CREATE FUNCTION db.foo +---- +SHOW CREATE FUNCTION db.foo +SHOW CREATE FUNCTION db.foo -- fully parenthesized +SHOW CREATE FUNCTION db.foo -- literals removed +SHOW CREATE FUNCTION _._ -- identifiers removed + +parse +SHOW CREATE FUNCTION db.sch.foo +---- +SHOW CREATE FUNCTION db.sch.foo +SHOW CREATE FUNCTION db.sch.foo -- fully parenthesized +SHOW CREATE FUNCTION db.sch.foo -- literals removed +SHOW CREATE FUNCTION _._._ -- identifiers removed diff --git a/pkg/sql/sem/tree/show.go b/pkg/sql/sem/tree/show.go index cb9d8a42cb28..a4a726869b4f 100644 --- a/pkg/sql/sem/tree/show.go +++ b/pkg/sql/sem/tree/show.go @@ -944,3 +944,16 @@ func (s ShowCompletions) Format(ctx *FmtCtx) { } var _ Statement = &ShowCompletions{} + +// ShowCreateFunction represents a SHOW CREATE FUNCTION statement. +type ShowCreateFunction struct { + Name ResolvableFunctionReference +} + +// Format implements the NodeFormatter interface. +func (node *ShowCreateFunction) Format(ctx *FmtCtx) { + ctx.WriteString("SHOW CREATE FUNCTION ") + ctx.FormatNode(&node.Name) +} + +var _ Statement = &ShowCreateFunction{} diff --git a/pkg/sql/sem/tree/stmt.go b/pkg/sql/sem/tree/stmt.go index 155f49c6cd58..94adc13827c7 100644 --- a/pkg/sql/sem/tree/stmt.go +++ b/pkg/sql/sem/tree/stmt.go @@ -1714,6 +1714,15 @@ func (*ShowCompletions) observerStatement() {} func (*ShowCompletions) hiddenFromShowQueries() {} +// StatementReturnType implements the Statement interface. +func (*ShowCreateFunction) StatementReturnType() StatementReturnType { return Rows } + +// StatementType implements the Statement interface. +func (*ShowCreateFunction) StatementType() StatementType { return TypeDML } + +// StatementTag returns a short string identifying the type of statement. +func (*ShowCreateFunction) StatementTag() string { return "SHOW CREATE FUNCTION" } + // StatementReturnType implements the Statement interface. func (*Split) StatementReturnType() StatementReturnType { return Rows } @@ -1926,14 +1935,15 @@ func (n *ShowTenantClusterSettingList) String() string { return AsString(n) } func (n *ShowColumns) String() string { return AsString(n) } func (n *ShowConstraints) String() string { return AsString(n) } func (n *ShowCreate) String() string { return AsString(n) } -func (node *ShowCreateAllSchemas) String() string { return AsString(node) } -func (node *ShowCreateAllTables) String() string { return AsString(node) } -func (node *ShowCreateAllTypes) String() string { return AsString(node) } +func (n *ShowCreateAllSchemas) String() string { return AsString(n) } +func (n *ShowCreateAllTables) String() string { return AsString(n) } +func (n *ShowCreateAllTypes) String() string { return AsString(n) } func (n *ShowCreateSchedules) String() string { return AsString(n) } func (n *ShowDatabases) String() string { return AsString(n) } func (n *ShowDatabaseIndexes) String() string { return AsString(n) } func (n *ShowEnums) String() string { return AsString(n) } func (n *ShowFullTableScans) String() string { return AsString(n) } +func (n *ShowCreateFunction) String() string { return AsString(n) } func (n *ShowGrants) String() string { return AsString(n) } func (n *ShowHistogram) String() string { return AsString(n) } func (n *ShowSchedules) String() string { return AsString(n) }