PREPARED_STATEMENT()
All functions > METADATA > PREPARED_STATEMENT()
Returns a reference to a prepared statement of the given feature with the given inputs.
Signatures
Returns: A statement that serving calls with one value per parameter
PREPARED_STATEMENT(
feature
USING { param | ( param, ... ) }, ...
[ CAPTURE ( feature, ... ) ]
)
param: input [ := REQUEST_TIME() | := REQUEST_SEED() ] → FEATURE| Parameter | Type | Required | Description |
|---|---|---|---|
feature | FEATURE | Yes | Feature to serve, or a ROW of features |
CAPTURE | FEATURE | Yes | Features computed in the same call, from the same reads, and never returned: every LOGGER of the statement logs them |
input | FEATURE | Yes | Input that becomes a call parameter, in call order. A parenthesized group (A, B) makes several inputs share one parameter. input := REQUEST_TIME() binds the input to the time the call starts and input := REQUEST_SEED() to a DOUBLE in [0, 1) drawn once per call: neither is a call parameter |
Notes
- Persist it with
CREATE FEATURES AS ...to call it from the serving API - The whole computation, including
EXTERNAL_KV(),EXTERNAL_HTTP()andEXTERNAL_COLUMNS()lookups, compiles into one execution plan - INTERVAL, BITSTRING, BINARY and geo inputs are not supported
REQUEST_TIME()andREQUEST_SEED()are the USING binders: one value per call, shared by all the call's rows; a LOGGER logs them with the other inputs, for replay.NOW()andRANDOM()are refused there and at run time- No FOR: the nested keys of a prepared statement are implicit and cover the whole source table
CAPTURE (...)lists features its loggers log without returning them;INCLUDEandCOLUMNSare refused
See also
Examples
Persist a prepared statement
FeatureQL
CREATE OR REPLACE FEATURE FM.TUTORIALS.PREPARED_STATEMENTS.FEATURE_Q_PS AS
PREPARED_STATEMENT(
FM.TUTORIALS.PREPARED_STATEMENTS.FEATURE_Q
USING FM.TUTORIALS.PREPARED_STATEMENTS.FEATURE_A
);Result
| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.PREPARED_STATEMENTS.FEATURE_Q_PS | CREATED | Feature created as not exists |
Call it with values for its parameters
Prepared
FM.TUTORIALS.PREPARED_STATEMENTS.FEATURE_Q_PSCall 1
{"input_1": [[1], [5]]} | FEATURE_A BIGINT | FEATURE_Q_PS BIGINT |
|---|---|
| 1 | 2 |
| 5 | 6 |
Several inputs sharing one parameter
Prepared
FM.TUTORIALS.PREPARED_STATEMENTS.FEATURE_R_PSCall 1
{"input_1": [[1, 2], [4, 5]], "input_2": [[10]]} | FEATURE_A BIGINT | FEATURE_B BIGINT | FEATURE_C BIGINT | FEATURE_R_PS BIGINT |
|---|---|---|---|
| 1 | 2 | 10 | 13 |
| 4 | 5 | 10 | 19 |