RELATED()
All functions > CORE > RELATED()
Joins a feature or an aggregation using a key as base
Signatures
Returns: The joined feature value
RELATED(base: FEATURE, add: FEATURE, [binding_features: FEATURE]) → T sql
| Parameter | Type | Required | Description |
|---|---|---|---|
base | FEATURE | Yes | Base feature to use for binding |
add | FEATURE | Yes | Feature to add |
binding_features | FEATURE | No | Optional outer feature for explicit join-key binding (BIND TO); omit when inference suffices |
Notes
- RELATED is syntactic sugar for EXTEND with automatic wrap/unwrap
- RELATED(joined_feature VIA base_feature) expands to: EXTEND(joined_feature AS joined_field WITH ROW(base_feature AS field_name))[joined_field]
- Optional
BIND TO binding_feature(standalone: afterVIA base; chained: inside.RELATED(...)) pins the outer join key when entity annotations do not infer it unambiguously - At most one
BIND TOexpression; use EXTEND withVIA … BIND TO …for field-level or multi-key binding - Avoids the manual ROW construction and field extraction needed with EXTEND
- Will be rewritten to EXTEND/EXTEND during query processing
Examples
Lookup across entities (VIA) — see 5-related.slt suite
FeatureQL
WITH
-- ** Features defining the semantic entities [likely already persisted in the registry] **
orders := ENTITY(),
order_id := INPUT(BIGINT#orders),
stores := ENTITY(),
store_id := INPUT(BIGINT#stores),
-- ** Features depending on ORDER_ID [likely already persisted in the registry] **
tables.orders := INLINE_COLUMNS(
order_id BIGINT#orders BIND TO order_id,
order_store_id BIGINT#stores
FROM CSV(
order_id,order_store_id
10,20
11,21
12,22
13,21
14,22
15,21
)
),
-- ** Features depending on STORE_ID [likely already persisted in the registry] **
tables.stores := INLINE_COLUMNS(
store_id BIGINT#stores BIND TO store_id,
store_category VARCHAR,
store_city VARCHAR
FROM CSV(
store_id,store_category,store_city
20,PIZZA,BCN
21,SUSHI,MAD
22,BURGER,VAL
)
),
-- ** New feature depending on ORDER_ID **
order_category := RELATED(
tables.stores[store_category] VIA tables.orders[order_store_id]
)
SELECT
order_id,
order_category
FOR
order_id := BIND_VALUES(SEQUENCE(10, 15))
ORDER BY order_id
;Result
| ORDER_ID BIGINT | ORDER_CATEGORY VARCHAR |
|---|---|
| 10 | PIZZA |
| 11 | SUSHI |
| 12 | BURGER |
| 13 | SUSHI |
| 14 | BURGER |
| 15 | SUSHI |