Skip to content

Commit

Permalink
sql: add parsing support for SHOW CREATE FUNCTION statement
Browse files Browse the repository at this point in the history
This commit adds a `SHOW CREATE FUNCTION` statement to the SQL grammar.
This statement is not yet implemented and executing it results in an
error.

Release note: None
  • Loading branch information
mgartner committed Jul 18, 2022
1 parent 116c5aa commit c8c5149
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/sql/delegate/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/delegate/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
20 changes: 20 additions & 0 deletions pkg/sql/delegate/show_function.go
Original file line number Diff line number Diff line change
@@ -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")
}
5 changes: 5 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/show_create
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 12 additions & 2 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{}
Expand Down
24 changes: 24 additions & 0 deletions pkg/sql/parser/testdata/show
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions pkg/sql/sem/tree/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
16 changes: 13 additions & 3 deletions pkg/sql/sem/tree/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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) }
Expand Down

0 comments on commit c8c5149

Please sign in to comment.