Query structure
A FeatureQL query defines features, selects which ones to return, and binds concrete values to their inputs. You can then filter, sort, and paginate the results — just like SQL.
Anatomy of a query
[WITH
feature_name := expression, -- Feature definition
...
]
SELECT
feature_name, -- Feature to evaluate and return
...
[FROM namespace, ...]
[FOR feature_name := BIND(), ...] -- Bind values to inputs
[WHERE boolean_expression] -- Filter results
[ORDER BY expression [ASC|DESC] [NULLS FIRST|LAST], ...] -- Sort results
[LIMIT count [OFFSET count]] -- Paginate results sql
Each clause has a specific role:
WITHdefines features locally, on top of what already exists in the registry. Only features referenced bySELECTare actually evaluated — the rest are ignored.SELECTlists the features to evaluate and return.FROMpulls in persisted features from one or more namespaces.FORbinds concrete values to the query's inputs. Without binding, a query withINPUT()features won't execute. See Binding inputs for details.WHEREfilters the result rows. You can reference any feature — including ones defined inline in theSELECT.ORDER BYsorts the results. SupportsASC/DESCandNULLS FIRST/NULLS LAST.LIMITandOFFSETcontrol pagination.
Note: GROUP BY and UNNEST are supported for analytics queries. See Grouping and unnesting for details.
Example
This example brings it all together: it defines an input with a data source, computes a derived feature, binds values, filters, sorts, and paginates.
FeatureQL
WITH
-- Input definitions
CUSTOMER_ID := INPUT(BIGINT),
-- Mapping to data source
DIM_CUSTOMERS := INLINE_COLUMNS(
customer_id BIGINT BIND TO CUSTOMER_ID,
name VARCHAR
FROM CSV(
customer_id,name
101,Alice
102,Bob
103,Charly
104,Daniel
105,Elody
106,Francis
107,George
108,Henry
109,Isaac
110,Jack
)
),
-- Define pure transformations
NAME := DIM_CUSTOMERS[name],
NAME_LENGTH := LENGTH(NAME)
SELECT
-- Features to evaluate and return
CUSTOMER_ID,
NAME,
NAME_LENGTH
FOR
CUSTOMER_ID := BIND_VALUES(@literal(SEQUENCE(101, 106))),
WHERE NAME < 'Henry'
ORDER BY NAME DESC
LIMIT 3 OFFSET 1Result
| CUSTOMER_ID BIGINT | NAME VARCHAR | NAME_LENGTH BIGINT |
|---|---|---|
| 105 | Elody | 5 |
| 104 | Daniel | 6 |
| 103 | Charly | 6 |
On this page