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) → T
sql
ParameterTypeRequiredDescription
baseFEATUREYesBase feature to use for binding
addFEATUREYesFeature to add

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]
  • 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 BIGINTORDER_CATEGORY VARCHAR
10PIZZA
11SUSHI
12BURGER
13SUSHI
14BURGER
15SUSHI

Last update at: 2026/05/26 17:22:09