...
However, they need to be done simultaneously to achieve the functionality in full stack.
Proposed Changes
We will first clarify the dimensions of functions.
System (can be used interchangeably with "builtin") | Catalog | |
---|---|---|
Non-Temporary | system functions | catalog functions |
Temporary | temporary system functions | temporary catalog functions |
1. Support Two Types of Temporary Functions
...
- temporary system function that has no namespace and overrides built-in functions
- temporary catalog function that has catalog and database namespaces and overrides catalog functions.
...
Existing “registerScalar/Table/AggregateFunctions()” will be deprecated in favor of the new APIs.
b) Temporary Catalog Functions
We will add a new member variable to FunctionCatalog as “Map<ObjectIdentifier, UserDefinedFunction> tempFunctions“ tempCatalogFunctions“ to hold those temporary catalog functions in a central place, and new APIs “registerTemporaryScalar/Table/AggregateFunction(ObjectIdentifier, UserDefinedFunction)”.
Lifespan of temp functions are not tied to those of catalogs and databases. Users can create temp catalog functions even though catalogs/dbs in their fully qualified names don't even exist.
Their DDLs are “CREATE/DROP TEMPORARY FUNCTION”.
Some other proposed SQL commands are:
"SHOW FUNCTIONS" - list names of temp and non-temp system/built-in functions, and names of temp and catalog functions in the current catalog and db
"SHOW ALL FUNCTIONS" - list names of temp and non-temp system/built functions, and fully qualified names of temp catalog functions and catalog functions in all catalogs and dbs
"SHOW ALL TEMPORARY FUNCTIONS" - list fully qualified names of temp catalog functions in all catalog and db
...
Lifespan of both types of temporary functions will be within a session, and will destroyed upon session end.
Note: corresponding DDL and SQL commands are not part of this FLIP
2. Support Precise Function Reference
Because built-in system functions don’t have namespaces, a precise function reference in Flink must be either temporary catalog functions with namespaces or catalog functions.
The resolution order will be
- Temporary catalog functions with no namespace
- Catalog functions
3. Support Ambiguous Function Reference with a Redefined Resolution Order
For ambiguous function reference, there are 4 types of functions to consider: temporary functions with and without no namespaces, Flink built-in system functions, and catalog functions.
...
- Temporary system functions
- Flink Built-in System functions
- Temporary catalog functions, in the current catalog and current database of the session
- Catalog functions, in the current catalog and current database of the session
...
Temp functions should rank above their corresponding persistent/built-in functions due to its temporary nature - users want to overwrite built-in or persistent functions with something temporary that is only visible to themselves and the session, and not impacting other users. In contrary, 1) if users don’t have the intention of overwriting other functions, they can just name the temporary functions to something else, considering the manipulation cost is so low for temporary objects, and 2) if built-in functions precede temporary functions, there’s no way to reference temp functions anymore
Flink built-in System functions should precede catalog functions, because 1) it always give a deterministic resolution order on ambiguous reference by invoking the built-in functions 2) catalog functions can always be precisely referenced with fully/partially qualified names. In contrary, if catalog functions precede built-in functions, built-in functions can never be referenced.
...
Code Block | ||
---|---|---|
| ||
Class FunctionIdentifier { // emptyfor temporary/non-temporary system function // for system functionstemporary/non-temporary catalog function Optional<ObjectIdentifier>ObjectIdentifier oi; String name; Optional<ObjectIdentifier> getIdentifier() {} Optional<String> getSimpleName() {} } |
Changes to CallExpression and UnresolvedCallExpression
...