Skip to content

v2 step 2: add did2.query in-memory evaluator#121

Merged
stevevanhooser merged 2 commits into
V2from
claude/did-v2-schema-stage2-nGrJx
May 12, 2026
Merged

v2 step 2: add did2.query in-memory evaluator#121
stevevanhooser merged 2 commits into
V2from
claude/did-v2-schema-stage2-nGrJx

Conversation

@stevevanhooser
Copy link
Copy Markdown
Contributor

Summary

Implements step 2 of docs/v2/PLAN.md §9: the in-memory query evaluator over V_gamma documents. This becomes the executable spec the SQL compiler (step 3) will be tested against.

Key Changes

  • src/did/+did2/query.m — V_gamma query value + evaluator:

    • Four-tuple {field, operation, param1, param2} search structure with and() / or() composition.
    • Operators from did-schema/schemas/did_query_model.md: exact_string, exact_string_anycase, contains_string, regexp, exact_number, lessthan(eq) / greaterthan(eq), hasfield, hasmember, hasanysubfield_contains_string, hasanysubfield_exact_string, isa, depends_on. ~-prefix negation on every operator except or.
    • Dot-path resolution with [*] array-of-structure iteration (existential semantics; independent quantifier across multiple [*] predicates per the model spec).
    • matches(doc), filter(docs, AsMask=) for list evaluation; static all() / none() helpers; resolvePath() and evaluate() exposed for the upcoming SQL compiler's reference-impl test harness.
  • tests/+did2/+unittest/testQuery.m — Function-based tests covering every operator, the ~ negation prefix, AND/OR composition, single and nested [*] iteration, the independent-quantifier semantics, filter / AsMask, and both did2.document and plain-struct input branches.

  • docs/v2/PLAN.md — Progress-log entry for step 2.

Implementation Details

  • isa matches the concrete class or any entry of document_class.superclasses[*].class_name. depends_on accepts a * wildcard on the name. Both operate directly on the V_gamma wire shape — no V_alpha-style lowering.
  • Composition: and() concatenates search-structure arrays; or() builds a single search structure whose operation is or and whose param1 / param2 are the sub-search-structure arrays. evaluateAll AND-s its struct array (empty matches vacuously); the or branch short-circuits on param1.
  • ~or is rejected at construction time with did2:query:badOperator (per the model spec, negating a boolean is expressed by combining negated leaves).
  • Unresolvable paths return {}. With a scalar operator that means no match; with ~-negation the match flips to true (literal reading of the spec).

Test plan

  • CI passes: did2.unittest.testQuery and pre-existing did2.unittest.testSchemaCache / did2.unittest.testDocumentScaffold all run green.
  • No regressions in the legacy +did suite.

https://claude.ai/code/session_013i5twd1zXsZyFXRjb4hbwL


Generated by Claude Code

Implements the abstract query model from
did-schema/schemas/did_query_model.md against V_gamma documents in
their class-scoped wire shape.

src/did/+did2/query.m:
- Four-tuple (field, operation, param1, param2) search-structure
  query value with and()/or() composition.
- Operators: exact_string, exact_string_anycase, contains_string,
  regexp, exact_number, lessthan(eq)/greaterthan(eq), hasfield,
  hasmember, hasanysubfield_contains_string,
  hasanysubfield_exact_string, isa, depends_on. `~`-prefix negation
  on every operator except `or`.
- Dot-path resolution with `[*]` array-of-structure iteration
  (existential semantics; independent quantifier across multiple
  predicates per the model spec).
- matches(doc), filter(docs, AsMask=) for list evaluation;
  static all()/none() helpers; resolvePath() and evaluate() exposed
  for the SQL compiler's reference-impl test harness.

tests/+did2/+unittest/testQuery.m:
- Function-based tests covering every operator, the `~` prefix, AND
  and OR composition, `[*]` iteration (single and nested),
  independent-quantifier semantics, filter/AsMask, and both the
  did2.document and plain-struct input branches.

docs/v2/PLAN.md:
- Progress log entry for step 2.

https://claude.ai/code/session_013i5twd1zXsZyFXRjb4hbwL
Comment thread src/did/+did2/query.m Fixed
Comment thread src/did/+did2/query.m Fixed
Comment thread src/did/+did2/query.m Fixed
- filter() return path: drop dead iscell branch (both legs were
  `out = docs(mask);`).
- walkPath non-iter case: drop dead isstruct guard (both legs were
  `next{end+1} = sub;`).
- opHasAnySubfieldExact: expand the one-line if/elseif/else to
  multi-line form so the analyzer's keyword alignment heuristic is
  happy.

No behavior change.

https://claude.ai/code/session_013i5twd1zXsZyFXRjb4hbwL
@stevevanhooser stevevanhooser merged commit 6eacd95 into V2 May 12, 2026
3 checks passed
@stevevanhooser stevevanhooser deleted the claude/did-v2-schema-stage2-nGrJx branch May 12, 2026 16:58
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.

3 participants