[x] Introduce proper function abstractions to engine (FunctionManager, FunctionHandle, etc). #11851 #12427 #12444 #12472 #12542 #12541
[x] Simplify function resolution
CREATE FUNCTION statement #13254 ALTER FUNCTION, DROP FUNCTION statement #13799 13412GRANT for function access4.34 SQL-paths
An SQL-path is a list of one or more
<schema name>s that determines the search order for one of the following:
— The subject routine of a<routine invocation>whose<routine name>does not contain a.
— The user-defined type when the<path-resolved user-defined type name>does not contain a<schema name>.
4.43.3 SQL-session properties
An SQL-session has an SQL-path that is used to effectively qualify unqualified
<routine name>s [...]
The SQL-path is initially set to an implementation-de ned value, but can subsequently be changed by the successful execution of a<set path statement>.
The text defining the SQL-path can be referenced by using the<general value specification> CURRENT_PATH.
6.4
<value specification>and<target specification>4) The declared type of
CURRENT_USER,CURRENT_ROLE,SESSION_USER,SYSTEM_USER,CURRENT_CATALOG,CURRENT_SCHEMA, andCURRENT_PATHis character string. Whether the character string is fixed-length or variable-length, and its length if it is fixed-length or maximum length if it is variable-length, are implementation-de ned. The character set of the character string isSQL_IDENTIFIER. The declared type collation is the character set collation ofSQL_IDENTIFIER, and the collation derivation is implicit.
12) The value specified byCURRENT_PATHis a<schema name list>where<catalog name>s are<delimited identifier>s and the<unqualified schema name>s are<delimited identifier>s. Each<schema name>is separated from the preceding<schema name>by a<comma>with no intervening<space>s. The schemas referenced in this<schema name list>are those referenced in the SQL-path of the current SQL-session context, in the order in which they appear in that SQL-path.
10.3
<path specification>Function
Specify an order for searching for an SQL-invoked routine.
Format
<path specification> ::= PATH <schema name list> <schema name list> ::= <schema name> [ { <comma> <schema name> }... ] <schema name> ::= [ <catalog name> <period> ] <unqualified schema name> <unqualified schema name> ::= <identifier> <catalog name> ::= <identifier>Syntax Rules
1) No two
<schema name>s contained in<schema name list>shall be equivalent.
19.8
<set path statement>Function
Set the SQL-path used to determine the subject routine of
<routine invocation>s with unqualified<routine name>s in<preparable statement>s that are prepared in the current SQL-session by an<execute immediate statement>or a<prepare statement>and in<direct SQL statement>s that are invoked directly. The SQL-path remains the current SQL-path of the SQL-session until another SQL-path is successfully set.Format
<set path statement> ::= SET <SQL-path characteristic> <SQL-path characteristic> ::= PATH <value specification>Syntax Rules
1) The declared type of the
shall be a character string type. Access Rules
None.
General Rules
1) Let
Sbe<value specification>and letVbe the character string that is the value ofTRIM ( BOTH ' ' FROM S )
a) IfVdoes not conform to the Format and Syntax Rules of a<schema name list>, then an exception condition is raised: invalid schema name list specification.
b) The SQL-path of the current SQL-session is set toV.
NOTE 724 — A<set path statement>that is executed between a<prepare statement>and an<execute statement>has no effect on the prepared statement.Conformance Rules
1) Without Feature S071, “SQL paths in function and type name resolution”, Conforming SQL language shall not contain a
<set path statement>.
Make it possible to implement user-defined functions and types in the future
This is possible correctly using JARs. Could you elaborate a bit? Do you mean a more holistic approach where:
How does planner/optimizer refer to function names (for a rewrite), given that the fully-qualified name depends on deployment configuration?
Could you give an example?
This is possible correctly using JARs. Could you elaborate a bit? Do you mean a more holistic approach where:
Yes, functions in languages such as Javascript, Ruby, Python or even the SQL-specific language --- basically, anything that can be properly sandboxed. Efforts such as Truffle/Graal can make this easier (and performant). See CREATE FUNCTION and CREATE TYPE in the spec.
How does planner/optimizer refer to function names (for a rewrite), given that the fully->> qualified name depends on deployment configuration?
Could you give an example?
For example, the upcoming spatial join optimizations. Or any of the desugaring optimizers if we decide to place the built-in functions into a namespace (although, those might go into a fixed namespace that's guaranteed to exist, similar to "sys" or "information_schema").
Efforts such as Truffle/Graal can make this easier (and performant). See CREATE FUNCTION and CREATE TYPE in the spec.
I didn't expect that, but it seems that there is serious effort to support R and Python: http://gigasquidsoftware.com/blog/2017/10/22/embedded-interop-between-clojure-r-and-python-with-graalvm/.
Do you plan to embrace Truffle/Graal in the next year or so?
functions in languages such as Javascript, Ruby, Python or even the SQL-specific language
I like that!
Do you plan to embrace Truffle/Graal in the next year or so?
I'd like to start experimenting with it, but it's unlikely we'll support it for production workloads, yet. The first step is to get on Java 9.
Updated based on https://github.com/prestosql/presto/issues/8
Most helpful comment
Yes, functions in languages such as Javascript, Ruby, Python or even the SQL-specific language --- basically, anything that can be properly sandboxed. Efforts such as Truffle/Graal can make this easier (and performant). See CREATE FUNCTION and CREATE TYPE in the spec.
For example, the upcoming spatial join optimizations. Or any of the desugaring optimizers if we decide to place the built-in functions into a namespace (although, those might go into a fixed namespace that's guaranteed to exist, similar to "sys" or "information_schema").