DMDL Reference

Mapping

Mappings define how source data from your operational databases maps to your Daana data model.

Mapping Structure

A mapping file connects source tables to a single entity in your model. It has four main components:

  1. Entity target - Which entity this mapping populates
  2. Mapping groups - Container for table mappings (typically one group)
  3. Tables - Source tables with column-to-attribute mappings
  4. Relationships - How this entity connects to other entities (foreign keys)

The examples on this page are excerpts from the bookstore example project's dab/mappings/ directory, with the connection profile named duckdb. This is the first source table of the customer mapping:

entity_id: customer

mapping_groups:
  - name: default_mapping_group
    tables:
      # Source 1: CRM data, core customer records with full status change history
      - connection: duckdb
        table: stage.customers
        primary_keys:
          - customer_id
        ingestion_strategy: FULL_LOG
        # Default effective timestamp for this table's attributes
        entity_effective_timestamp_expression: updated_at
        attributes:
          - id: customer_id
            transformation_expression: customer_id
          - id: customer_name
            transformation_expression: CONCAT(first_name, ' ', last_name)
          - id: customer_email
            transformation_expression: email
          - id: customer_status
            transformation_expression: account_status

    relationships:
      - id: customer_registered_at_location
        source_table: stage.customers
        target_transformation_expression: registration_location_id

Within one mapping, each group name is used once, each relationship id once per group and each attribute id once per table, compared case-insensitively: daana check mapping reports a repeat, naming the item and its group or table.

Every key in a mapping file must be one the format defines, in the place it belongs. A key that is unknown or in the wrong place is an error, never silently ignored: daana check reports it with its file and line, and daana deploy refuses the mapping. When the key belongs somewhere else, the message says where (relationships belongs to a mapping group, not to a table); when it looks like a misspelling, it suggests the key you meant (did you mean "batch_expression"?). The keys each level accepts are listed in the Quick Reference.

A mapping file holds one YAML document. A second document after a --- line is an error, never silently ignored: daana check reports it with its file and the line where it starts, and daana deploy refuses the mapping. Put each entity's mapping in its own file. A --- at the start of the file, or at the end with nothing after it but comments, is fine.

Casing convention. Throughout the mapping examples, entity ids, relationship ids and attribute ids use lower_snake_case, as in the bookstore project, so they line up with the lowercase objects and columns Daana generates (view_customer, customer_name). Ids in a mapping must match the model as written, casing included.

Tip: Always use schema.table format (e.g., stage.customers, stage.sales_orders) to avoid ambiguity across database schemas.

Composite and Computed Primary Keys

primary_keys accepts two forms. The simple form is a list of one or more source column names; that is what the generator emits and what most mappings use:

primary_keys:
  - customer_id

When the source has no single column that uniquely identifies a row, you can use a SQL expression directly. The expression is evaluated against the source table on every read, and its result is the natural-key string from which Daana derives the entity key. In stage.sales_order_lines, order_line_id is a line number within the order (1, 2, 3), so the order line mapping combines it with the order id:

# Composite key: order_line_id is only unique within an order
primary_keys:
  - "order_id || '-' || order_line_id"

With this expression, line 2 of order 6 gets the order_line_key 6-2. Write a composite key as one expression. A primary_keys list with more than one entry declares alternative identifiers, which requires allow_multiple_identifiers: true (see Multiple Identifiers). Without it, daana deploy refuses the mapping (specifies multiple primary keys but allow_multiple_identifiers is false).

In tutorial chapter 5, you choose this key for order_line (The order line).

Stability matters. Daana derives <entity>_key deterministically from the natural-key value the expression returns for each row. Two expressions that produce the same string for the same row (for example CONCAT(a, '-', b)) yield the same surrogate keys. Changing the expression so that it returns a different string (for example dropping a separator, or changing the order of columns) does change every surrogate key, so treat any change to the value shape the same way you would treat changing a primary-key column.

Ingestion Strategies

The ingestion_strategy field determines how Daana loads data from your source table. Choose based on your data characteristics:

StrategyBest ForDescription
FULLSource has current state only (1 row per entity), small enough to scan each runComplete snapshot of all data for each delivery
FULL_LOGSource already contains history (N rows per entity), small enough to scan each runComplete history of all changes, with multiple rows per instance
INCREMENTALSource is mutable (rows can be updated in place) and large enough that watermarked reads pay offOnly changed or new data since last load (requires watermark column)
TRANSACTIONALSource is an append-only event log (rows are written once and never updated)Append-only data where each instance is delivered exactly once

For narrative coverage of when to pick each strategy, walked through with a real source for every choice, see Tutorial Chapter 4: Loading strategies. For per-attribute overrides (e.g., INCREMENTAL table with a FULL_LOG attribute), see Advanced Mapping Patterns.

Effective Timestamps

Daana keeps history for every mapped attribute and adds a history row when a mapped value changes. Where the mapping states an effective timestamp expression for an attribute, that expression dates the attribute's history rows. Instead of manually creating timestamp entries in your mapping, use the DRY expression fields.

Daana processes in UTC. Map effective and precedence timestamps in UTC. Timestamps in local time are the mapping author's responsibility: the processing time that Daana stamps where a mapping states no timestamp, where an expression yields NULL, or where FULL cannot date a change from its source, is UTC, and a local timestamp ahead of UTC lies after it.

entity_effective_timestamp_expression

Set a default timestamp expression at the table level for every attribute mapped from that table:

tables:
  - connection: duckdb
    table: stage.customers
    primary_keys:
      - customer_id
    ingestion_strategy: FULL_LOG

    # Default for every attribute mapped from this table
    entity_effective_timestamp_expression: updated_at

    attributes:
      - id: customer_name
        transformation_expression: CONCAT(first_name, ' ', last_name)
      - id: customer_email
        transformation_expression: email

Every attribute of this table block uses the CRM's updated_at column for its effective timestamp unless it has an expression of its own. The expression can be any SQL expression. For a FULL source, map its load time; see Dating a FULL source.

attribute_effective_timestamp_expression

Override the table default for specific attributes that need a different timestamp source:

tables:
  - connection: duckdb
    table: stage.products
    primary_keys:
      - product_id
    ingestion_strategy: FULL_LOG

    # Default timestamp expression
    entity_effective_timestamp_expression: updated_at

    attributes:
      - id: book_title
        transformation_expression: title
        # Uses entity default: updated_at

      - id: book_status
        transformation_expression: >-
          CASE WHEN discontinued_date IS NOT NULL THEN 'Out of Print'
               WHEN publication_date > CURRENT_DATE THEN 'Preorder'
               WHEN is_active THEN 'In Print'
               ELSE 'Inactive' END
        # Override: a discontinued book is out of print from its discontinued date
        attribute_effective_timestamp_expression: COALESCE(CAST(discontinued_date AS TIMESTAMP), updated_at)

The override on book_status is an example edit; the bookstore's book mapping has no attribute override. In that mapping, each table sets its own default. The catalog attributes from stage.products take updated_at. The price group from stage.product_pricing takes CAST(effective_date AS TIMESTAMP): a price becomes effective at the start of its price period, not when the catalog record was last updated.

When to use each

ScenarioUse
Same timestamp for all attributesentity_effective_timestamp_expression only
Most attributes share a timestamp, some differBoth (entity default + attribute overrides)
Each attribute has a unique timestampattribute_effective_timestamp_expression on each

An attribute with effective_timestamp: true in the model needs one of the two expressions on the table that maps it. daana check and daana deploy refuse the mapping otherwise, checking each table on its own: an expression on one table does not date an attribute mapped from another.

An attribute without the flag takes the table's entity_effective_timestamp_expression, else the processing time. A relationship takes its relationship_effective_timestamp_expression, else the table's entity_effective_timestamp_expression, else the processing time. A relationship needs no model flag for it. See Relationship Options.

A stable time for FULL_LOG, INCREMENTAL and TRANSACTIONAL

FULL_LOG, INCREMENTAL and TRANSACTIONAL order the rows of one instance by their effective timestamp. The processing time is the same for every row of one read and new on every read, so it orders nothing, and FULL_LOG stores the whole log again on each read. daana check and daana deploy therefore refuse a table with one of these strategies, an attribute overridden to one of them, or a relationship read with one of them, when the processing time would be its effective timestamp. Map entity_effective_timestamp_expression on the table to the source's stable change or business time. A table needs none only when no statement read from it under one of these strategies would take the processing time: each such attribute has effective_timestamp: true and its own attribute_effective_timestamp_expression, or is overridden to FULL, and each such relationship has its own relationship_effective_timestamp_expression. FULL reads one delivery, one row per instance, and may take the processing time.

The expression mapped to the effective timestamp must give a source row the same value on every read, and give the rows of one key distinct values. Never map CURRENT_TIMESTAMP, NOW(), CURRENT_DATE or another value computed at read time. daana check and daana deploy accept such expressions.

  • Under FULL_LOG, Daana compares each log row with the row stored at the same effective timestamp. A value computed at read time gives every row a new effective timestamp on every read, so each run closes the stored rows and stores the whole log again.
  • Under INCREMENTAL, Daana compares each row with the latest row stored before it, so a row read again unchanged is not stored again. But with a value computed at read time, all rows of one key in a batch get the same effective timestamp and have no order between them. PostgreSQL and DuckDB refuse the load. On BigQuery and Snowflake, which row is kept is not defined. The history is also dated by when Daana read the rows, not by when they changed.

Dating a FULL source

Date a FULL source by a date that moves forward with the data: one that is never set back and that a late-arriving row cannot fall behind. The simplest are the dates the process sets: the as-of, extraction or landing date that every row of one delivery shares. A business date works only where it changes whenever the data it dates changes. An order's order_date is set once: it can date the order_date attribute, but as the entity's effective timestamp it gives every later change of the order the same date, and a change stored at the same effective and precedence time is a correction that replaces the earlier value, not a new point in its history.

In the bookstore, the order lines are dated by ingested_at, each line's load time, and the time the order was placed is the value of the line's order_line_purchase_ts, which a mapping reads from the order header with a correlated subquery. The FULL relationship source stage.order_promotions is dated by its delivery, popln_tmstp, which all the rows of one order share.

Precedence Timestamps

A precedence timestamp states when the source sent a value. Of the values stored for one attribute of one entity at the same effective timestamp, the views show the latest-sent one as current, and the others stay in the descriptor table as history. Map it only where a source sends more than one value at one effective timestamp; most tables need none. For when to map it and which source column to choose, see Precedence Timestamps in Advanced Mapping Patterns. For the model flag, see Ordering Values Sent for One Effective Time.

entity_precedence_timestamp_expression

Set a precedence expression for every attribute and relationship read from the table:

tables:
  - connection: dev
    table: stage.order_events
    primary_keys:
      - order_id
    ingestion_strategy: FULL_LOG

    entity_effective_timestamp_expression: status_changed_at
    # When the order system sent each row
    entity_precedence_timestamp_expression: sent_at

    attributes:
      - id: order_status
        transformation_expression: status

attribute_precedence_timestamp_expression

Override the table's precedence expression for one attribute. The attribute, or its group, must have precedence_timestamp: true in the model:

    attributes:
      - id: order_status
        transformation_expression: status
        # When the order system sent this status
        attribute_precedence_timestamp_expression: status_sent_at

daana check mapping reports invalid-precedence-tmstp-expression when the key is on an attribute without precedence_timestamp: true, and conflicting-precedence-tmstp-expression when the members of one group state different expressions in one table.

How the precedence is resolved

Daana resolves each attribute's and each relationship's precedence when it compiles the mapping:

Mapped itemPrecedence
Attribute with precedence_timestamp: trueits attribute_precedence_timestamp_expression, else the table's entity_precedence_timestamp_expression; with neither, the mapping is refused
Any other attributethe table's entity_precedence_timestamp_expression, else the attribute's effective-timestamp expression
Relationshipits relationship_precedence_timestamp_expression, else the table's entity_precedence_timestamp_expression, else its relationship_effective_timestamp_expression, else the table's entity_effective_timestamp_expression
No expression at allthe processing time, as for the effective timestamp

On a table that states no precedence expression, the attributes without precedence_timestamp: true and the relationships that state no precedence expression of their own therefore order their values by the effective timestamp alone: each such value's PRECEDENCE_TMSTP equals its EFF_TMSTP. A row whose precedence expression yields NULL gets the processing time.

For an entity with a precedence_timestamp: true attribute, daana generate mapping writes the line # entity_precedence_timestamp_expression: <source column>, commented out, in the table; with --verbose it also writes a hint above that line. Set the key, or the attribute's key, to a source column before you check or deploy the mapping.

The precedence expression must give a row the same value on every read, and a relationship's precedence must be the same for every row of one delivered set. See The value must be stable.

Row Status

A row-status expression states, for each source row, whether it is active or ends what it carries. Map one when the source marks rows it has deleted or deactivated, such as a CDC stream's delete markers, an is_active flag or a tombstone. Daana loads such a row as an end: the views no longer show the values and links it names from its effective timestamp on, and the history keeps the end. Without an expression every row is active.

entity_row_status_expression

Set a row-status expression for every attribute and relationship read from the table. The expression yields 'N' for a row that ends what it carries, and 'Y' or NULL for an active row:

tables:
  - connection: duckdb
    table: stage.user_accounts
    primary_keys:
      - user_id
    ingestion_strategy: FULL_LOG
    entity_effective_timestamp_expression: updated_at
    # A deactivated account ends its attributes at its updated_at
    entity_row_status_expression: CASE WHEN NOT is_active THEN 'N' END

Daana reads the expression as COALESCE((<expression>), 'Y'), so a NULL result is an active row.

attribute_row_status_expression and relationship_row_status_expression

Override the table's expression for one attribute, or for one relationship entry:

    attributes:
      - id: user_account_last_login_ts
        transformation_expression: last_login
        # This attribute ends only when the login record is purged
        attribute_row_status_expression: CASE WHEN login_purged THEN 'N' END

A group of attributes, such as an amount and its currency, has one row status per table: Daana loads a group's members together. An expression stated on one member applies to every member, and daana check mapping reports conflicting-row-status-expression when members state different ones.

What an end does

StrategyAn ended row
INCREMENTALends the value from its effective timestamp. An end sent again writes nothing, a value after it starts again, and a row that arrives later with an earlier effective timestamp does not undo it. The row is loaded even when its attribute values are NULL, as a delete marker's often are
FULLends the key's current value. For a key with no current value it writes nothing
FULL_LOGis written as an end at its own effective timestamp. Read again on the next run, it writes nothing
TRANSACTIONALnot allowed: daana check mapping reports row-status-on-transactional, because a transactional row is an event that nothing ends

For relationships:

  • A relationship read per target (ONE_TO_MANY) or per row (MANY_TO_ONE, ONE_TO_ONE) ends the pair the row names.
  • A relationship read as sets (MANY_TO_MANY, or no cardinality) still needs whole sets from its source. An ended row is not a member of its set, and a set whose rows are all ended ends the driving key's members.

An ended relationship row must name its target: a row whose target expression yields NULL is not read as a link, so it ends nothing. A delete marker that carries no target ends the attributes it maps, not the relationships.

An end closes attributes and relationships. The entity's key and identifiers stay.

Transformation Expressions

Transformation expressions define how to extract and transform data from source columns. These expressions use the SQL dialect of the target database, so syntax varies by platform (DuckDB, PostgreSQL, Snowflake, BigQuery).

Note: The examples below come from the bookstore mappings and run on DuckDB, whose syntax is close to PostgreSQL. Consult your database documentation for platform-specific functions and operators.

Direct Column Mapping

- id: customer_email
  transformation_expression: email

SQL Functions

- id: customer_name
  transformation_expression: CONCAT(first_name, ' ', last_name)

- id: book_publication_ts
  transformation_expression: CAST(publication_date AS TIMESTAMP)

Concatenation

- id: order_line_id
  transformation_expression: "order_id || '-' || order_line_id"

Literals

A quoted SQL literal sets a constant value. stage.product_pricing has no currency column, so the book mapping sets the currency of the list price to USD:

- id: book_list_price_currency
  transformation_expression: "'USD'"

Multiline Expressions

For complex SQL expressions like CASE statements, subqueries, or nested function calls, use YAML's multiline syntax. This makes your mappings much more readable.

Folded Style (>)

The folded style (>) joins lines with spaces, ideal for SQL that would normally be written on one line:

- id: order_size
  transformation_expression: >
    CASE WHEN total_amount >= 100 THEN 'LARGE'
         WHEN total_amount >= 50  THEN 'MEDIUM'
         ELSE 'SMALL' END

Literal Style (|)

The literal style (|) preserves line breaks exactly, useful when formatting matters:

- id: book_publisher
  transformation_expression: |
    (SELECT pb.publisher_name
     FROM stage.publishers pb
     WHERE pb.publisher_id = products.publisher_id)

Multiline with Modifiers

You can add modifiers to control trailing newlines:

IndicatorDescription
> or |Default: single trailing newline
>- or |-Strip: no trailing newline
>+ or |+Keep: preserve all trailing newlines
# Strip trailing newline with >-
- id: book_status
  transformation_expression: >-
    CASE WHEN discontinued_date IS NOT NULL THEN 'Out of Print'
         WHEN publication_date > CURRENT_DATE THEN 'Preorder'
         WHEN is_active THEN 'In Print'
         ELSE 'Inactive' END

Practical Examples

Complex CASE expression (the source holds language names; the model wants ISO 639-1 codes):

- id: book_language
  transformation_expression: >-
    CASE language
         WHEN 'English'    THEN 'en'
         WHEN 'Spanish'    THEN 'es'
         WHEN 'French'     THEN 'fr'
         WHEN 'German'     THEN 'de'
         ELSE language END

Nested function calls (from stage.customer_addresses):

- id: customer_city
  transformation_expression: >
    COALESCE(NULLIF(TRIM(city), ''), 'Unknown')

Correlated subquery (the primary category of a book):

- id: book_genre
  transformation_expression: >-
    (SELECT c.category_name FROM stage.product_categories pc
       JOIN stage.categories c ON c.category_id = pc.category_id
      WHERE pc.product_id = products.product_id AND pc.is_primary
      LIMIT 1)

A correlated subquery refers to the source table by its name (products above): the generated reader selects from the mapped table without an alias.

Tip: Use folded style (>) for most SQL expressions. Use literal style (|) when you need exact line breaks preserved (rare).

Where Clauses

Filter conditions to select relevant data. A where on a table applies to every attribute of that table that has no where of its own; the bookstore order mapping keeps test orders out of the warehouse:

- connection: duckdb
  table: stage.sales_orders
  primary_keys:
    - order_id
  ingestion_strategy: TRANSACTIONAL
  entity_effective_timestamp_expression: order_date
  # Business rule: test orders never enter the warehouse
  where: "order_number NOT LIKE 'TEST-%'"

A where on an attribute filters only the rows that provide that attribute:

- id: customer_email
  transformation_expression: email
  where: email IS NOT NULL AND email LIKE '%@%'

A table, an attribute and a relationship can each state a where. An attribute's or a relationship's where replaces the table's where for that attribute's or relationship's pipeline; the two are not combined. To keep the table's filter as well, repeat it in the attribute's or relationship's condition, for example where: "order_number NOT LIKE 'TEST-%' AND email IS NOT NULL". For a relationship, see Relationship Options.

Relationship Mappings

If your model defines relationships between entities, you map them by specifying how to extract the foreign key from your source data. Relationships are defined at the mapping group level (not inside tables). A relationships block inside a table is an error: check and deploy name its file and line and say it belongs to the mapping group.

Basic Relationship Mapping

The bookstore model has an order_line entity with a relationship to order, defined with name: is_part_of, source_entity_id: order_line, and target_entity_id: order. Daana derives the relationship id order_line_is_part_of_order. The order line mapping references that id and specifies how to find the order id:

entity_id: order_line

mapping_groups:
  - name: default_mapping_group
    tables:
      - connection: duckdb
        table: stage.sales_order_lines
        primary_keys:
          - "order_id || '-' || order_line_id"
        ingestion_strategy: FULL
        # When the line landed in stage
        entity_effective_timestamp_expression: ingested_at
        attributes:
          - id: order_line_id
            transformation_expression: "order_id || '-' || order_line_id"
          - id: order_line_quantity
            transformation_expression: quantity

    # Relationships are defined at the mapping group level
    relationships:
      - id: order_line_is_part_of_order
        source_table: stage.sales_order_lines
        target_transformation_expression: order_id
      - id: order_line_is_of_book
        source_table: stage.sales_order_lines
        target_transformation_expression: product_id

Relationship Fields

FieldDescription
idThe relationship's id, derived by Daana from the model definition following the pattern {source_entity_id}_{relationship_name}_{target_entity_id} (e.g., order_is_placed_by_customer)
source_tableThe table containing the foreign key data (use schema.table format)
target_transformation_expressionSQL expression that returns the target entity's identifier
where, ingestion_strategy, relationship_effective_timestamp_expression, relationship_precedence_timestamp_expression, relationship_row_status_expressionOptional. Each overrides the table's value for this relationship; see Relationship Options and Row Status

Finding the correct id value: id follows a fixed pattern: a model relationship with name: is_placed_by between source entity order and target entity customer gives the mapping relationship id order_is_placed_by_customer. The easiest way to get the exact value is to run daana generate mapping, which pre-fills it for each relationship.

Relationship Options

A relationship entry can state four optional keys. Each one sets a value for the relationship's own pipeline only: the table's attributes, its identifier pipeline and its other relationships are not affected.

KeyWhat it setsWithout it, the relationship takes
whereWhich rows of the source table the relationship reads. It replaces the table's where; Daana does not combine the twothe table's where, else every row
ingestion_strategyThe strategy the relationship's pipeline loads under: its reader, its change detection, and whether the batch window appliesthe table's ingestion_strategy
relationship_effective_timestamp_expressionThe links' EFF_TMSTPthe table's entity_effective_timestamp_expression, else the processing time
relationship_precedence_timestamp_expressionThe links' PRECEDENCE_TMSTPthe table's entity_precedence_timestamp_expression, else the relationship's own effective-timestamp expression, else the table's, else the processing time

The options apply to two-way and N-way relationships alike. For example, stage.order_customer_links holds both the customer who placed each order and, for an order sent as a gift, the customer it is shipped to. link_kind tells the two apart, linked_at is the time each link was made and sent_at the time the source sent it. The bookstore model has is_placed_by; this example adds is_shipped_to from order to customer:

relationships:
  - id: order_is_placed_by_customer
    source_table: stage.order_customer_links
    target_transformation_expression: customer_id
    where: "link_kind = 'PLACED_BY'"
    relationship_effective_timestamp_expression: linked_at
    relationship_precedence_timestamp_expression: sent_at

  - id: order_is_shipped_to_customer
    source_table: stage.order_customer_links
    target_transformation_expression: customer_id
    where: "link_kind = 'SHIPPED_TO'"
    relationship_effective_timestamp_expression: linked_at
    relationship_precedence_timestamp_expression: sent_at

Each relationship reads only its own link kind, times its links by linked_at, and orders links sent for one linked_at by sent_at. One Link Table, Several Relationship Kinds walks through what the relationship table then holds.

Rules for the options:

  • A strategy override reads with the table's keys and batch expression. The relationship's pipeline derives its entity key from the table's primary_keys. Under INCREMENTAL or TRANSACTIONAL it filters by the table's batch_expression, else the workflow's; under FULL and FULL_LOG it reads every row.
  • A FULL relationship reads one delivery of links. Its source holds the latest delivery only: every driving key that has links, with every link it has now. A relationship whose driving key can link to several targets at once arrives as a table of its own, one row per link, keyed by the driving key and the target, with no attributes. Date it by the delivery: map its effective timestamp to the extraction, load or as-of date that every row of one delivery shares (see Dating a FULL source). On every run FULL reads each driving key's links as one set and compares it with the stored set. When the two differ, all of the set's links are written at the delivery's date, or at the processing time when that date does not lie after the stored set's. A link that is no longer in the delivery drops out of the relationship views because the newer set no longer holds it. A driving key that is no longer in the delivery at all gets an N row for each of its links, stamped with the processing time. An unchanged delivery writes nothing. A table that keeps earlier deliveries or sets of links beside the latest is a log: load it FULL_LOG or INCREMENTAL, since FULL reads every link it holds as one set.
  • The precedence expression must be the same for every row of one delivered set. See The value must be stable.
  • daana check mapping refuses an unknown strategy. A relationship's ingestion_strategy must be one of FULL, FULL_LOG, INCREMENTAL or TRANSACTIONAL, as a table's must.

Multi-Source Relationships

When a relationship's data comes from multiple sources, or from a different table than the entity's attributes, you have several patterns available.

Multi-Group Pattern

Two mapping groups can drive the same relationship independently. Each group generates its own pipeline with a unique DATA_KEY, and truedelta operates independently per group.

The bookstore records the customer of an order in stage.sales_orders and again in stage.returns, whose rows carry the order_id and customer_id of the returned order. Reading the relationship from both tables, each in its own group, gives the order mapping a second group:

entity_id: order

mapping_groups:
  - name: default_mapping_group
    tables:
      - connection: duckdb
        table: stage.sales_orders
        primary_keys: [order_id]
        ingestion_strategy: TRANSACTIONAL
        batch_expression: ingested_at
        entity_effective_timestamp_expression: order_date
        attributes:
          - id: order_value_amount
            transformation_expression: total_amount
          - id: order_value_currency
            transformation_expression: currency
    relationships:
      - id: order_is_placed_by_customer
        source_table: stage.sales_orders
        target_transformation_expression: customer_id

  - name: returns
    tables:
      - connection: duckdb
        table: stage.returns
        primary_keys: [order_id]
        ingestion_strategy: FULL
        # A FULL relationship is dated by its delivery
        entity_effective_timestamp_expression: popln_tmstp
        attributes: []
    relationships:
      - id: order_is_placed_by_customer
        source_table: stage.returns
        target_transformation_expression: customer_id

Both groups populate the same relationship (order_is_placed_by_customer) from different source tables. The DATA_KEY isolation ensures each group's truedelta operates independently: the relationship rows read from returns never interfere with the rows read from orders. On the bookstore data, order_customer_x then holds rows under two DATA_KEY values.

Relationship-Only Source Tables

A table entry can have empty attributes (attributes: []) and exist solely to provide primary_keys, ingestion_strategy, and batch_expression for a relationship's source_table. This is useful when a relationship's source data comes from a different table than the entity's attributes. The bookstore book mapping reads the authors of a book from the bridge table stage.product_authors, which holds one row per book and author:

entity_id: book

mapping_groups:
  - name: default_mapping_group
    tables:
      # Source 1: product catalog, one row per sellable edition
      - connection: duckdb
        table: stage.products
        primary_keys:
          - product_id
        ingestion_strategy: FULL_LOG
        entity_effective_timestamp_expression: updated_at
        attributes:
          # ...
          - id: book_title
            transformation_expression: title
      # ...
      # Source 3: book-to-author bridge (relationship only, no attributes).
      # One row per (product, author); co-authored titles have several rows.
      # A change to a book's credits re-asserts its whole author set at a new
      # updated_at, and the earlier rows stay: the table is a log of sets.
      # INCREMENTAL reads only rows loaded since the last run (popln_tmstp),
      # and the newer set supersedes the older one. FULL would read every row
      # of a book as one set, the earlier authors included.
      # author_order is not carried: DMDL relationships have no attributes.
      - connection: duckdb
        table: stage.product_authors
        primary_keys:
          - product_id
        ingestion_strategy: INCREMENTAL
        batch_expression: popln_tmstp
        entity_effective_timestamp_expression: updated_at
        attributes: []

    relationships:
      - id: book_is_written_by_author
        source_table: stage.product_authors
        target_transformation_expression: author_id

The relationship pipeline uses stage.product_authors as its source, deriving entity keys from that table's primary_keys and applying batch filtering from its ingestion_strategy and batch_expression. No TYPE pipelines are generated for this table since it has no attributes. A co-authored book has several rows in the bridge table, so it gets one is_written_by row per author.

Both daana check and daana deploy accept this pattern.

source_table Resolution

The source_table field must name one of the tables in the same mapping group's tables list. Daana compares the names ignoring case, so stage.SALES_ORDERS names the table stage.sales_orders. daana check and daana deploy refuse a relationship whose source_table names no table of its group, and name the relationship, its group and the group's tables: source_table 'stage.product_authorz' of relationship 'book_is_written_by_author' in group 'default_mapping_group' names no table of the group (tables: stage.products, stage.product_pricing, stage.product_authors). When the misspelled relationship was the only reader of a relationship-only table, daana check reports that table as well, because it has no attributes and no relationship reads it: attributes must have at least one attribute for table 2 in group 'default_mapping_group'.

The relationship inherits these properties from the matched source table:

  • primary_keys: used to derive the entity key
  • ingestion_strategy: determines the SQL template and batch filtering, unless the relationship states its own
  • batch_expression: controls watermark-based incremental reads
  • where, entity_effective_timestamp_expression and entity_precedence_timestamp_expression: unless the relationship states its own (see Relationship Options)

Multi-Table Mappings

Map a single entity from multiple source tables. The bookstore customer mapping merges three source tables with three different change-recording shapes into one customer entity: the CRM change log, daily address snapshots, and the current loyalty membership.

entity_id: customer

mapping_groups:
  - name: default_mapping_group
    tables:
      # Source 1: CRM data, core customer records with full status change history
      - connection: duckdb
        table: stage.customers
        primary_keys:
          - customer_id
        ingestion_strategy: FULL_LOG
        entity_effective_timestamp_expression: updated_at
        attributes:
          - id: customer_id
            transformation_expression: customer_id
          - id: customer_name
            transformation_expression: CONCAT(first_name, ' ', last_name)
          - id: customer_email
            transformation_expression: email
          - id: customer_status
            transformation_expression: account_status

      # Source 2: Address snapshots, merged automatically with Source 1
      - connection: duckdb
        table: stage.customer_addresses
        primary_keys:
          - customer_id
        ingestion_strategy: FULL_LOG
        entity_effective_timestamp_expression: snapshot_date
        attributes:
          - id: customer_city
            transformation_expression: city
          - id: customer_state
            transformation_expression: state

      # Source 3: Loyalty tier, merged automatically with Sources 1 and 2
      - connection: duckdb
        table: stage.loyalty_memberships
        primary_keys:
          - customer_id
        ingestion_strategy: FULL
        # Overwriting source: stamp detected changes at the activity date,
        # falling back to join_date for the initial load
        entity_effective_timestamp_expression: COALESCE(last_activity_date, join_date)
        attributes:
          - id: customer_loyalty_tier
            transformation_expression: tier_level

All three tables key the customer by the same customer_id value, so their rows describe the same entity.

Multiple Identifiers

By default, each entity has a single identifier (primary key). The allow_multiple_identifiers setting is an advanced feature for rare scenarios involving multi-source data integration.

When Multiple Identifiers Are Needed

This feature is designed for multi-source data integration scenarios where the same real-world entity exists in different source systems with different identifiers, and you need to preserve both:

ScenarioExample
Multi-source integrationThe same customer exists as customer_id: 2 in the CRM and as membership number LM-2024-000002 in the loyalty system; both identifiers must remain queryable
Data consolidation after an acquisitionAfter the bookstore buys another bookshop chain, that chain's customer numbers must coexist with the bookstore's own customer_id for the same person

A composite business key, such as an order line identified by order_id and order_line_id, is not a case for multiple identifiers. Write it as one key expression instead (see Composite and Computed Primary Keys).

When NOT to Use Multiple Identifiers

For most use cases, a single surrogate key is preferred:

  • Customer lookup by email/phone - Use attributes with indexes, not multiple identifiers
  • Alternative lookup keys - Model these as regular attributes, not identifiers
  • Book id vs ISBN - One should be the identifier, the other an attribute. The bookstore uses product_id as the identifier of book and maps the ISBN to the book_isbn attribute

Industry best practice: Data warehouses typically use surrogate keys rather than composite business keys. Multiple identifiers add complexity and are only justified when you must preserve source system identity relationships.

Enabling Multiple Identifiers

Set allow_multiple_identifiers: true in your mapping group:

The bookstore keeps one identifier per customer through tutorial chapter 8, and chapter 9 adds reader profiles keyed by email and declares several identifiers on the CRM rows. The following variant of the customer mapping makes the loyalty membership number a second identifier of customer. It runs on the bookstore data (the other customer tables stay as they are):

entity_id: customer

mapping_groups:
  - name: default_mapping_group
    allow_multiple_identifiers: true  # Enable multiple identifiers

    tables:
      # Source 1: CRM. Single identifier (customer_id).
      - connection: duckdb
        table: stage.customers
        primary_keys:
          - customer_id
        ingestion_strategy: FULL_LOG
        entity_effective_timestamp_expression: updated_at
        attributes:
          - id: customer_id
            transformation_expression: customer_id

      # Source 2: Loyalty system. Carries its own identifier plus the CRM
      # customer_id as a cross-reference (the overlapping identifier that
      # binds the two sources together).
      - connection: duckdb
        table: stage.loyalty_memberships
        primary_keys:
          - membership_number
          - customer_id
        ingestion_strategy: FULL
        entity_effective_timestamp_expression: COALESCE(last_activity_date, join_date)
        attributes:
          - id: customer_loyalty_tier
            transformation_expression: tier_level

The overlap is intentional: every loyalty row must carry the customer_id value of the same customer in the CRM, so that resolution at INTEGRATION time matches the existing IDFR row and reuses the CRM-assigned surrogate. The CRM source does not need to know about membership_number. The overlap on customer_id is sufficient for the loyalty system's identifiers to attach to the existing entity.

How resolution works

Daana supports up to 5 identifier types per entity, stored in slots IDFR_01 through IDFR_05. When allow_multiple_identifiers: true, each source row carries one identifier value per slot (drawn from the mapping group's primary_keys), and the pipeline resolves the row to an entity by co-occurrence:

  1. READER populates the IDFR slots with the identifier values from the source row.
  2. INTEGRATION looks each slot value up against the existing <entity>_idfr table. The lookup is a LEFT JOIN across all five slots; any match returns the entity's surrogate key.
  3. TRUEDELTA classifies the row:
    • If a slot matches an existing identifier, Daana uses the first matching slot's key for any new identifiers on the row. Existing bindings keep their keys. The row carries an existing entity.
    • If no slot value matches anything, Daana generates a fresh UUID. The row carries a new entity.
  4. INSERT writes only the new identifier values to the <entity>_idfr table. Existing identifiers are not re-inserted.

This is the mechanism that binds different source systems together. In chapter 9, a CRM row pairs a customer number with an email address. An external profile can then find the customer by that email alone.

Example. The CRM emits a row for Emily Johnson with customer_id = 2. Daana finds no match in IDFR and assigns a new surrogate UUID-AAA. The IDFR table now has one row:

customer_idfr   | customer_key | row_st
2               | UUID-AAA     | Y

The loyalty system later emits a row for the same customer carrying membership_number = LM-2024-000002 and customer_id = 2 together. Daana's lookup finds 2 → UUID-AAA, classifies the row as an existing entity, and inserts only the new identifier:

customer_idfr   | customer_key | row_st
2               | UUID-AAA     | Y
LM-2024-000002  | UUID-AAA     | Y

Both identifiers resolve to the same surrogate. Downstream queries on customer_key = UUID-AAA return both source-side identifiers as different facets of one entity.

Two properties of resolution worth stating explicitly:

  • Resolution matches values, not column names. The IDFR table stores identifier values in a single column (<entity>_idfr); the source column the value originated from is not preserved. If the loyalty source's cross-reference column were named crm_ref instead of customer_id, resolution would still work as long as the value 2 appears in some row of the loyalty source. What binds sources together is the overlap of values, not the overlap of column names.
  • The first entry in primary_keys is the identifier every row must carry. Resolution checks every slot against the IDFR table, and any match returns the existing surrogate. When the identifiers on one row already belong to two different entities, the earliest slot's entity wins, so the order of primary_keys decides which one the row resolves to. Attribute and relationship pipelines look a row's surrogate up through the first entry, so it must be the source's mandatory key (see the rules below).

Two rules for the input

  • The first identifier is mandatory. The first entry in a table's primary_keys is that source's mandatory key, set on every row from the start. Later entries may be filled in later in a process: a web shop session id exists from the first visit, a loyalty membership number only after the customer has joined the loyalty program. Attribute and relationship pipelines find a row's surrogate through the first identifier, and resolution binds a row only when it has one. A row whose first identifier is NULL is not supported: nothing is loaded from it, and nothing reports it.
  • Resolve ambiguous identifier pairs before loading. Within one batch from one source table, the pipeline reads each distinct combination of identifiers once. Suppose two CRM rows pair different customer numbers with the same email, and all the identifiers are new. The pipeline generates two candidate keys and tries to bind the email to both. DuckDB and PostgreSQL reject the insert because the two rows have the same identifier, effective timestamp and version timestamp, which together must be unique. The generated BigQuery and Snowflake tables have no uniqueness constraint (BigQuery only clusters by identifier), so both keep the email under both keys. See the chapter 9 DuckDB example.

Identifier transformations

The primary_keys field accepts SQL expressions, not just column names (Composite and Computed Primary Keys covers the syntax). For multi-identifier setups, this matters: each source's primary_keys is what lands in the IDFR table, and a normalization expression lets two sources that store the same logical identifier in different shapes still produce matching values.

For example, the bookstore CRM stores both customer_id (2) and a customer number (stage.customers.customer_number, CUST-000002), while the loyalty system carries only customer_id. To key customers by the customer number, the loyalty mapping builds the same value from customer_id on read:

      - connection: duckdb
        table: stage.customers
        primary_keys:
          - customer_number   # 'CUST-000002'
        ...
      - connection: duckdb
        table: stage.loyalty_memberships
        primary_keys:
          - membership_number
          - "'CUST-' || LPAD(CAST(customer_id AS VARCHAR), 6, '0')"
        ...

Both sources now write CUST-000002 to IDFR for the same customer, and resolution proceeds normally: on the bookstore data, CUST-000002 and LM-2024-000002 resolve to one surrogate. Every other table of the mapping group must key the customer the same way (stage.customer_addresses with the same expression), and so must every relationship that targets customer. In the order mapping, order_is_placed_by_customer needs target_transformation_expression: "'CUST-' || LPAD(CAST(customer_id AS VARCHAR), 6, '0')". A relationship that still returns customer_id links no order to a customer, and neither daana check nor daana execute reports it. The same pattern handles composite natural keys (one source carries tenant_id + customer_id, the other carries a pre-combined global_customer_id): a CONCAT expression collapses the composite into a single value that can overlap with the other source.

The overlap requirement still applies to the transformed values. If the expression on each side produces different strings for the same real-world entity, the result is identifier orphaning.

Identifier orphaning

The resolution above requires that overlapping sources share at least one identifier value per row. If they don't, Daana cannot tell that two source rows describe the same real-world entity and creates two separate surrogates.

Concrete failure mode. Assume the loyalty source arrives without the customer_id cross-reference (carrying only membership_number = LM-2024-000002):

customer_idfr   | customer_key
LM-2024-000002  | UUID-XXX

The CRM source then arrives with customer_id = 2 and no overlapping identifier. Daana finds no match and assigns a fresh surrogate:

customer_idfr   | customer_key
LM-2024-000002  | UUID-XXX
2               | UUID-YYY

Two surrogate keys now exist for one real-world customer. Downstream tables keyed by customer_key treat them as separate entities. The warehouse silently carries a duplicate.

Operational requirement. The sources need a row that links their identifiers. In the loyalty example above, the working configuration has the loyalty source emit both membership_number and customer_id on every row; the failing configuration has it emit only membership_number.

If a source system emits rows with only its own identifiers and no overlap with any other source, multi-identifier resolution is not the right tool. Solve the integration upstream (data cleaning, ID-mapping table, or a master-data-management system) before the data reaches Daana.

Adding identifiers later

Within the 5-slot ceiling, identifier evolution is rowwise, not schema-wise:

  • New identifier types from existing sources flow as new rows in <entity>_idfr without any DDL change. If a CRM row that previously carried only customer_id starts also carrying customer_email (a new identifier type), the new value lands in an unused slot, becomes a new IDFR row, and resolves like any other identifier.
  • New source systems that emit identifier types overlapping with existing sources attach via the same mechanism. They contribute new rows that resolve via co-occurrence; existing rows are unchanged.
  • No schema migrations are required for either case. The IDFR table's column shape is fixed at install time.

Warning: This setting is irreversible. Once you enable multiple identifiers for an entity and deploy the mapping, you cannot go back to single-identifier mode. This is a permanent structural change to how the entity is stored.

Why irreversible. When allow_multiple_identifiers: true, the IDFR table becomes the authoritative source of entity identity: surrogate keys are generated by co-occurrence resolution in IDFR and propagated to every <entity>_desc, <entity>_focal, and relationship _x row. Disabling multi-identifier mode requires regenerating every surrogate from a different path (the f_<entity>() derivation used in single-identifier mode), which cascades to every downstream row that holds the old surrogate. There is no in-place migration.

If you change it anyway. Once an entity holds data, daana deploy refuses to change its allow_multiple_identifiers, in either direction, and changes nothing. There are two ways to go on:

  • Set allow_multiple_identifiers back to its earlier value, then deploy again.
  • Rebuild the install from source. Drop the connection profile's target, stage, metadata and DAR schemas (the refusal lists them), then run daana install, daana deploy and daana execute. Dropping the schemas deletes everything Daana loaded into them. The rebuild brings back only what the sources still hold. Downstream consumers (Layer 3 views, BI dashboards) get new surrogate keys for every entity.

Dropping only the entity's own tables is not enough: install still finds the install and refuses.

Rebuild in new schemas, keeping the old warehouse. A variant of the rebuild keeps the existing schemas until the new build is checked. In the profile, set target_schema, stage_schema and metadata_schema to names that do not exist yet. A project with DAR outputs sets a new dar_schema too, so the rebuild does not share the old daana_dar. Then run daana install, daana deploy and daana execute. The rebuild loads only what the sources still hold. Compare it with the old schemas before you point consumers at it. For the bookstore customer returned to one identifier, in schemas named daana_dw_v2, daana_stage_v2, daana_metadata_v2 and daana_dar_v2:

SELECT (SELECT count(*) FROM daana_dw_v2.view_customer) AS customers,
       (SELECT string_agg(customer_key, ',' ORDER BY customer_key::int) FROM daana_dw_v2.view_customer) AS customer_keys,
       (SELECT count(*) FROM daana_dw_v2.view_order_with_rel WHERE customer_key IS NOT NULL) AS orders_with_customer,
       (SELECT count(*) FROM daana_dw_v2.view_customer_hist) AS history_rows;
customerscustomer_keysorders_with_customerhistory_rows
101,2,3,4,5,6,7,8,9,101632

The keys are the CRM's customer_id again, every order still has its customer, and the history has the same 32 rows. Consumers see new keys for the rebuilt entity. Drop the old schemas when nothing reads them.

Key Considerations

  1. Exhaust alternatives first - Can you solve this with a single identifier and additional attributes?
  2. Plan ahead - Decide whether you need multiple identifiers before your first deployment
  3. Performance impact - Multiple identifiers increase storage and may affect query performance
  4. No rollback - If you enable this by mistake, rebuild the warehouse in new schemas, as described above

Complete Example

The bookstore order mapping: one transactional source with a test-order filter and a business rule, one relationship-only source, and three relationships.

entity_id: order

mapping_groups:
  - name: default_mapping_group
    tables:
      - connection: duckdb
        table: stage.sales_orders
        primary_keys:
          - order_id
        ingestion_strategy: TRANSACTIONAL
        # Business rule: test orders never enter the warehouse
        where: "order_number NOT LIKE 'TEST-%'"
        batch_expression: ingested_at
        entity_effective_timestamp_expression: order_date
        attributes:
          - id: order_id
            transformation_expression: order_id
          - id: order_status
            transformation_expression: order_status
          - id: order_size
            # Business rule in plain SQL: classify order magnitude
            transformation_expression: >-
              CASE WHEN total_amount >= 100 THEN 'LARGE'
                   WHEN total_amount >= 50  THEN 'MEDIUM'
                   ELSE 'SMALL' END
          - id: order_purchase_ts
            transformation_expression: order_date
          - id: order_value_amount           # child attribute of the order_value group
            transformation_expression: total_amount
          - id: order_value_currency         # child attribute of the order_value group
            transformation_expression: currency

      # Source 2: promotions applied to the order (relationship only)
      - connection: duckdb
        table: stage.order_promotions
        primary_keys:
          - order_id
        ingestion_strategy: FULL
        # A FULL relationship is dated by its delivery: popln_tmstp, the time
        # the export landed in stage, shared by all the rows of one order
        entity_effective_timestamp_expression: popln_tmstp
        attributes: []

    relationships:
      - id: order_is_placed_by_customer
        source_table: stage.sales_orders
        target_transformation_expression: customer_id
      - id: order_is_sold_at_location
        source_table: stage.sales_orders
        target_transformation_expression: location_id
      - id: order_uses_promotion
        source_table: stage.order_promotions
        target_transformation_expression: promotion_id

Quick Reference

Looking up a specific field? Here's the complete reference for all fields in mapping YAML files.

Mapping Root Fields

FieldTypeRequiredDescription
entity_idstring✓
Target entity ID from your model
mapping_groupslist of MappingGroup✓
List of mapping groups for this entity

✓ = required, ○ = optional

Mapping Group Fields

FieldTypeRequiredDescription
namestring✓
Name of the mapping group
allow_multiple_identifiersbool✓
Allow multiple identifier values per entity
⚠ This setting is irreversible - once enabled, you cannot go back to single identifier mode⚠ Only enable if you need multiple primary keys per entity
tableslist of Table✓
List of source tables in this mapping group
relationshipslist of RelationshipMapping○
Relationship mappings at the group level

✓ = required, ○ = optional

Table Fields

FieldTypeRequiredDescription
connectionstring✓
Connection profile name
tablestring✓
Source table name with schema
primary_keyslist of string✓
Primary key columns or SQL expression for the source table
⚠ A single entry containing SQL operators or function calls is evaluated as an expression against the source table⚠ Write a composite key as one expression (order_id || '-' || order_line_id)⚠ Multiple entries declare alternative identifiers of the entity and require allow_multiple_identifiers: true; deploy refuses them otherwise
ingestion_strategyIngestionStrategy✓
How to load data from this table
wherestring○
SQL WHERE clause to filter source data
⚠ Syntax is database-specific - consult your platform's SQL documentation
entity_effective_timestamp_expressionstring○
Default timestamp expression for all attributes
⚠ Syntax is database-specific - consult your platform's SQL documentation
⚠ Used whether the model attribute's effective_timestamp is true, false, or omitted
entity_precedence_timestamp_expressionstring○
When the source sent each row, for rows that share an effective timestamp
⚠ Syntax is database-specific - consult your platform's SQL documentation
⚠ Needed only where the source delivers several values for one key at one effective timestamp⚠ Required, here or per attribute, for attributes with precedence_timestamp: true in the model⚠ Use an expression that gives a row the same value on every read: a value that changes on each reload makes a FULL_LOG table store its rows again
batch_expressionstring○
Batch filtering expression (overrides workflow default)
⚠ Filters INCREMENTAL and TRANSACTIONAL pipelines, which need it, and every IDFR pipeline; the other pipelines of FULL and FULL_LOG tables read all data and record the highest batch value they read⚠ If not set, falls back to the workflow-level batch_expression⚠ If value contains ${BATCH_START} or ${BATCH_END}, it's used as raw SQL
batch_settle_timestring○
Minimum age of a batch value before a run reads it (overrides workflow default)
⚠ Applies wherever a batch window applies: INCREMENTAL and TRANSACTIONAL pipelines and the IDFR pipelines of any table with a batch_expression; the other pipelines of FULL and FULL_LOG tables read all data and record the highest batch value they read⚠ If not set, falls back to the workflow-level batch_settle_time; if neither is set, the window ends at the highest batch value⚠ A duration such as 30s, 2m or 1h30m; "0s" turns off a workflow-level settle time for this table⚠ Rows within the settle time of the newest batch value wait until newer rows arrive
entity_row_status_expressionstring○
Whether each source row is active ('Y') or ends what it states ('N')
⚠ Syntax is database-specific - consult your platform's SQL documentation
⚠ An ended row is loaded even when its attribute values are NULL, as a delete marker's often are⚠ Under INCREMENTAL an end is a statement like any other: an end sent again writes nothing, an active row after it starts the value again, and a row with an earlier effective timestamp does not undo a later end⚠ Under FULL an end closes the key's active value, and writes nothing for a key that has none⚠ A relationship read as sets (MANY_TO_MANY or undeclared) still needs whole sets: an ended row is not a member, and a set whose rows are all ended ends the driving key's members
attributeslist of AttributeMapping✓
List of attribute mappings

✓ = required, ○ = optional

Attribute Mapping Fields

FieldTypeRequiredDescription
idstring✓
Attribute ID from the model
transformation_expressionstring✓
SQL expression to extract/transform the value
⚠ Syntax is database-specific - consult your platform's SQL documentation
ingestion_strategyIngestionStrategy○
Override ingestion strategy for this attribute
wherestring○
SQL WHERE clause for this attribute
⚠ Syntax is database-specific - consult your platform's SQL documentation
attribute_effective_timestamp_expressionstring○
Override timestamp expression for this attribute
⚠ Syntax is database-specific - consult your platform's SQL documentation
⚠ Only needed when this attribute has a different timestamp source than other attributes
attribute_precedence_timestamp_expressionstring○
Override the precedence expression for this attribute
⚠ Syntax is database-specific - consult your platform's SQL documentation
⚠ Only needed when this attribute's statements are sent at a different time than the table's other attributes
attribute_row_status_expressionstring○
Override the row-status expression for this attribute
⚠ Syntax is database-specific - consult your platform's SQL documentation
⚠ Only needed when this attribute ends at other rows than the table's other attributes

✓ = required, ○ = optional

Relationship Mapping Fields

FieldTypeRequiredDescription
idstring✓
Relationship ID from the model
⚠ Do not add a separate `atomic_context:` line. The mapping schema only defines `id` for relationships; an `atomic_context:` line is refused as an unknown key
source_tablestring✓
Source table name with schema
target_transformation_expressionstring○
Expression to get the target entity identifier
⚠ Syntax is database-specific - consult your platform's SQL documentation
target_transformation_expressionsmap[string]string○
Per-target identifier expressions, keyed by entity id (N-way)
⚠ Syntax is database-specific - consult your platform's SQL documentation
wherestring○
SQL WHERE clause for this relationship
⚠ Syntax is database-specific - consult your platform's SQL documentation
ingestion_strategyIngestionStrategy○
Override ingestion strategy for this relationship
relationship_effective_timestamp_expressionstring○
Effective timestamp expression for this relationship
⚠ Syntax is database-specific - consult your platform's SQL documentation
⚠ A relationship needs no model flag: the mapping alone states its effective timestamp⚠ Only needed when the links have a different valid time than their table's other rows
relationship_precedence_timestamp_expressionstring○
When the source sent each link, for links that share an effective timestamp
⚠ Syntax is database-specific - consult your platform's SQL documentation
⚠ Needed only where the source delivers several sets of links for one key at one effective timestamp⚠ Use an expression that gives every row of one delivered set the same value: a value that differs between the rows of one set splits it into as many sets
relationship_row_status_expressionstring○
Override the row-status expression for this relationship
⚠ Syntax is database-specific - consult your platform's SQL documentation
⚠ Only needed when the links end at other rows than their table's⚠ An ended row must name its target: a row whose target expression yields NULL ends nothing

✓ = required, ○ = optional

Best Practices

  1. Generate templates first - Start with generated templates and customize as needed
  2. Always use schema.table format - Specify schema.table (e.g., stage.customers, stage.sales_orders) to avoid ambiguity
  3. Use descriptive expressions - Make transformation logic clear and maintainable
  4. Add where clauses - Filter out invalid or incomplete data at the source
  5. Use entity_effective_timestamp_expression - Set a DRY default at the table level
  6. Override when needed - Use attribute_effective_timestamp_expression for attributes with different timestamp sources
  7. Map a precedence timestamp only where it is needed - Use entity_precedence_timestamp_expression when a source sends several values at one effective timestamp, from a column whose value is the same on every read
  8. Map a row status where the source marks its deletes - Use entity_row_status_expression to end what a delete marker or inactive flag carries, instead of filtering those rows out with where
  9. Validate data types - Use CAST functions to ensure correct data types
  10. Choose the right ingestion strategy - Match the strategy to the shape of the source: FULL for small dimensions with one row per entity, FULL_LOG when the source already carries history, INCREMENTAL for large mutable tables (use the load time for batch_expression), TRANSACTIONAL for append-only event logs

Next Steps

Previous
Model