Agree on what the report should measure
A delivery report can count shipments that arrived on time or customers who received their complete order on time. Both calculations are useful. They answer different questions, and a team needs to know which one it is looking at before judging service performance.
For this example, the business chooses complete orders delivered by the original promised date. Canceled orders are excluded. Incomplete orders remain in the count of orders the business was expected to deliver.
The source data contains four eligible orders. Two were complete by the original promise date, so the result is 50%. The runnable fulfillment guide explains every source row and supplies the model. If investment reporting is closer to your work, follow the portfolio example.
All 4 orders were due Jan 31. Snapshot: end of Feb 3. Each shipment carries one item.
-
A100
Jan 30On time Jan 31On timeComplete on time 2 / 2 items delivered
-
A101
Jan 31On time Feb 2LateComplete late 2 / 2 items delivered
-
A102
Jan 31On time PendingUndeliveredIncomplete 1 / 2 items delivered
-
A103
Jan 31On timeComplete on time 1 / 1 item delivered
This counts shipments and leaves the undelivered item out.
Every eligible order counts, including the incomplete one.
Put the definition in a model
The model author records which orders count, what “complete and on time” means, and how to calculate the percentage. The model also names the dimensions people may use to group the results, such as region.
These decisions become reusable definitions. A regional report and a company-wide report can select the same metrics without rebuilding their rules in each query. The business still owns the choice of definition and the quality of its source data.
Crossfield reads supported Apache Ossie definitions and adds rules for their use in DuckDB. The model authoring guide explains the files and their responsibilities.
Attach the model and ask a question
The fulfillment setup loads the source facts into warehouse and attaches the model as operations. The model becomes a catalog alongside the data; attachment checks its source references without copying the source rows.
ATTACH 'fulfillment-current.package.json' AS operations (
TYPE crossfield,
BINDINGS '{"warehouse":"warehouse"}'
);
SELECT region, eligible_orders, on_time_orders, on_time_percent
FROM SEMANTIC operations.fulfillment
GROUP BY region
ORDER BY region;
FROM SEMANTIC operations.fulfillment selects the model. The query chooses metrics and a grouping; the model supplies the eligibility and delivery rules. BINDINGS connects its logical source to the physical warehouse catalog.
The setup already performs this attachment. Run it once in a fresh connection, then use the query. The guide includes expected regional and overall results.
Inspect the calculation before running the report
When reviewing a model, you should be able to see how a business definition becomes a calculation. EXPLAIN (SEMANTIC) shows the selected definitions and generated SQL without running the report or calling providers.
Inspect this report and its generated SQL
Look for the original promise date, canceled-order exclusion and complete-delivery condition.
EXPLAIN (SEMANTIC)
SELECT region, eligible_orders, on_time_orders, on_time_percent
FROM SEMANTIC operations.fulfillment
GROUP BY region
ORDER BY region;
WITH "__crossfield_fact_bbd41d58-a472-44de-bd04-78121436d06b" AS (
SELECT
__cf_source_0.region AS __cf_d0,
"system".main.count(__cf_source_0.id) AS __cf_metric_0,
"system".main.sum(
CASE
WHEN (((__cf_source_0.delivered_units >= __cf_source_0.ordered_units) AND (__cf_source_0.last_delivered_date <= __cf_source_0.original_promised_date))) THEN (1)
ELSE 0
END) AS __cf_metric_1,
((100.0 * "system".main.sum(
CASE
WHEN (((__cf_source_0.delivered_units >= __cf_source_0.ordered_units) AND (__cf_source_0.last_delivered_date <= __cf_source_0.original_promised_date))) THEN (1)
ELSE 0
END)) / "system".main.count(__cf_source_0.id)) AS __cf_metric_2,
1 AS __cf_present
FROM warehouse.main.order_facts AS __cf_source_0
WHERE ((__cf_source_0.original_promised_date = CAST('2024-01-31' AS DATE)) AND (__cf_source_0.status != 'cancelled'))
GROUP BY __cf_source_0.region
)
SELECT
__cf_keys.__cf_d0 AS region,
"__crossfield_fact_bbd41d58-a472-44de-bd04-78121436d06b".__cf_metric_0 AS eligible_orders,
"__crossfield_fact_bbd41d58-a472-44de-bd04-78121436d06b".__cf_metric_1 AS on_time_orders,
"__crossfield_fact_bbd41d58-a472-44de-bd04-78121436d06b".__cf_metric_2 AS on_time_percent
FROM ((
SELECT __cf_d0
FROM "__crossfield_fact_bbd41d58-a472-44de-bd04-78121436d06b"
) AS __cf_keys
LEFT JOIN
"__crossfield_fact_bbd41d58-a472-44de-bd04-78121436d06b" ON ((__cf_keys.__cf_d0 IS NOT DISTINCT
FROM "__crossfield_fact_bbd41d58-a472-44de-bd04-78121436d06b".__cf_d0
))
)
ORDER BY __cf_keys.__cf_d0
This is captured output from the runnable example. Execute the original semantic query to keep Crossfield’s validation. The explanation reference also explains EXPLAIN (SQL), which binds and optimizes, and EXPLAIN ANALYZE, which executes.
Decide how much freedom query authors should have
Attaching a model makes its definitions available. You can leave ordinary SQL available for exploration, compose semantic results in a larger query, or require supported reporting queries to follow one model’s rules.
Checked inside DuckDB
offExplore your data
Keep ordinary SQL available for exploration and data preparation. Queries through an attached semantic catalog still follow its definitions.
- Query an attached model
- Validate the model query
- Return approved calculations
Direct source queries also remain available.
semanticCompose semantic results
Use governed semantic blocks within ordinary SQL. Compare model revisions or reconcile results while retaining the definitions inside each block.
- Use semantic query blocks
- Validate each semantic block
- Compose results with outer SQL
You own the outer calculations; they are not approved model metrics.
strictRequire the reporting rules
Require supported business queries to follow one model attachment’s policy. Reject direct source queries and unapproved calculations.
- Submit a business query
- Validate the query and its model
- ✓ Execute× Reject
The reporting contract applies to the surrounding query too.
off and semantic allow ordinary SQL; strict adds restrictions to supported business statements. These settings apply to this connection.The engine can reject a query that bypasses the reporting rules.
Crossfield uses hooks in DuckDB to check the sources and calculations a query actually resolves to. Those checks follow supported queries through aliases, CTEs and prepared statements. In strict mode, a request outside the model’s policy produces an error before execution, giving a person or AI agent a chance to repair it.
Why this requires integration with DuckDB’s engine →Use strict mode for this example
USE selects the default model catalog. The setting applies the reporting restrictions to this connection.
USE operations.semantic;
SET crossfield_mode = 'strict';
For example, strict mode can reject a calculation written directly against the source tables when the report must use the model. An application that must prevent users from changing those controls also needs to seal the connection. Host-controlled sessions describe that application boundary.
Keep the checks inside query execution
Crossfield resolves the definitions and builds a DuckDB query. DuckDB binds, optimizes and executes it in the same connection. Crossfield’s checks continue through supported query preparation and execution, including checks that require actual source rows.
- Bind & validate
- Optimize
- Execute
This engine integration is why Crossfield will ship in Haybarn, Query Farm’s DuckDB distribution. Read about the engine changes and the problems they solve.
Review a definition change before adoption
Suppose the business proposes measuring against revised delivery promises. One previously late order now qualifies. Run both model versions against the same source data to see how much that rule change affects the result.
operations.fulfillment Original delivery promise
An order is on time only if every unit arrived by the original promised date.
revised.fulfillment Revised delivery promise
Evaluate the same orders against their revised promised dates.
The reported rate rises because the delivery standard changed. No additional orders were delivered. Reviewers can measure that effect before adopting the new definition.
Whether the revised promise is appropriate is a business decision. Crossfield gives reviewers a way to examine its effect before changing the reports people use. The model versions guide walks through the comparison and explains how to keep earlier definitions available.
Combine reports that different teams maintain
Different teams can maintain separate models and combine their results through approved shared dimensions. In the investment example, the portfolio model calculates exposure while the risk model supplies limits. Their results meet at the issuer dimension.
Each model calculates its own result before the join. The models must agree on the meaning and complete grouping keys of the shared dimension; identical column names are insufficient. A missing limit remains NULL.
These comparisons use semantic or off mode. Strict business queries stay within one attachment. The query composition guide covers the SQL and join rules.