Prototyping
Feature definitions are evaluated lazily. It means that if you don't use a feature in the SELECT clause, it will not be evaluated. It is convenient for prototyping, as what you put in the SELECT governs what is evaluated.
Using the exact same query with customer outputs, you can see that the query is evaluated for the customers 100, 101 and 102.
WITH
-- Related to the customer
CUSTOMER_NAME := TABLES.DIM_CUSTOMERS[name],
NUM_ORDERS_RELATED := RELATED(SUM(IF(ORDER_DATE>TIMESTAMP '2025-01-01', 1, 0)) GROUP BY TABLES.FCT_ORDERS[order_customer_id] VIA CUSTOMER_ID),
-- Related to the order
ORDER_DATE := TABLES.FCT_ORDERS[time_create]
SELECT
-- Related to the customer
CUSTOMER_ID,
NUM_ORDERS_RELATED,
-- Related to the order
-- ORDER_ID,
-- ORDER_DATE
FROM FM.ECOMM
FOR
CUSTOMER_ID := BIND_VALUES(SEQUENCE(100,102)),
ORDER_ID := BIND_VALUES(SEQUENCE(200,203)),
;| FM.ECOMM.CUSTOMER_ID BIGINT | NUM_ORDERS_RELATED VARCHAR |
|---|---|
| 100 | 2 |
| 101 | 0 |
| 102 | 1 |
Using the exact same query with order outputs, you can see that the query is evaluated for the orders 200, 201, 202 and 203.
WITH
-- Related to the customer
CUSTOMER_NAME := TABLES.DIM_CUSTOMERS[name],
NUM_ORDERS_RELATED := RELATED(SUM(IF(ORDER_DATE>TIMESTAMP '2025-01-01', 1, 0)) GROUP BY TABLES.FCT_ORDERS[order_customer_id] VIA CUSTOMER_ID),
-- Related to the order
ORDER_DATE := TABLES.FCT_ORDERS[time_create]
SELECT
-- Related to the customer
-- CUSTOMER_ID,
-- NUM_ORDERS_RELATED,
-- Related to the order
ORDER_ID,
ORDER_DATE
FROM FM.ECOMM
FOR
CUSTOMER_ID := BIND_VALUES(SEQUENCE(100,102)),
ORDER_ID := BIND_VALUES(SEQUENCE(200,203)),
;| FM.ECOMM.ORDER_ID BIGINT | ORDER_DATE VARCHAR |
|---|---|
| 200 | 2025-09-18T14:30:00 |
| 201 | 2024-12-08T09:45:00 |
| 202 | 2025-02-03T12:00:02 |
| 203 | 2025-09-18T14:30:00 |
Once you are happy with your query, we recommend you to clean the definitions to keep only the features needed for clarity.
Note: Be careful, if you use the exact same query with customer outputs and order outputs, it will perform a cross-join between the customers and the orders, which is likely not what you want.