Description
Summary
Add a SHOW CREATE FUNCTION statement that returns the exact CREATE FUNCTION DDL used to register a UDF, mirroring the existing SHOW CREATE TABLE / SHOW CREATE VIEW pattern. The output should be a fully-formed, re-runnable CREATE statement including argument type qualifiers (sizes, precision, scale) and, for inline functions, the function body.
Motivation
StarRocks supports two existing discovery commands for functions — SHOW FUNCTIONS and SHOW FULL FUNCTIONS — but both have blind spots that make real-world operational tasks painful
Drawback 1 — Size/precision qualifiers are stripped
mysql> SHOW FULL FUNCTIONS FROM analytics;
+---------------------------+---------------+---------------+-------------------+------------+
| Signature | Return Type | Function Type | Intermediate Type | Properties |
+---------------------------+---------------+---------------+-------------------+------------+
| format_phone(VARCHAR) | VARCHAR | Scalar | | |
| compute_tax(DECIMAL, INT) | DECIMAL | Scalar | | |
+---------------------------+---------------+---------------+-------------------+------------+
The signature column prints bare type names without the size/precision the function was actually registered with. A user who created format_phone(VARCHAR(100)) has no way to recover that 100 from the catalog — same story for CHAR(n), DECIMAL(p, s) etc.
Drawback 2 — No way to see inline function bodies
For inline UDFs (Python functions using the AS $$ ... $$ body form):
CREATE FUNCTION analytics.normalize_email(VARCHAR(256))
RETURNS VARCHAR(256)
PROPERTIES ("type" = "Python", "symbol" = "normalize_email")
AS $$
def normalize_email(e):
return e.strip().lower()
$$;
Proposal
Syntax
SHOW CREATE [GLOBAL] FUNCTION <function_name> [ ( <input_type_list> ) ]
- Argument types are required. This matches DROP FUNCTION and GRANT ... ON FUNCTION, which also require an argument list, so users learn a single mental model across all function-scoped DDL.
Output schema
Single column Create Function of type VARCHAR, mirroring MySQL's SHOW CREATE PROCEDURE:
mysql> SHOW CREATE FUNCTION analytics.string_process(VARCHAR(1000), VARCHAR(50));
+--------------------------------------------------------------------------+
| Create Function |
+--------------------------------------------------------------------------+
| CREATE FUNCTION analytics.string_process(VARCHAR(1000), VARCHAR(50))
| RETURNS VARCHAR(1000)
| PROPERTIES (
| "type" = "Python",
| "file" = "inline",
| "symbol" = "string_process",
| "input" = "scalar"
| )
| AS $$
|
| def string_process(text, operation):
| if text is None:
| return None
|
| if operation == 'upper':
| return text.upper()
| elif operation == 'lower':
| return text.lower()
| else:
| return text
| $$
+--------------------------------------------------------------------------+
Implementation status
This feature has been implemented and tested internally on a recent StarRocks branch. We are happy to contribute this to upstream once the community aligns.