Home / Blog / Architecture

Architecture

Apache Ossie: an introduction to the open semantic layer standard

What this open format describes, and a first model on the TPC-H orders data

Apache Ossie is an open format for writing your business metrics once, in a file every tool can read, directly or through a converter. We build a first model on order data, validate it with the official tooling, and let DuckDB compute it.

Contents
  1. What Ossie is
  2. Set up
  3. Write the model
  4. Validate and compute
  5. What the spec leaves to each tool
  6. Where the project stands
  7. Key takeaways
  8. Test yourself
  9. Frequently asked questions
Apache Ossie: an introduction to the open semantic layer standard

What was revenue in the first quarter of 1995? On the TPC-H orders data, the answer depends on which column you sum:

  • o_totalprice, the order total, gives 8.55 billion, tax included;
  • l_extendedprice, the gross line price, gives 8.65 billion;
  • the same price minus each line’s discount gives 8.22 billion.

All three queries are valid, yet the highest and lowest answers are 433 million apart. In a real team, each formula lives in a different tool (a dashboard, a SQL engine, an AI agent), and nobody notices they disagree. With Apache Ossie, you write the definition once and every tool reads it.

What Ossie is

An Ossie model is a YAML or JSON file. It describes four objects:

  • a dataset points to a table through its source key;
  • a field reads a column and gives it a business name, such as gross_price for l_extendedprice;
  • a metric is an aggregate calculation over fields;
  • a relationship links two datasets through a foreign key.

Every expression is written in sql, in OSSIE_SQL_2026, the portable language the spec defines. A dialects list can add variants specific to one tool.

Here’s an excerpt from the model we’ll write, with one dataset, one field and one metric:

datasets:
  - name: line_items
    source: tpch.main.lineitem
    fields:
      - name: gross_price
        expression:
          sql: l_extendedprice
    metrics:
      - name: revenue
        expression:
          sql: SUM(gross_price * (1 - discount))

Ossie is neither an engine nor an access control system.

  • It stores no data and computes nothing. Whatever reads the file (a BI tool, a SQL engine, an AI agent) translates each definition into its own SQL. The project publishes converters in the apache/ossie-converters repository.
  • It defines metrics, but doesn’t say who’s allowed to see them.
One definition any tool can read

The spec has four layers:

  • Layer 1 defines the model format and its expression language;
  • Layer 2 says how to query it in SQL, with AGG();
  • Layer 3 queries it with a list of dimensions, metrics and a filter, the spec itself fixing the joins;
  • Layer 4 carries the ontology.

This tutorial only uses Layer 1.

Set up

You need Python 3.11 or later, git, about 400 MB of disk space, and macOS or Linux.

Get the code. The full model and both scripts are ready to download: sales.ossie.yaml, prepare.py, compute.py, and every command in commands.sh.

Step 1 · Install the official tooling

The project repository holds the validator (a Python script) and the Python SDK that reads models. The spec changes from week to week, so we pin the repository to a commit. DuckDB will serve as both the database and the tool that computes the metrics.

$ git clone -q https://github.com/apache/ossie
$ git -C ossie checkout -q aa500d3
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install -q sqlglot==30.31.0 jsonschema==4.26.0 pyyaml==6.0.3 duckdb==1.5.6 ./ossie/python
$ pip list | grep ossie
apache-ossie              0.3.0.dev0

Step 2 · Generate the orders and measure the problem

DuckDB generates TPC-H with its tpch extension, so there is no data file to download. The script builds tpch.duckdb at scale factor 1 (one and a half million orders, six million lines), then computes the quarter’s revenue the three ways.

"""Generates the TPC-H data in a DuckDB database, then computes one quarter's revenue three ways."""
import duckdb

db = duckdb.connect("tpch.duckdb")
db.sql("INSTALL tpch; LOAD tpch; CALL dbgen(sf => 1)")
quarter = "o_orderdate >= DATE '1995-01-01' AND o_orderdate < DATE '1995-04-01'"
calculations = {
    "sum of o_totalprice": f"SELECT SUM(o_totalprice) FROM orders WHERE {quarter}",
    "sum of l_extendedprice": f"SELECT SUM(l_extendedprice) FROM lineitem JOIN orders ON l_orderkey = o_orderkey WHERE {quarter}",
    "same sum, after discount": f"SELECT SUM(l_extendedprice * (1 - l_discount)) FROM lineitem JOIN orders ON l_orderkey = o_orderkey WHERE {quarter}",
}
for label, query in calculations.items():
    print(f"{label:<26}{db.sql(query).fetchone()[0]:>18,.2f}")
$ python prepare.py
sum of o_totalprice         8,545,777,729.15
sum of l_extendedprice      8,649,700,379.71
same sum, after discount    8,216,374,767.78

Generating the data takes about ten seconds. The first time, DuckDB downloads the tpch extension, so you need internet access.

Each number counts something different. o_totalprice is the order total, tax included and discount taken off. l_extendedprice is a line’s price before discount. We keep the third definition, net of discount and before tax, and write it into the model.

Write the model

Step 3 · Describe the datasets and their fields

Create sales.ossie.yaml with three datasets: customers, orders and order lines. Only the model sees the TPC-H column names, such as l_extendedprice. The metrics use gross_price.

version: 0.3.0.dev0
name: sales
description: Customers, orders and order lines from the TPC-H dataset.
datasets:
  - name: customers
    source: tpch.main.customer
    primary_key: [customer_id]
    fields:
      - name: customer_id
        expression:
          sql: c_custkey
      - name: segment
        expression:
          sql: c_mktsegment
        dimension: {is_time: false}
  - name: orders
    source: tpch.main.orders
    primary_key: [order_id]
    fields:
      - name: order_id
        expression:
          sql: o_orderkey
      - name: customer_id
        expression:
          sql: o_custkey
      - name: order_date
        expression:
          sql: o_orderdate
        datatype: Date
        dimension: {is_time: true}
      - name: total_with_tax
        description: Order total, tax included and discount taken off.
        expression:
          sql: o_totalprice
        datatype: Decimal
  - name: line_items
    source: tpch.main.lineitem
    description: One row per item ordered.
    primary_key: [order_id, line_number]
    fields:
      - name: order_id
        expression:
          sql: l_orderkey
      - name: line_number
        expression:
          sql: l_linenumber
      - name: gross_price
        expression:
          sql: l_extendedprice
        datatype: Decimal
      - name: discount
        expression:
          sql: l_discount
        datatype: Decimal
      - name: return_flag
        expression:
          sql: l_returnflag
        dimension: {is_time: false}
  • The primary key references the order_id field, not the o_orderkey column.
  • The dimension block carries the time role: is_time says whether the field is a time axis. Without it, the spec infers that role from the datatype, and Date gives a time axis. Any field can be used to group by, but some tools, such as the Python SDK, only treat the fields that carry this block as dimensions.
  • sql is written in OSSIE_SQL_2026, which starts from SQL:2003 and adds common vendor functions such as IFF or DATEADD. It’s the only language whose meaning the spec defines. An expression can also carry a dialects list, whose names are free-form: the project’s catalog, which is non-normative, lists nineteen, including ANSI_SQL and TRINO. Apart from OSSIE_SQL_2026, the spec treats them as opaque, and a tool may ignore them. If sql and an OSSIE_SQL_2026 entry both exist, sql wins.
Columns, fields, metrics

Three levels of names. The spec separates table columns, fields and metrics. A metric reads fields. It names a table column only in one specific form, source.column, which we see in step 6.

Step 4 · Write revenue once

A metric that reads a single dataset is declared inside that dataset and uses the short names of its fields. That’s a dataset-level metric: it needs no join, so there is no join to choose. Append these lines to the file, indented by four spaces because they belong to line_items.

    metrics:
      - name: revenue
        description: Revenue net of discount, before tax.
        expression:
          sql: SUM(gross_price * (1 - discount))
        datatype: Decimal
        ai_context:
          synonyms: [sales, turnover, net revenue]
      - name: returned_revenue
        description: Revenue from lines the customer sent back.
        expression:
          sql: SUM(gross_price * (1 - discount)) FILTER (WHERE return_flag = 'R')
        datatype: Decimal
  • The description of revenue settles the opening question: net of discount, before tax.
  • ai_context gives an AI agent synonyms, so it finds the metric when someone asks about “sales”.
  • FILTER (WHERE ...) is part of OSSIE_SQL_2026. Here it keeps only the returned lines.

There’s nothing to run here: the validator in step 6 reads these lines.

In a relationship, from is the “many” side and to is the “one” side: an order has many lines, a customer has many orders. A metric that crosses a relationship is a model-level metric. It goes at the top level of the file, and every field in it is written as dataset.field, even when only one dataset has that name. Append these lines to the file, with no indentation.

relationships:
  - name: line_items_orders
    from: line_items
    to: orders
    from_columns: [order_id]
    to_columns: [order_id]
  - name: orders_customers
    from: orders
    to: customers
    from_columns: [customer_id]
    to_columns: [customer_id]
metrics:
  - name: avg_order_value
    description: Average revenue per order.
    expression:
      sql: AGG(line_items.revenue) / COUNT(DISTINCT orders.order_id)
    datatype: Decimal
  • Despite their names, from_columns and to_columns name fields. On the to side, they must form the primary key or a unique key.
  • AGG(line_items.revenue) reuses the metric from step 4: the revenue formula is written only once. AGG only takes a dataset-level metric, written dataset.metric, and no FILTER.
  • In OSSIE_SQL_2026, / is true division: 5 / 2 is 2.5. An engine that truncates integer division, such as Trino, has to evaluate an equivalent expression, for example with a CAST to DECIMAL.

Again, there’s nothing to run: the next step reads these lines.

Validate and compute

Step 6 · Validate the model

The official validator checks the structure against the JSON Schema, looks for duplicate names, resolves the names that keys, relationships and metrics refer to, and checks the SQL syntax.

$ python ossie/validation/validate.py sales.ossie.yaml
Validation PASSED: sales.ossie.yaml

A column instead of a field

We replace gross_price with the l_extendedprice column in the revenue metric. The validator rejects it.

$ sed '1,/SUM(gross_price/s/SUM(gross_price/SUM(l_extendedprice/' sales.ossie.yaml > column-test.yaml
$ python ossie/validation/validate.py column-test.yaml
Validation FAILED with 1 error(s):

  [Scope] Dataset-scoped metric 'line_items.revenue' in model 'sales' (OSSIE_SQL_2026) references undeclared field(s) 'l_extendedprice'. A dataset-scoped metric may reference only the dataset's declared fields, and its source columns as source.column.

The message gives the fix: name the table column as source.column.

$ sed '1,/SUM(gross_price/s/SUM(gross_price/SUM(source.l_extendedprice/' sales.ossie.yaml > source-test.yaml
$ python ossie/validation/validate.py source-test.yaml
Validation PASSED: source-test.yaml

A qualified name such as line_items.gross_price is still rejected in a dataset-level metric.

A column in a relationship

A key or a relationship must name fields. Here, from_columns gets a table column.

$ sed 's/from_columns: \[order_id\]/from_columns: [l_orderkey]/' sales.ossie.yaml > relation-test.yaml
$ python ossie/validation/validate.py relation-test.yaml
Validation FAILED with 1 error(s):

  [Reference] Relationship 'line_items_orders' in model 'sales': from_columns references undeclared field 'l_orderkey'. from_columns must be field names of the from dataset 'line_items'.

An unqualified name

In the average order value, we write order_id without its dataset. The spec forbids it, but the validator only prints a warning.

$ sed 's/COUNT(DISTINCT orders.order_id)/COUNT(DISTINCT order_id)/' sales.ossie.yaml > name-test.yaml
$ python ossie/validation/validate.py name-test.yaml
  [Reference] Warning: Metric 'avg_order_value' in model 'sales' (OSSIE_SQL_2026): 'order_id' is not qualified; metric expressions refer to fields as dataset.field
Validation PASSED: name-test.yaml

The warning is printed before the Validation PASSED line, and the exit code stays 0. In a script, read the output, not just the exit code. A column named in a model-level metric, such as line_items.l_extendedprice, also gets only a warning.

A variant for Trino

An expression can add a variant for one tool, next to sql. This command adds a TRINO entry to the gross_price field.

$ awk '{print} /^          sql: l_extendedprice$/ {print "          dialects:"; print "            - dialect: TRINO"; print "              expression: l_extendedprice"}' sales.ossie.yaml > trino-test.yaml
$ python ossie/validation/validate.py trino-test.yaml
Validation PASSED: trino-test.yaml

TRINO has been in the dialect catalog since 30 October. The catalog is non-normative, and for the spec a TRINO expression stays opaque. The validator reads it as Trino SQL.

Step 7 · Compute the metrics as a tool would

Now we act as the tool. The script reads the model with the SDK, exposes each dataset’s fields in a subquery, then computes each dataset-level metric on DuckDB.

"""Computes the metrics of each dataset in an Ossie model, on a DuckDB database."""
import sys

import duckdb
from ossie import OssieDocument

model = OssieDocument.from_ossie_yaml(open(sys.argv[1]).read())
db = duckdb.connect(sys.argv[2])


def sql(expression):
    # `sql` is the portable form and wins. Without it, we read the OSSIE_SQL_2026 entry of dialects.
    if expression.sql:
        return expression.sql
    return next(d.expression for d in expression.dialects if d.dialect == "OSSIE_SQL_2026")


for dataset in model.datasets:
    # Fields are the dataset's interface: every metric reads them.
    # This script doesn't handle source.column, which the spec also allows in a dataset-level metric.
    fields = ", ".join(f"{sql(field.expression)} AS {field.name}" for field in dataset.fields)
    for metric in dataset.metrics or []:
        query = f"SELECT {sql(metric.expression)} FROM (SELECT {fields} FROM {dataset.source})"
        print(f"{dataset.name}.{metric.name} = {db.sql(query).fetchone()[0]}")
$ python compute.py sales.ossie.yaml tpch.duckdb
line_items.revenue = 218102223885.0001
line_items.returned_revenue = 53741292684.6040
  • These numbers cover the full history, from 1992 to 1998: the script doesn’t filter.
  • For the quarter, you filter on order_date, which lives in orders, so you join line_items to orders along line_items_orders, as in step 2. Our script doesn’t join: that’s the job of an engine that implements the spec’s query layers.

Note. Layer 1 doesn’t say how to compute a metric that spans datasets: Layers 2 and 3 do. In Layer 2, the tool writes its own joins in SQL, and AGG() evaluates each metric without double counting. In Layer 3, you ask for dimensions, metrics and a filter, and the spec fixes the choice of joins: a conforming engine rejects an ambiguous path instead of guessing. The quarter is requested like this: {"metrics": ["line_items.revenue"], "filter": "orders.order_date >= DATE '1995-01-01' AND orders.order_date < DATE '1995-04-01'"}.

A real tool also has to translate OSSIE_SQL_2026 into its own SQL, which this tutorial doesn’t do. The next article looks at the pitfalls of that translation on Trino.

What the spec leaves to each tool

What Ossie describes, what it leaves to tools
  • Access rights, row filters and column masks. Layer 2 says their effect on metric evaluation is “recognized but not addressed”.
  • Identity. No field ties a metric to a user or a group. The roadmap plans access control for models stored in a catalog, not for the data they describe.
  • Personal data. The contains_personal_data and is_confidential attributes are not part of the format. They remain on the roadmap (issue 58, issue 59).

If only finance should see your revenue figure, write that rule in the engine or the catalog.

Where the project stands

The project used to be called Open Semantic Interchange (OSI). It has been in the Apache Incubator since June 2026.

  • There is no Apache release yet. The only version the spec history marks as released is 0.1.1, from December 2025, published under the former name. The version in development is 0.3.0.dev0, and the next planned release will be called 0.3.0-incubating. The spec warns that it may still change and advises against relying on it in production.
  • The dialect name has been free-form since 26 October, and the portable expression is written in sql. TRINO entered the non-normative catalog of dialects on 30 October.
  • Compared with 0.1.1, several changes break compatibility: a single model per document, placed at the top level of the file, custom_extensions renamed nonportable_extensions, and field names, no longer column names, in keys, relationships and metrics.

Key takeaways

  • A loosely defined revenue metric allows several correct but incompatible answers: 433 million apart on our quarter.
  • Metrics read fields, fields read columns. Write the formula in a dataset-level metric, then reuse it with AGG in a model-level metric.
  • The validator rejects a bare column in a dataset-level metric, in a key and in a relationship. For an unqualified name in a model-level metric it only prints a warning: read its output.
  • Ossie computes nothing and enforces no access rules: the tool translates, joins and controls access.

Test yourself

1. Does Ossie compute your metrics?

No. A tool reads the file, then computes with its own engine, the way our script does with DuckDB.

2. Why write orders.order_id rather than order_id in the average order value?

The average order value is a model-level metric: the spec requires dataset.field for every field, even without ambiguity. Here, order_id exists in both line_items and orders. The validator doesn’t reject the model, it prints a warning before Validation PASSED, but the model isn’t conforming.

3. Can a metric read the l_extendedprice column?

Not under that name. It reads the gross_price field. In a dataset-level metric you can also name the source column, written source.l_extendedprice; a bare column is rejected there. In a model-level metric, the spec forbids it too, but the validator only prints a warning.

Frequently asked questions

What is Apache Ossie?

An open format, in YAML or JSON, that describes a semantic model: datasets, fields, metrics and relationships. It lets BI tools, SQL engines and AI agents share the same definitions, such as the definition of revenue.

What is the current version of Ossie?

The only version the spec history marks as released is 0.1.1, from December 2025. The version in development is 0.3.0.dev0, unreleased: it may still change. The next planned release is 0.3.0-incubating. There is no Apache release yet.

How do I validate an Ossie model?

With the validation/validate.py script from the apache/ossie repository. It rejects a bare column in a dataset-level metric, in a key and in a relationship. For a doubtful reference in a model-level metric, it only prints a warning.

Is Trino a dialect of Apache Ossie?

TRINO has been in the project's dialect catalog since 30 October 2026. The catalog is non-normative. The spec only defines OSSIE_SQL_2026, and a TRINO expression is opaque to it. The official validator checks its syntax as Trino SQL.

Does Ossie handle access rights on metrics?

No. The spec describes no access rights, no identity and no filtering of rows by user: it recognizes the subject without addressing it. Those rules stay in the engine and the catalog.

Share this articleReact on LinkedIn ↗
Abderrahmen Dridi
AKKO, a sovereign data & AI platform project

Designs AKKO. Writes about Trino and data governance.