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
| Parameter | Type | Required | Description |
|---|---|---|---|
entity | ENTITY | Yes | The entity type this keyset represents |
query | VARCHAR | Yes | SQL query defining how to retrieve entity keys; may contain named :parameters |
PARTITION BY (param = FEATURE) | clause | No | Declares 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 dayvhasORDER_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 VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.KEYSETS1.ORDERS | CREATED | Feature created as not exists |
| FM.TUTORIALS.KEYSETS1.ORDER_KEYS | CREATED | Feature 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 VARCHAR | PARAM_NUM BIGINT |
|---|---|
| tablec1_11 | 10 |