v2 step 2: add did2.query in-memory evaluator#121
Merged
Conversation
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
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:{field, operation, param1, param2}search structure withand()/or()composition.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 exceptor.[*]array-of-structure iteration (existential semantics; independent quantifier across multiple[*]predicates per the model spec).matches(doc),filter(docs, AsMask=)for list evaluation; staticall()/none()helpers;resolvePath()andevaluate()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 bothdid2.documentand plain-struct input branches.docs/v2/PLAN.md— Progress-log entry for step 2.Implementation Details
isamatches the concrete class or any entry ofdocument_class.superclasses[*].class_name.depends_onaccepts a*wildcard on the name. Both operate directly on the V_gamma wire shape — no V_alpha-style lowering.and()concatenates search-structure arrays;or()builds a single search structure whoseoperationisorand whoseparam1/param2are the sub-search-structure arrays.evaluateAllAND-s its struct array (empty matches vacuously); theorbranch short-circuits onparam1.~oris rejected at construction time withdid2:query:badOperator(per the model spec, negating a boolean is expressed by combining negated leaves).{}. With a scalar operator that means no match; with~-negation the match flips to true (literal reading of the spec).Test plan
did2.unittest.testQueryand pre-existingdid2.unittest.testSchemaCache/did2.unittest.testDocumentScaffoldall run green.+didsuite.https://claude.ai/code/session_013i5twd1zXsZyFXRjb4hbwL
Generated by Claude Code