Design choices that may surprise you
Some FeatureQL results differ from what SQL, a warehouse or a stream processor would give you. Each one follows from a design rule. This page lists the ones people meet first: what happens, why, and what to write instead.
Non-finite values from a source become NULL
What happens. A NaN, Infinity or -Infinity that arrives from a source column or a bound input is read as NULL. SUM then skips it, and COUNT_IF(x IS NOT NULL) does not count it, where plain SQL on the same table would return Infinity or NaN:
DEFINE
s := INPUT(VARCHAR)
RETURN
s,
f := s::DOUBLE
FOR
s := BIND_VALUES(ARRAY('1.5', 'Infinity', 'NaN'))
ORDER BY s
;| S VARCHAR | F DOUBLE |
|---|---|
| 1.5 | 1.5 |
| Infinity | NULL |
| NaN | NULL |
Why. A FeatureQL number is finite. Non-finite patterns are not values of the type, so they cannot be ordered or compared in the same way on every backend. They are not portable either: MySQL and MariaDB cannot store them, and on an overflow PostgreSQL and BigQuery raise an error where other engines return Infinity. Refusing every query that reads a column holding 'NaN' would fail too much, so the conversion happens where the data enters, and it is visible in the generated SQL. A non-finite constant you write is refused at compile time, and a computation that creates one raises an error ( Errors ).
What to write instead. Decide what a non-finite value means before it reaches FeatureQL, in the source or in the pipeline that writes it: a sentinel, a separate flag column, or NULL. To measure how many rows are affected, count them in SQL on the source, as you would for any other data contract .
A latest sink keeps the newest request time, not the newest event time
What happens. A hook writing a latest sink keeps, for each key, the row with the greater or equal request_time. For an event hook, request_time is the record's Kafka timestamp. Between equal times, the later write wins. A field of the payload such as event_time takes no part. So an order replayed or produced late, with an older event_time but a newer Kafka timestamp, replaces the newer order in the sink.
Why. A stream declares no event time: the engine never reads a payload field as the time of a call. REQUEST_TIME() has one meaning everywhere, the time of the request, and it is what every stored value carries. Event-time watermarks were rejected: deciding when an event-time window is complete belongs to a stream processor. Hooks are a precompute cache, not a ledger. Every stored value is exact for the inputs it was computed from, but an entry can lag or go back while records arrive out of order ( Which write lands ). A late or replayed record still computes its key from the sources as they are now, so only a value computed from the record's own payload can go back. An opt-in ordering by a payload column may come later, on demand; it does not exist today.
What to write instead. When event order matters, write the events to an append index keyed by the entity, INDEXED ON the event time and UNIQUE ON the event's id, and compute "the latest by event time" at request time from that index ( Sinks and reading ). Or use a scheduled hook that recomputes the value from the index: its value does not depend on the order in which records arrived.
DATE_DIFF(a, b, unit) is a − b, and counts boundaries
What happens. DATE_DIFF(end, start, 'day') returns end − start, counted as the number of day boundaries crossed. From 23:00 to 01:00 the next day, that is 1 day, and 1 year when the two times are on each side of New Year:
DEFINE
started := TIMESTAMP '2025-12-31 23:00:00',
ended := TIMESTAMP '2026-01-01 01:00:00'
RETURN
days_crossed := DATE_DIFF(ended, started, 'day'),
swapped := DATE_DIFF(started, ended, 'day'),
years_crossed := DATE_DIFF(ended, started, 'year'),
days_elapsed := DATE_SUBTRACT(ended, started, 'day')
;| DAYS_CROSSED BIGINT | SWAPPED BIGINT | YEARS_CROSSED BIGINT | DAYS_ELAPSED BIGINT |
|---|---|---|---|
| 1 | -1 | 1 | 0 |
DuckDB and Snowflake put the unit first: DATE_DIFF('day', start, end). In FeatureQL that order matches no signature, and the error says which order is expected:
DEFINE
STARTED := TIMESTAMP '2025-12-31 23:00:00',
ENDED := TIMESTAMP '2026-01-01 01:00:00',
RETURN D := DATE_DIFF('day', STARTED, ENDED);Why. FeatureQL functions take the value first and the unit last (DATE_TRUNC(ts, 'month'), DATE_PART(ts, 'hour')), so the arguments read in the order of the subtraction. Boundary counting is the SQL meaning of DATE_DIFF, kept so that a migrated query gives the same numbers.
What to write instead. Swap the arguments when you port SQL. For whole elapsed units (2 hours is 0 days), write DATE_SUBTRACT(end, start, 'day'). For a threshold such as "within 14 days", compare against DATE_ADD(start, 14, 'day') instead of subtracting. See DATE_DIFF .
GREATEST(NULL, 5) is NULL
What happens. GREATEST and LEAST return NULL when any argument is NULL. The ARRAY_* reducers skip NULL, as SQL aggregates do:
DEFINE
a := INPUT(BIGINT),
b := INPUT(BIGINT)
RETURN
a,
b,
g := GREATEST(a, b),
g_known := ARRAY_MAX(ARRAY(a, b))
FOR
(a, b) := BIND_VALUES(ARRAY(ROW(3, 5), ROW(NULL::BIGINT, 5)))
ORDER BY a
;| A BIGINT | B BIGINT | G BIGINT | G_KNOWN BIGINT |
|---|---|---|---|
| 3 | 5 | 5 | 5 |
| NULL | 5 | NULL | 5 |
Why. Engines disagree here: PostgreSQL and DuckDB skip NULL in GREATEST, while Trino, Snowflake, BigQuery and MySQL return NULL. FeatureQL picks one behaviour and keeps it on every backend. It picks propagation because a missing input should not be repaired silently into an answer. The behaviour belongs to the function name, so there is no option that changes it.
What to write instead. To ignore missing values, write ARRAY_MAX(ARRAY(a, b)), or put a default in with COALESCE first. See GREATEST .
COUNT(), COUNT(*) and COUNT(x)
What happens. COUNT() counts rows and is the canonical spelling. COUNT(*) is accepted as a permissive spelling of the same thing: /* STRICT */ refuses it and FORMAT (FIX) rewrites it to COUNT(). COUNT(x) is refused:
DEFINE
ARR := ARRAY(ROW(1 AS v), ROW(NULL::BIGINT AS v), ROW(3 AS v)),
RETURN
N_ROWS := ARR.TRANSFORM(RETURN COUNT()).UNWRAP_ONE(),
N_STAR := ARR.TRANSFORM(RETURN COUNT(*)).UNWRAP_ONE(),
N_VALUES := ARR.TRANSFORM(RETURN COUNT_IF(v IS NOT NULL)).UNWRAP_ONE();| N_ROWS BIGINT | N_STAR BIGINT | N_VALUES BIGINT |
|---|---|---|
| 3 | 3 | 2 |
DEFINE
ARR := ARRAY(ROW(1 AS v), ROW(NULL::BIGINT AS v), ROW(3 AS v)),
RETURN N := ARR.TRANSFORM(RETURN COUNT(v)).UNWRAP_ONE();Why. In SQL, COUNT(x) counts the rows where x is not NULL, and it is easily read as a row count. Each construct has one meaning in FeatureQL, so the two counts have two spellings.
What to write instead. COUNT() for rows, COUNT_IF(x IS NOT NULL) or COUNT() FILTER (WHERE x IS NOT NULL) for values. COUNT(DISTINCT x) keeps its argument. See Counting and Strictness and canonical form .
An unmatched RELATED(COUNT()) is 0, other aggregates are NULL
What happens. A customer with no orders has RELATED(COUNT()) equal to 0 and ARRAY_AGG equal to [], while SUM, AVG, MIN and MAX over the same empty set are NULL:
DEFINE
customers := ENTITY(),
orders := ENTITY(),
customer_id := INPUT(BIGINT#customers),
order_id := INPUT(BIGINT#orders),
ord := INLINE_COLUMNS(
order_id BIGINT#orders BIND TO order_id,
customer_id BIGINT#customers,
amount BIGINT
FROM JSON([
{"order_id": 101, "customer_id": 1, "amount": 10},
{"order_id": 102, "customer_id": 1, "amount": 5}
])
),
n_orders := customer_id.RELATED(COUNT() GROUP BY (ord[customer_id])),
revenue := customer_id.RELATED(SUM(ord[amount]) GROUP BY (ord[customer_id]))
RETURN
customer_id,
n_orders,
revenue,
revenue_or_zero := COALESCE(revenue, 0)
FOR
customer_id := BIND_VALUES(ARRAY(1, 2)),
NESTED order_id := BIND_VALUES(ARRAY(101, 102))
ORDER BY customer_id
;| CUSTOMER_ID BIGINT#CUSTOMERS | N_ORDERS BIGINT | REVENUE BIGINT | REVENUE_OR_ZERO BIGINT |
|---|---|---|---|
| 1 | 2 | 15 | 15 |
| 2 | 0 | NULL | 0 |
Why. A known parent with no children is an empty set, not a missing value. A count of an empty set is defined, so it is 0. SUM of an empty set is NULL, as in SQL. This keeps SUM(x) equal to ARRAY_SUM(ARRAY_AGG(x)) on every group.
What to write instead. Test "has no children" with COUNT() = 0, not IS NULL. Where a revenue of 0 is what you mean, write COALESCE(REVENUE, 0). See Absence, emptiness and errors .
SELECT 1 runs, SELECT F := 1 is refused
What happens. A request with no FeatureQL in it is SQL, and it runs on your backend as written:
SELECT 1 + 2 AS total;| total BIGINT |
|---|
| 3 |
A := makes the request FeatureQL, and SELECT is not a FeatureQL keyword:
SELECT F := 1;Why. The query endpoint and the Python client accept both languages, so SQL tools and setup scripts work unchanged. A request is FeatureQL when it carries FeatureQL (RETURN, DEFINE, CREATE FEATURES, a top-level :=, …), and SQL otherwise. Inside FeatureQL, each clause has one spelling: DEFINE and RETURN, not WITH and SELECT.
What to write instead. Write RETURN F := 1. To force a language, start the request with /* SQL */ or /* FEATUREQL */ ( Language mode ).
Changing a feature's base type means replacing its dependents too
What happens. CREATE OR REPLACE cannot change a persisted feature from one base type family to another, such as BIGINT to VARCHAR. The error says to drop the feature first, but a feature that others read cannot be dropped alone:
CREATE OR REPLACE FEATURES IN FM.TUTORIALS.SURPRISES AS
PERSIST
BASE := 'one'
;DROP FEATURES FM.TUTORIALS.SURPRISES.BASE;Why. The registry is one consistent program. Each dependent was checked against its inputs' types, and a different family can make it fail or change what it computes. A width, an entity annotation or a unit can change in place, because every dependent is checked again in the same statement. A family change is refused instead of being applied silently under the dependents.
What to write instead. Drop the feature and its dependents in one statement, then create them again with the new type. List the dependents first with IS_DOWNSTREAM_OF() ( Registry consistency ):
DROP FEATURES FM.TUTORIALS.SURPRISES.BASE, FM.TUTORIALS.SURPRISES.DEP;| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.SURPRISES.BASE | DELETED | Feature successfully deleted |
| FM.TUTORIALS.SURPRISES.DEP | DELETED | Feature successfully deleted |
CREATE FEATURES IN FM.TUTORIALS.SURPRISES AS
PERSIST
base := 'one',
dep := base || '!'
;| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.SURPRISES.BASE | CREATED | Feature created as not exists |
| FM.TUTORIALS.SURPRISES.DEP | CREATED | Feature created as not exists |
RETURN
dep
FROM FM.TUTORIALS.SURPRISES
;| FM.TUTORIALS.SURPRISES.DEP VARCHAR |
|---|
| one! |
Between the two statements the features do not exist, so run them when nothing reads the namespace. To keep the old feature running while you move, create the new one under another name and move the dependents one by one.
Next
Absence, emptiness and errors covers NULL, empty sets and runtime errors in full. Strictness and canonical form lists every permissive spelling.