You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This introduces compilable SQL functions, as defined, for the most part,
in the SQL standard. The functions currently have the following
characteristics:
* non-temporary, defined, and serialized as part of the schema template.
* lazily compiled, the deserialized form of a SQL function only captures
its SQL definition, and compiled the first time it is referenced in a
SQL query.
* functions can nest, no support for recursive functions.
* they support (named) parameters, with expression default values (no
support for scalar queries).
* functions can be invoked either with named arguments, or unnamed
arguments, (no support for mixing named and unnamed arguments).
* the body of the function is currently limited to a single SQL
statement.
**Example**
```sql
create table t1(col1 bigint, col2 string, col3 integer, primary key(col1))
create function f1 ( in a bigint, in b string )
as select col1, col2 from t1 where col1 < a and col2 = b
create function f2 ( in k bigint )
as select col1, col2, col3 from t1 where col3 = k
create function f3 ( a bigint, b string, c bigint) as select A.col1, A.col2, B.col3 from f1(a, b) A, f2(c) B
```
When the above DDL is parsed, the functions are visited, and serialized
to disk along with the rest of the metadata, the serialized form of
compilable SQL functions comprises their name, and their description,
i.e. their SQL definition.
```sql
insert into t1 values
(100, 'a', 1),
(101, 'b', 2),
(102, 'b', 2),
(103, 'b', 2),
(104, 'c', 2),
(105, 'd', 4)
```
Invoking the functions can be done in two ways:
1. Using unnamed arguments
```sql
select * from f3(103, 'b', 4)
101, 'b', 4
102, 'b', 4
```
2. Using named arguments
```sql
select * from f3(a => 103, b => 'b', c => 4)
101, 'b', 4
102, 'b', 4
```
It is possible to define a function with default parameter values, for
example we could've defined the function `f3` as the following:
```sql
create function f3 ( in a bigint default 42, in b string default 'b', in c bigint default '4') as select A.col1, A.col2, B.col3 from f1(a, b) A, f2(c) B
```
if we did so, then we could've invoked `f3` as the following:
```sql
select * from f3()
101, 'b', 4
102, 'b', 4
```
This fixes#3325
Copy file name to clipboardExpand all lines: fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/metadata/expressions/FunctionKeyExpression.java
Copy file name to clipboardExpand all lines: fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/BitmapAggregateIndexExpansionVisitor.java
Copy file name to clipboardExpand all lines: fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/BuiltInFunction.java
Copy file name to clipboardExpand all lines: fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/CatalogedFunction.java
* Main interface for defining all functions that can be evaluated against a number of arguments.
36
45
* Two major sub interfaces inherit this interface: {@link BuiltInFunction} and {@link UserDefinedFunction}
37
-
* {@link BuiltInFunction} represents all functions that are built-in, and stored in code, while {@link UserDefinedFunction} represents all functions defined by users, and stored in {@link com.apple.foundationdb.record.RecordMetaDataProto.MetaData}
46
+
* {@link BuiltInFunction} represents all functions that are built-in, and stored in code, while
47
+
* {@link UserDefinedFunction} represents all functions defined by users, and stored in
0 commit comments