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
ParameterTypeRequiredDescription
featureFEATUREYesFeature to serve, or a ROW of features
CAPTUREFEATUREYesFeatures computed in the same call, from the same reads, and never returned: every LOGGER of the statement logs them
inputFEATUREYesInput 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() and EXTERNAL_COLUMNS() lookups, compiles into one execution plan
  • INTERVAL, BITSTRING, BINARY and geo inputs are not supported
  • REQUEST_TIME() and REQUEST_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() and RANDOM() 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; INCLUDE and COLUMNS are 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 VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.PREPARED_STATEMENTS.FEATURE_Q_PSCREATEDFeature created as not exists

Call it with values for its parameters

Prepared
FM.TUTORIALS.PREPARED_STATEMENTS.FEATURE_Q_PS
Call 1
{"input_1": [[1], [5]]}
FEATURE_A BIGINTFEATURE_Q_PS BIGINT
12
56

Several inputs sharing one parameter

Prepared
FM.TUTORIALS.PREPARED_STATEMENTS.FEATURE_R_PS
Call 1
{"input_1": [[1, 2], [4, 5]], "input_2": [[10]]}
FEATURE_A BIGINTFEATURE_B BIGINTFEATURE_C BIGINTFEATURE_R_PS BIGINT
121013
451019