Skip to content

Extend value_mappings to support expr values #165

@amc-corey-cox

Description

@amc-corey-cox

Summary

Extend value_mappings so that mapping values can be expressions, not just literals. This keeps value_mappings as the single declarative lookup mechanism while supporting cases where each branch needs computed output.

Current behavior

value_mappings maps literal keys to literal values:

slot_derivations:
  visit_label:
    populated_from: visit_code
    value_mappings:
      "1": "SCREENING"
      "7": "BASELINE"

Proposed behavior

Mapping values can be either a literal string (unchanged) or an object with an expr field:

slot_derivations:
  visit_id:
    populated_from: visit_code
    value_mappings:
      "1":
        expr: "uuid5({id} + 'SCREENING')"
      "7":
        expr: "uuid5({id} + 'BASELINE')"

Motivation

When each branch of a value mapping needs different computation (not just a different literal), users currently have to inline everything into a case() expression, which is unreadable for non-trivial mappings. This extension keeps the mapping table as a clean, auditable artifact while allowing computed results.

Design decisions

  • Literal string values continue to work unchanged — no migration needed
  • The expr in a mapping value has access to the same bindings as a top-level expr (source fields, joins, etc.)
  • No-match behavior: returns None (unchanged from current value_mappings)
  • This subsumes the unimplemented expression_to_value_mappings field, which should be removed from the spec

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions