- Introduction
- Quick Start
- Table Design
- Data Loading
- Overview of data loading
- Load data from a local file system or a streaming data source using HTTP push
- Load data from HDFS or cloud storage
- Routine Load
- Spark Load
- Insert Into
- Change data through loading
- Transform data at loading
- Json Loading
- Synchronize data from MySQL
- Load data by using flink-connector-starrocks
- DataX Writer
- Data Export
- Using StarRocks
- Reference
- SQL Reference
- User Account Management
- Cluster Management
- ADMIN CANCEL REPAIR
- ADMIN CHECK TABLET
- ADMIN REPAIR
- ADMIN SET CONFIG
- ADMIN SET REPLICA STATUS
- ADMIN SHOW CONFIG
- ADMIN SHOW REPLICA DISTRIBUTION
- ADMIN SHOW REPLICA STATUS
- ALTER SYSTEM
- CANCEL DECOMMISSION
- CREATE FILE
- DROP FILE
- INSTALL PLUGIN
- SHOW BACKENDS
- SHOW BROKER
- SHOW FILE
- SHOW FRONTENDS
- SHOW FULL COLUMNS
- SHOW INDEX
- SHOW PLUGINS
- SHOW TABLE STATUS
- UNINSTALL PLUGIN
- DDL
- ALTER DATABASE
- ALTER TABLE
- ALTER VIEW
- BACKUP
- CANCEL BACKUP
- CANCEL RESTORE
- CREATE DATABASE
- CREATE INDEX
- CREATE MATERIALIZED VIEW
- CREATE REPOSITORY
- CREATE RESOURCE
- CREATE TABLE AS SELECT
- CREATE TABLE LIKE
- CREATE TABLE
- CREATE VIEW
- CREATE FUNCTION
- DROP DATABASE
- DROP INDEX
- DROP MATERIALIZED VIEW
- DROP REPOSITORY
- DROP RESOURCE
- DROP TABLE
- DROP VIEW
- DROP FUNCTION
- HLL
- RECOVER
- RESTORE
- SHOW RESOURCES
- SHOW FUNCTION
- TRUNCATE TABLE
- DML
- ALTER ROUTINE LOAD
- BROKER LOAD
- CANCEL LOAD
- DELETE
- EXPORT
- GROUP BY
- INSERT
- PAUSE ROUTINE LOAD
- RESUME ROUTINE LOAD
- ROUTINE LOAD
- SELECT
- SHOW ALTER
- SHOW BACKUP
- SHOW DATA
- SHOW DATABASES
- SHOW DELETE
- SHOW DYNAMIC PARTITION TABLES
- SHOW EXPORT
- SHOW LOAD
- SHOW PARTITIONS
- SHOW PROPERTY
- SHOW REPOSITORIES
- SHOW RESTORE
- SHOW ROUTINE LOAD
- SHOW ROUTINE LOAD TASK
- SHOW SNAPSHOT
- SHOW TABLES
- SHOW TABLET
- SHOW TRANSACTION
- SPARK LOAD
- STOP ROUTINE LOAD
- STREAM LOAD
- Data Types
- Auxiliary Commands
- Function Reference
- Java UDFs
- Window Function
- Date Functions
- convert_tz
- curdate
- current_timestamp
- curtime
- datediff
- date_add
- date_format
- date_sub
- date_trunc
- day
- dayname
- dayofmonth
- dayofweek
- dayofyear
- from_days
- from_unixtime
- hour
- minute
- month
- monthname
- now
- quarter
- second
- str_to_date
- timediff
- timestampadd
- timestampdiff
- to_date
- to_days
- unix_timestamp
- utc_timestamp
- weekofyear
- year
- hours_diff
- minutes_diff
- months_diff
- seconds_diff
- weeks_diff
- years_diff
- Aggregate Functions
- Geographic Functions
- String Functions
- JSON Functions
- Overview of JSON functions and operators
- JSON constructor functions
- JSON query and processing functions
- JSON operators
- Aggregate Functions
- Bitmap Functions
- Array Functions
- cast function
- hash function
- Cryptographic Functions
- Math Functions
- Utility Functions
- System variables
- Error code
- System limits
- SQL Reference
- Administration
- FAQ
- Deploy
- Data Migration
- SQL
- Other FAQs
- Benchmark
- Developers
- Contribute to StarRocks
- Code Style Guides
- Use the debuginfo file for debugging
- Development Environment
- Trace Tools
- Integration
CREATE FUNCTION
description
Syntax
CREATE [AGGREGATE] FUNCTION function_name
(arg_type [, ...])
RETURNS ret_type
[INTERMEDIATE inter_type]
[PROPERTIES ("key" = "value" [, ...]) ]
Parameters
AGGREGATE: This parameter indicates that the created function is an aggregate function, otherwise it is a scalar function.
function_name: When creating the name of a function, you can include the name of the database. For example,db1.my_func
。
arg_type: Argument type of function, the same type as that defined when creating table. The added argument can be represented by, ...
The added type is the same as that of the last argument before it was added.
ret_type: A function return type.
inter_type: A data type used to represent the intermediate stage of an aggregate function.
properties: It is used to set properties related to aggregate function, which include:
object_file: Custom function dynamic library URL path, currently only supports HTTP/HTTPS protocol. This path needs to remain valid throughout the life cycle of the function. The option is required.
symbol: Function signature of scalar functions for finding function entries from dynamic libraries. This option is required for scalar functions.
init_fn: Initialization function signature of aggregate function. Required for aggregation functions.
update_fn: Update function signature for aggregate function. Required for aggregation functions.
merge_fn: Merge function signature of aggregate function. Required for aggregation functions.
serialize_fn: Serialized function signature of aggregate function. Optional for aggregation functions. If not specified, the default serialization function will be used.
finalize_fn: A function signature that aggregates functions to obtain the final result. Optional for aggregate functions. If not specified, the default obtained result function will be used.
md5: The MD5 value of the function dynamic link library, which is used to verify that the downloaded content is correct. This option is optional.
prepare_fn: Function signature of the prepare function for finding the entry from the dynamic library. This option is optional for custom functions.
close_fn: Function signature of the close function for finding the entry from the dynamic library. This option is optional for custom functions.
This statement creates a custom function. To execute this command requires the
ADMIN
permission of the user.If the
function_name
contains the database name, the custom function will be created in the corresponding database. Otherwise the function will be created in the database where the current session is located. The name and parameters of the new function cannot be the same as functions already existing in the current namespace, otherwise the creation will fail. But the creation can be successful with the same name and different parameters.
example
Create a custom scalar function.
CREATE FUNCTION my_add(INT, INT) RETURNS INT PROPERTIES ( "symbol" = "_ZN9starrocks_udf6AddUdfEPNS_15FunctionContextERKNS_6IntValES4_", "object_file" = "http://host:port/libmyadd.so" );
Create a custom scalar function with prepare/close functions.
CREATE FUNCTION my_add(INT, INT) RETURNS INT PROPERTIES ( "symbol" = "_ZN9starrocks_udf6AddUdfEPNS_15FunctionContextERKNS_6IntValES4_", "prepare_fn" = "_ZN9starrocks_udf14AddUdf_prepareEPNS_15FunctionContextENS0_18FunctionStateScopeE", "close_fn" = "_ZN9starrocks_udf12AddUdf_closeEPNS_15FunctionContextENS0_18FunctionStateScopeE", "object_file" = "http://host:port/libmyadd.so" );
Create a custom aggregate function.
CREATE AGGREGATE FUNCTION my_count (BIGINT) RETURNS BIGINT PROPERTIES ( "init_fn"="_ZN9starrocks_udf9CountInitEPNS_15FunctionContextEPNS_9BigIntValE", "update_fn"="_ZN9starrocks_udf11CountUpdateEPNS_15FunctionContextERKNS_6IntValEPNS_9BigIntValE", "merge_fn"="_ZN9starrocks_udf10CountMergeEPNS_15FunctionContextERKNS_9BigIntValEPS2_", "finalize_fn"="_ZN9starrocks_udf13CountFinalizeEPNS_15FunctionContextERKNS_9BigIntValE", "object_file"="http://host:port/libudasample.so" );
Create a scalar function with variable length arguments.
CREATE FUNCTION strconcat(varchar, ...) RETURNS varchar properties ( "symbol" = "_ZN9starrocks_udf6StrConcatUdfEPNS_15FunctionContextERKNS_6IntValES4_", "object_file" = "http://host:port/libmyStrConcat.so" );
keyword
CREATE,FUNCTION