Fix query-engine bugs: :in predicate bindings, intra-tx lookup refs, EDN symbol chars - #15
Merged
Merged
Conversation
… symbol chars - query_where: substitute :in bindings into equality/comparison-N predicates, arithmetic/value clauses, source clauses, and not/not-join clauses in bound_relation_clause so the relation fast path no longer drops rows for [(= ?v ?target)] / [(not= ...)] over :in-bound vars - transact: resolve entity-map attr values per attr at add time against the accumulating tx datoms (upstream sequential [:db/add] order) so lookup refs see datoms added by earlier attrs of the same entity map; upsert probes resolve non-strictly like upstream resolve-upserts - parser: ' is a non-terminating macro char in EDN, so it is legal mid-symbol; remove it from the delimiter set so symbols/keywords like foo*+!_'?<>=- tokenize like upstream cljs reader - tests: new test_query_engine_fixes suite covering recursive-rule direction, predicates over :in scalars and collections, intra-tx lookup refs, and EDN symbol special chars; upstream alias entries added for ported tests
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
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
Fixes several engine bugs hit by the Logseq db-worker port, root-caused in the engine and verified against upstream juxt/datascript semantics. New test suite
test_query_engine_fixescovers each fix (upstream tests ported where they exist; aliases added toupstream_test_aliases.tsv).Bug:
[(= ...)]/[(not= ...)]predicates over:in-bound vars drop all rows — CONFIRMED + FIXED.bound_relation_clauseinimpl/query_where.mlonly substituted bindings into patterns and 2-argComparisonPredicate, leavingEqualityPredicate/ComparisonPredicateNuntouched. A:in-bound var stayed aQVar, sofilter_relation_equalitycouldn't resolve it and every row was dropped. Now all relation-evaluable clause kinds get bound: equality predicates, N-arg comparison predicates, arithmetic/name/namespace/keyword value clauses,SourceClause, andNot/SourceNot/NotJoin/SourceNotJoin(the function is nowrec).[(= ?v ?target)]and[(not= ?d ?x)]over:inscalars now return the right rows.Bug: intra-transaction lookup refs in entity maps fail — CONFIRMED + FIXED.
apply_entity_mapcalledresolve_entity_attrswhich strictly resolved all attr values against the datoms accumulated before the entity map ran. An attr value like[:block/uuid #uuid "..."]referencing an entity created by an earlier attr of the same map (or an earlier tx op) raised "Nothing found for entity id". Upstreamtransactresolves each[:db/add]op sequentially against the accumulatingdb-after. Now the entity-map fold resolves eachtx_valuestrictly insideapply_attrat its add step, so earlier attrs of the same map are visible; the upsert probe (entity_unique_identity,validate_explicit_upsert_target,tuple_identity_lookup_writes) uses a non-strict resolution matching upstreamresolve-upserts(unresolvable refs keep raw form and never match). Verified: earlier-op refs, same-entity self-refs, Add-op refs to earlier-tx entities, tempid/uuid upsert merging all work; forward refs and unresolvable refs still correctly raise.Bug: EDN reader can't tokenize
'inside symbols/keywords — CONFIRMED + FIXED.'was inread_edn'sis_delimiterset, splittingfoo'intofoo+ quote. Upstream EDN treats'as a non-terminating macro char: special only at token start, legal mid-symbol. Removed from the delimiter set; leading-'quoting still works viaparse_form.{:user.property/foo*+!_'?<>=- nil}and[sym' foo*+!_'?<>=- 'quoted ?var]now parse like cljsedn/read-string.Bug 1 (recursive rules wrong direction): not reproducible — ported upstream
test-rulescases (recursive walk, "Rule with branches" positional binding with renamed head vars, swapped-arg symmetric closure) all pass on main. Kept as regression tests.Bug 3 (
[?x ...]collection:inignored): not reproducible — collection inputs iterate correctly via the sequential clause path; ported upstreamtest-bindingscollection case kept as regression test.Bug 4 (avet not backfilled on kvs sqlite restore): not reproducible — restore paths rebuild avet (existing sqlite test asserts
datoms restored Avet; memory/file storage verified empirically: attr+value lookups, lookup-ref resolution, and avet queries all work post-restore).Full
dune runtestis green with upstream parity checks enabled.Link to Devin session: https://app.devin.ai/sessions/c82925b6976a4a6da2688c410e65011a
Open in Devin Desktop: https://app.devin.ai/desktop/session/c82925b6976a4a6da2688c410e65011a?variant=devin
Requested by: @tiensonqin