Products

How a Data Agent Understands Average Order Value

From business phrase and population to numerator, denominator, time, grain, and metric contract: why semantics must precede SQL.

Products #Data Agent#Alibaba Cloud#DataWorks#Semantic Layer#Metrics

Semantic contract from business phrase to query

“What is average order value by category over the last 30 days?” A model can easily produce valid SQL and an invalid business answer. Average order value may be paid amount divided by paid orders, exclude refunds, use buyers as the denominator, or count only fulfilled orders.

This is not primarily a SQL problem. The phrase has not yet been bound to executable meaning.

A metric needs at least five constraints

Entity and cohort define who is counted. Numerator and denominator define the formula. Time specifies event time, window, and timezone. Grain determines whether aggregation occurs by order, customer, or item. Effective dates and versions state when the definition applies.

The metric name is only an entry point. The metric contract is the executable object. It should also carry legal joins, default filters, null behavior, an owner, validation queries, and known exceptions.

Why code and metadata both matter

Transformation code contains real derivations, filters, and join logic. Table metadata describes fields, partitions, and lineage. Together they can produce a semantic-model draft for business and data owners to review. Schema alone rarely reveals an implicit condition such as “paid and not cancelled.”

The relevant DataWorks direction is notable because it places semantic generation between data development and analytical workflows. Semantics become constraints loaded by the agent, not a document sitting beside the system.

A generated model still needs tests

Editable YAML or another semantic format is only a carrier. Before release, test known questions against trusted queries: do synonyms bind to one metric, boundary dates agree, joins preserve grain, and new versions preserve expected historical results?

A practical minimum loop starts with ten frequent metrics, extracts code and metadata, generates a draft, obtains owner approval, and stores the result in a versioned semantic repository. Every query records the metric version. Corrections become new tests rather than temporary prompt patches.

A data agent understands “average order value” not because the model has seen the phrase, but because the phrase resolves to an owned, versioned, and verifiable computation contract.

Reference: Alibaba Cloud DataWorks documentation