Skip to content

feat: implement mapping evaluator with built-in functions#45

Merged
alvinreal merged 1 commit intomainfrom
fix/issue-17
Feb 21, 2026
Merged

feat: implement mapping evaluator with built-in functions#45
alvinreal merged 1 commit intomainfrom
fix/issue-17

Conversation

@alvinreal
Copy link
Owner

Summary

Closes #17 — Mapping evaluator.
Part of #3 (Mapping DSL epic).

Changes

Evaluator (src/mapping/eval.rs):

  • All 6 statement types: rename, select, drop, set, default, cast
  • Path resolution: nested fields, array indices (positive & negative), wildcards
  • Expression evaluation with precedence: arithmetic, comparison, logical, unary
  • String concatenation via + with auto-coercion to string
  • Type casting: int↔float↔string↔bool with null handling
  • Division/modulo by zero detection
  • Mixed int/float arithmetic with automatic promotion
  • Truthiness for all types (null=false, empty string=false, 0=false, etc.)

Built-in functions (src/mapping/functions.rs) — 30+ functions:

  • String: lower, upper, trim, trim_start, trim_end, len, replace, contains, starts_with, ends_with, substr, concat, split, join, reverse
  • Type: to_int, to_float, to_string, to_bool, type_of
  • Math: abs, min, max, floor, ceil, round
  • Null: is_null, coalesce, default
  • Aliases: lowercase/downcase, uppercase/upcase, length/size, ltrim/rtrim, substring, int/float/str/string/bool/typeof

Tests (110+):

  • Eval: rename (simple, nested, nonexistent), select (single, multi, nested), drop (single, multi, nested), set (all literal types, path refs, expressions, functions), default (missing, existing, null), cast (all type combinations, null, errors)
  • Expressions: arithmetic chain, string concat, comparisons, logical ops, not, mixed int/float
  • Functions: all 30+ functions with aliases, error cases (unknown, wrong arg count)
  • Multi-statement: rename+select, set+drop, complex 7-statement pipeline
  • Edge cases: division by zero, modulo by zero, null input, empty map, array index, truthiness

All checks pass: cargo build, cargo test (575 tests), cargo fmt --check, cargo clippy -D warnings.

- Implement statement evaluator (eval.rs) supporting all 6 statement
  types: rename, select, drop, set, default, cast
- Path resolution with nested field access, array indices, and wildcards
- Expression evaluation with operator precedence: arithmetic (+, -, *, /,
  %), comparison (==, !=, >, >=, <, <=), logical (and, or, not)
- String concatenation via + operator with auto-coercion
- Type casting: int, float, string, bool with null handling
- Division/modulo by zero error detection
- Mixed int/float arithmetic with automatic promotion
- Truthiness semantics for all value types
- Implement 30+ built-in functions (functions.rs):
  String: lower, upper, trim, trim_start, trim_end, len, replace,
  contains, starts_with, ends_with, substr, concat, split, join, reverse
  Type: to_int, to_float, to_string, to_bool, type_of
  Math: abs, min, max, floor, ceil, round
  Null: is_null, coalesce, default
- Function aliases: lowercase/downcase, uppercase/upcase, length/size,
  ltrim/rtrim, substring, int/float/str/string/bool/typeof
- Add 110+ tests covering: all statement types with various inputs,
  path resolution (nested, array, wildcard), expression evaluation,
  function calls (direct and nested), type casting, error cases,
  multi-statement pipelines, complex programs, edge cases

Fixes #17
@alvinreal alvinreal merged commit 5e489fc into main Feb 21, 2026
0 of 6 checks passed
@alvinreal alvinreal deleted the fix/issue-17 branch February 21, 2026 12:50
alvinreal added a commit that referenced this pull request Feb 21, 2026
- Replace single-arm match with if-let for modulo-by-zero check (clippy::single_match)
- Remove redundant closure in join() (clippy::redundant_closure)
- Replace 3.14 test values with 2.72 to avoid clippy::approx_constant (PI detection)

Fixes CI failure introduced by #45.
alvinreal added a commit that referenced this pull request Feb 21, 2026
- Replace single-arm match with if-let for modulo-by-zero check (clippy::single_match)
- Remove redundant closure in join() (clippy::redundant_closure)
- Replace 3.14 test values with 2.72 to avoid clippy::approx_constant (PI detection)

Fixes CI failure introduced by #45.
@github-actions github-actions bot mentioned this pull request Mar 20, 2026
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.

Mapping language: Evaluator

1 participant