KEYSET()

All functions > METADATA > KEYSET()

Returns a reference to a keyset.

Signatures

Returns: A table representing the defined keyset

KEYSET(entity: ENTITY, query: VARCHAR, [PARTITION BY (param = FEATURE): clause]) → TABLE
sql
ParameterTypeRequiredDescription
entityENTITYYesThe entity type this keyset represents
queryVARCHARYesSQL query defining how to retrieve entity keys; may contain named :parameters
PARTITION BY (param = FEATURE)clauseNoDeclares that :param selects one partition of the keys, and FEATURE (a key attribute) names each key's partition. The parameter then takes one value or an ARRAY of values (a set of partitions).

Notes

  • The persisted feature name is the keyset identity
  • Keysets define collections of entity identifiers for batch processing
  • Source lineage is derived from the query; no table hints are required
  • Use named :parameters with a named ROW in @BIND_KEYSET()
  • KEYSET(ORDERS, 'SELECT order_id FROM orders WHERE ds = :ds' PARTITION BY (ds = ORDER_DS)) declares that the keyset bound to a set of days is the disjoint union of its daily keysets, and that every key of day v has ORDER_DS = v. The compiler trusts it and checks neither
  • A partitioned parameter accepts one value or an ARRAY of values: ROW(ds := SEQUENCE(DATE '2026-10-05', DATE '2026-10-07')). One value and a one-element array are the same binding; repeated values are merged; NULL is refused

See also

Examples

Persist a keyset

FeatureQL
CREATE OR REPLACE FEATURES IN FM.TUTORIALS.KEYSETS1 AS
PERSIST
    orders := ENTITY(),
    order_keys := KEYSET(
        orders,
        'SELECT order_id FROM (VALUES (10), (11), (12)) AS t(order_id)'
    )
;
Result
feature_name VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.KEYSETS1.ORDERSCREATEDFeature created as not exists
FM.TUTORIALS.KEYSETS1.ORDER_KEYSCREATEDFeature created as not exists

Bind its keys with @BIND_KEYSET()

FeatureQL
DEFINE
    orders := fm.tutorials.keysets1.orders,
    order_id := INPUT(BIGINT#orders),
    order_keys := fm.tutorials.keysets1.order_keys
RETURN
    order_id
FOR
    order_id := @BIND_KEYSET(order_keys)
;
Result
ORDER_ID BIGINT#ORDERS
10
11
12

Fill named :parameters with a ROW

FeatureQL
CONST
    BASE := 5,
    NUM := base * 2
DEFINE
    key_id := INPUT(BIGINT),
    keys_c_group := fm.tutorials.keysets2c.keys_c_group
RETURN
    value := EXTERNAL_COLUMNS(
        key_id BIGINT BIND TO key_id,
        value VARCHAR
        FROM TABLE(keysets.tablec1)
    )[value],
    param_num := VALUE(@eval_as_literal(num))
FOR
    key_id := @BIND_KEYSET(keys_c_group, ROW(num AS num))
;
Result
VALUE VARCHARPARAM_NUM BIGINT
tablec1_1110