Status
Current state: "Under Discussion"
Discussion thread: http://apache-flink-mailing-list-archive.1008284.n3.nabble.com/Discussion-FLIP-79-Flink-Function-DDL-Support-td33965.html
JIRA: https://issues.apache.org/jira/browse/FLINK-7151
Released:
Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
Motivation
This proposal aims to support function DDL with the consideration of SQL syntax, language compliance, and advanced external UDF lib registration. The Flink DDL is initialized and discussed in the design [1] by Shuyi Chen and Timo. As the initial discussion mainly focused on the table, type and view. FLIP-69 [2] extend it with a more detailed discussion of DDL for catalog, database, and function. Original the function DDL was under the scope of FLIP-69. After some discussion with the community, we found that there are several ongoing efforts, such as FLIP-64 [3], FLIP-65 [4], and FLIP-78 [5]. As they will directly impact the SQL syntax of function DDL, the proposal wants to describe the problem clearly with the consideration of existing works and make sure the design aligns with efforts of API change of temporary objects and type inference for UDF defined by different languages.
Proposed Changes
Requirements
Before deep into the DDL SQL, we want to discuss the major requirements for defining a function within Flink runtime by related FLIPs:
External lib registration. The requirements come from the hive integration that enhances the adoption of Flink batch. HQL supports syntax like:
CREATE FUNCTION addfunc AS 'com.example.hiveserver2.udf.add' USING JAR 'hdfs:///path/to/jar' Language distinguish. Due to bytecode language specifics in Scala, there are some limitations to extract type information from scala function. At the same time, support python UDF in table runtime is another ongoing effort. Thus, the SQL syntax consider support multiple languages. Mysql create function syntax support language in this way:
CREATE FUNCTION hello (s CHAR(20))RETURNS CHAR(50)DETERMINISTIC RETURN CONCAT('Hello, ',s,'!') LANGUAGE SQL - Properties Definition. Similar with properties for table, we can add properties for function. The motivation of it is to make the UDF definition more extendable for future works.
- Temporary Object Scope.Temporary functions identifiers resolution consider object scopes whether in particular catalog, database or just concurrent catalog and database. Thus, all of the function DDL needs to support 3-part path.
Function DDL SQL Syntax
Create Function Statement
CREATE FUNCTION [IF NOT EXISTS] [catalog_name.db_name.]function_name AS class_name LANGUAGE lang_str [USING resource_path] [WITH PROPERTIES ‘(‘ name=value [, name=value]* ‘)’] |
---|
Drop Function Statement
DROP FUNCTION [IF EXISTS] [catalog_name.][db_name.] function_name; |
---|
Alter Function Statement
ALTER FUNCTION [IF EXISTS] [catalog_name.][db_name.] function_name RENAME TO new_name; |
---|
Show Function Statement
SHOW FUNCTION [catalog_name.][db_name] |
---|