Skip to content

Support expr values in value_mappings#195

Open
amc-corey-cox wants to merge 7 commits intomainfrom
value-mapping-expr
Open

Support expr values in value_mappings#195
amc-corey-cox wants to merge 7 commits intomainfrom
value-mapping-expr

Conversation

@amc-corey-cox
Copy link
Copy Markdown
Contributor

Summary

  • Extend value_mappings so each KeyVal entry can use an expr field (evaluated against source bindings) instead of a literal value. Specifying both is an error.
  • Add _resolve_key_val method and lazy bindings init in the populated_from + value_mappings path
  • Add _expand_keyval_dicts preprocessing to handle ReferenceValidator normalization when KeyVal has more than two fields
  • Deprecate expression_to_value_mappings and expression_to_expression_mappings in the schema ahead of 1.0 removal

Closes #165

Test plan

  • Scaffold test: expr-valued mapping with uuid5() and source field bindings
  • Scaffold test: literal value mapping (backward compat)
  • Error test: both value and expr set raises
  • Edge case: no-match returns None
  • Full suite: 584 passed, 4 skipped

🤖 Generated with Claude Code

Extend value_mappings so each entry can use an expr field (evaluated
against source bindings) instead of a literal value. Deprecate
expression_to_value_mappings and expression_to_expression_mappings
ahead of 1.0 removal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extends the transformer spec and runtime to allow value_mappings entries to compute their mapped values via an expr (evaluated with source bindings), while preserving backward-compatible literal mappings and deprecating older expression-mapping fields.

Changes:

  • Add KeyVal.expr support and resolve mapped values via a new _resolve_key_val helper in the populated_from + value_mappings path.
  • Pre-expand shorthand dict[str, KeyVal] values (e.g., "A": Admin) prior to ReferenceValidator normalization to avoid normalization failures after KeyVal gains extra fields.
  • Add tests covering expr-valued mappings, literal backward compatibility, mutual-exclusion error, and no-match behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/test_transformer/test_object_transformer_new.py Adds integration/unit tests for expr-valued and literal value_mappings, plus error/no-match cases.
src/linkml_map/transformer/transformer.py Adds preprocessing to expand shorthand KeyVal dict values before normalization.
src/linkml_map/transformer/object_transformer.py Resolves value_mappings outputs via literal value or evaluated expr, with lazy bindings init.
src/linkml_map/datamodel/transformer_model.yaml Adds KeyVal.expr and deprecates older expression-mapping fields in the schema.
src/linkml_map/datamodel/transformer_model.py Updates generated Pydantic models/metadata to reflect KeyVal.expr and deprecations.

Unify expression evaluation: extract _eval_expr from _derive_from_expr
so _resolve_key_val shares the same eval path (including unrestricted_eval
fallback). Fix KeyVal bindings type signature to Bindings | None. Fix
double-space typo in deprecation message.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 8, 2026 15:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

…g-expr

# Conflicts:
#	src/linkml_map/datamodel/transformer_model.py
#	src/linkml_map/transformer/object_transformer.py
After the _derive_slot extraction, bindings is always initialized
unconditionally in map_object, so the | None is no longer needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 8, 2026 19:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

amc-corey-cox and others added 2 commits April 8, 2026 16:57
Instead of adding expr to KeyVal (which polluted the shared slot
namespace and required a ReferenceValidator shim), add a dedicated
expression_mappings field on ElementDerivation. KeyVal stays clean
(key + value only), the _expand_keyval_dicts shim is removed, and
the runtime handles expression_mappings as a fallback after
value_mappings in _derive_slot.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 8, 2026 21:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

YAML silently coerces unquoted true/false to booleans and bare
numbers to integers, causing silent lookup misses against the
stringified source value. Note this in value_mappings and
expression_mappings descriptions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend value_mappings to support expr values

2 participants