Query structure
Basic query structure
WITH
-- Input definitions
INPUT_FEATURE := INPUT(BIGINT),
-- External data
-- Derived features (composition, enrichment, transformation)
SELECT
feature1,
feature2...
FOR
INPUT_FEATURE := BIND()
; sql
A FeatureQL query basic query is made of three main parts:
- The
WITHclause defines features that can be used in the query, in addition to the features already defined in the registry. These features won't necessarily be evaluated, depending on the features returned in theSELECTclause. - The
SELECTclause defines the features that will be evaluated by the query. They must all depend on the same inputs, which values are defined in theFORclause. - The
FORclause defines the values that will be bound to the inputs for evaluation. They must all be of the same type as the inputs defined in theWITHclause.
Query with filtering and ordering
WITH
-- Input definitions
INPUT_FEATURE := INPUT(BIGINT),
-- External data
-- Derived features (composition, enrichment, transformation)
SELECT
feature1,
feature2...
FOR
INPUT_FEATURE := BIND()
WHERE
condition
ORDER BY
feature1, feature2...
OFFSET m
LIMIT n; sql
You can add the following optional clauses to better control the query results:
- The
WHEREclause filters results by feature values. - The
ORDER BYclause sorts results by feature values. - The
LIMITclause restricts the number of returned rows ton. - The
OFFSETclause skipsmrows for pagination.
Notes: Grouping and unnesting are supported for analytics queries. See Grouping and unnesting for more information.
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.
@fql-playground(query_structure_proto_customers)
@fql-playground(query_structure_proto_orders)
Once you are happy with your query, we recommend you to clean the definitions to keep only the features needed for clarity.