Schema definition
Write, validate, and publish the schema that defines what your datamart indexes.
Your goal
Declare the objects and properties of your datamart, index the ones you will query on, and publish the result without breaking what already works.
Expected outcome
A LIVE schema on your datamart in which every property your use cases need is present, and the properties used in WHERE clauses are indexed.
What a schema is
A schema is applied to a datamart and defines what mediarithmics should index and make available through queries. It defines the model according to which your data is stored and queried.
Each schema is a GraphQL schema defining an object tree index, which is what allows fast OTQL queries over the whole graph. Being strongly typed is what unlocks the tooling around it.
Schemas can evolve: a new schema replaces the previous one without losing historical data, because the platform records all events it receives in a separate database. Changing the schema changes what is indexed, not what is stored.
Reading your current schema
You do not have to work blind:
The advanced segment builder shows a simplified view of your schema containing only the indexed fields, which you can expand and collapse.
The schema itself is defined and amended in your datamart settings.
The default objects
A default schema declares every available mediarithmics object with its standard properties. Start from it and add or remove properties based on your needs and the data you ingest.
Each of these objects is described in Understand mediarithmics standard objects.
Types and syntax
The ! operator
! marks an element as mandatory - it is expected not to be null.
Basic types
ID, String, Int, Boolean, Timestamp, and Date are available. ID is treated as a keyword string, but marks data that is not meaningful to a human because it is an identifier.
Timestamps and dates
Import objects carrying dates as Timestamp, and generate a Date from the timestamp with the ISODate function when you want it displayed as a date and time in queries or exports.
Both types work with date operators in queries. Use only one @TreeIndex directive when deriving a date from a timestamp - index the timestamp, not the function result. It saves index space, and both types have the same query capabilities.
Directives
Directives are how you tell the platform what to do with a property.
@TreeIndexRoot(index:"USER_INDEX")
Marks the root element of the object tree index. Always USER_INDEX; multiple indexes are not currently supported.
@TreeIndex(index:"USER_INDEX")
Makes a field available in WHERE clauses and in aggregation operations. Fields without it can still be retrieved in SELECT.
@Property(path:...) / @Property(paths:[...])
Changes the path a property reads from. Several paths can be given: if the first is empty, the next is used.
@Mirror(object_type:..., filter:...)
Creates a custom type based on a predefined one, optionally filtered.
@Function(name:..., params:[...])
Declares a calculated field using a predefined function.
@ReferenceTable(type:"CORE_OBJECT", model_type:...)
Gives query builders an autocomplete on names instead of IDs, for channels, compartments, and segments.
@EdgeAvailability
Marks a property as usable in Edge segment queries.
@ComputedField(technical_name:...)
Marks a property as calculated by a computed field function.
@UpdateStrategyKey
Enables targeted updates on objects that have an ID property inside a UserProfile.
@UpdateValueObject
Enables targeted updates on objects without an ID property inside a UserProfile.
@TreeIndex, and how strings are indexed
Do not mark every field with @TreeIndex. Fields such as first name or last name will never be used in a WHERE clause and would only make the index larger.
When indexing a String, choose how it is indexed:
The value is treated as a set of words. The QUICK brown fox JuMpS, over the Lazy doG. becomes the, quick, brown, fox, jumps, over, lazy, dog.
These transformations happen: words are lowercased - so all string operators are case-insensitive on a text field - and the string is split, with the splitting characters removed.
Characters that commonly trigger a split include space, -, ", ', ,, ;, ?, !, and /. Characters that do not trigger a split include ., _, and apostrophes.
Use text for full sentences such as page titles, URLs, lists of keywords, and similar content - generally when you do not fully control the value and want broad queries on it.
The value is treated as a single word, with no transformation applied.
Use keyword for single values, IDs passed as text such as UUIDs, product IDs or category IDs, and any field whose values you already know - for instance because they come from a taxonomy.
Generally: when you control the value and want exact equality in queries.
@Property
By default the path of a property is its own name. @Property changes that - most usefully to lift properties out of a nested $properties object so they are easier to query.
Properties in the default schema already redefine their path - creation_ts on UserPoint points at $creation_ts without you declaring it. Properties that do not exist in the default schema, such as those of a custom Product object, do need the directive.
Other capabilities:
Several paths.
channel_id: String @Property(paths:["$site_id", "$app_id"])- a user activity's channel ID is the site ID or the app ID depending on context.The
[parent]token, to go up the object tree:@Property(path:"[parent].[parent].$origin.$creative_id").
@Mirror
Used with a filter, @Mirror gives you typed collections per event kind:
Renaming a type without a filter is possible but should be avoided - it adds no capability.
@Function
ISODate
Creates a Date from a Timestamp: creation_date: Date! @Function(name:"ISODate", params:["creation_ts"]).
ThirdPartyCookieMappings
Retrieves third-party cookie mappings for a device point. It works on device points carrying a device technical ID of type MUM_ID, translates that into a vector_id, and returns the attached partners' third-party cookies.
DeviceInfo
Legacy. Extracts device information for an agent identifier. Only for datamarts still referencing the legacy UserAgent type; on datamarts using UserDevicePoint, use ThirdPartyCookieMappings.
Publishing a schema
A schema has a status - DRAFT, LIVE, or ARCHIVED - and only one draft can exist at a time.
Create a draft, by cloning
Cloning the current LIVE version is the preferred method: it keeps all the settings of the previous version, such as cluster versions and index sizes.
Creating a draft without cloning is possible with POST /v1/datamarts/:datamartId/graphdb_runtime_schemas, but then the initial settings are not carried over - only do this if you know the settings you need and can set them before publishing.
Either call fails if a draft already exists.
Reading schemas: GET .../graphdb_runtime_schemas returns all schemas and their status - archived ones included, so you keep a history - GET .../graphdb_runtime_schemas/:schemaId returns one, and GET .../graphdb_runtime_schemas/:schemaId/text returns its content.
What happens when you change a schema
This is the part worth reading twice.
Add any property
Immediately usable in the SELECT part of your OTQL queries, and with any operator that does not require indexing.
Add an indexed property - a new property with @TreeIndex, or @TreeIndex added to an existing one
Only new elements entering the datamart are indexed. WHERE queries and operators needing indexing run, but return nothing for elements already stored.
Remove an indexed property
You instantly stop being able to run WHERE queries and indexed operators on it.
Decorators: changing how the schema reads
Decorators let you rename fields for display, or hide them from users, without altering the technical schema. They affect the Advanced Segment Builder and the Query Tool.
They are defined as a CSV file with these columns:
OBJECT_NAME
The object where the property is located.
FIELD_NAME
The original technical name of the property.
HIDDEN
true or false - whether the field is hidden in the interface.
LABEL
The user-friendly name shown in the Segment Builder and Query Tool.
HELP_TEXT
A short description shown as a tooltip.
LOCALE
Currently must be en-US.
Use a comma as separator, and double quotes around strings containing commas.
Manage them in Settings > Datamart > Object View Configuration, where you can upload new decorators - which overwrites the existing ones - download a blank template, download the active file, or delete it, in which case the schema reverts to raw technical names and hidden fields become visible again.
Or by API:
Best practices
Index the timestamp, not the derived date. Put
@TreeIndexoncreation_ts, not on theISODateresult.Do not duplicate
UserEvent. Declaring events both on theUserPointand insideUserActivityis only justified in specific scenarios - for instance using frequency directives on events while also querying several events within a single activity. Otherwise pick one.Index deliberately. Every indexed property costs query performance and index size.
Avoid
!outside the predefined properties, or one null value silently drops the whole object from the index.
Verify
Validation returns no schema errors before you publish.
Every property used in a
WHEREclause by your use cases carries@TreeIndex.A test OTQL query on each new indexed property returns results for data arriving after publication.
If you need history on a new indexed property, a reindexing has been requested.
Related pages
Last updated
Was this helpful?