8000 Phase 7.3: Add or/or-join disjunction to Datalog query language by adityamukho · Pull Request #24 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

Phase 7.3: Add or/or-join disjunction to Datalog query language - #24

Merged
adityamukho merged 20 commits into
mainfrom
feature/phase-7-3-disjunction
Mar 26, 2026
Merged

adityamukho merged 20 commits into
mainfrom
feature/phase-7-3-disjunction

Conversation

@adityamukho
@adityamukho adityamukho comm 10BC8 ented Mar 26, 2026
Copy link
Copy Markdown
Collaborator

Summary

  • Adds (or branch1 branch2 ...) and (or-join [?vars] branch1 ...) disjunction clauses to Datalog queries and rule bodies
  • Branches support all clause types: Pattern, RuleInvocation, not, not-join, Expr, and nested or/or-join; (and ...) groups multiple clauses into one branch
  • Post-pass execution model: top-level patterns matched first, then apply_or_clauses, then existing not/not-join/Expr filters; rules with or/or-join route to the mixed_rules path in StratifiedEvaluator

Technical changes

  • WhereClause gains Or(Vec<Vec<WhereClause>>) and OrJoin { join_vars, branches } variants
  • New pub(crate) functions in executor.rs: evaluate_branch, apply_or_clauses
  • New pub(crate) method on PatternMatcher: match_patterns_seeded
  • DependencyGraph::from_rules refactored with recursive collect_clause_deps helper
  • Parse-time safety: or branches must introduce the same new variables; or-join join vars must be pre-bound; or/or-join inside not/not-join bodies rejected at parse time
  • Version bumped to 0.13.0

Test plan

  • cargo test — 384 lib tests + 17 integration tests, all passing
  • 16 dedicated integration tests in tests/disjunction_test.rs covering: union, filter, dedup, not inside branch, nested or, or-join variable stripping, multiple join vars, safety errors, rule bodies, :as-of temporal filter, stratification cycle detection

Notes

  • .wiki/Datalog-Reference.md has been updated with a new ## Disjunction section but the wiki commit requires GPG signing (/dev/tty unavailable in CI). Please commit it manually:
    cd .wiki && git add Datalog-Reference.md && git commit -m "docs: add Disjunction section for Phase 7.3 or/or-join"

🤖 Generated with Claude Code

adityamukho and others added 17 commits March 26, 2026 10:11
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…_invocation arm)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds Or(Vec<Vec<WhereClause>>) and OrJoin { join_vars, branches } variants
to WhereClause, extends rule_invocations(), has_negated_invocation(), and
collect_rule_invocations_recursive() to recurse into branches, and adds
stub arms in stratification.rs, parser.rs, and evaluator.rs to keep the
codebase compiling until later tasks implement full or/or-join support.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…pendency graph

Replace the stub Or/OrJoin match arm in DependencyGraph::from_rules with a
recursive free function collect_clause_deps that traverses Or/OrJoin branches
and propagates positive edges, while preserving negative edges for Not/NotJoin.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add parsing of (or ...), (or-join [...] ...), and (and ...) grouping in
:where clauses, including safety checks that all or-branches introduce
the same new variables and that or-join join-vars are already bound.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ute_query paths

Implements Or/OrJoin disjunction evaluation in the executor layer:
- evaluate_branch: evaluates a single or/or-join branch (patterns → nested-or → not/not-join → expr)
- apply_or_clauses: unions branch results with deduplication; OrJoin projects out branch-private vars
- Wired into execute_query (filtered_storage) and execute_query_with_rules (derived_storage)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ly_or_clauses

Extend the has_not inline closure to include WhereClause::Or and
WhereClause::OrJoin so rules with disjunction bodies are routed to the
mixed_rules path. Wire apply_or_clauses into the mixed-rules loop after
match_patterns and before apply_expr_clauses_in_evaluator. Add unit test
verifying both entities are derived when a rule body contains Or.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ranch, nested

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…fication tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…or/or-join

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… comments

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread src/query/datalog/parser.rs Fixed
Comment thread src/query/datalog/parser.rs Fixed
Comment thread src/query/datalog/parser.rs Fixed
adityamukho and others added 2 commits March 26, 2026 16:21
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread src/query/datalog/parser.rs Fixed
Comment thread src/query/datalog/parser.rs Fixed
Comment thread src/query/datalog/parser.rs Fixed
…deQL)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@adityamukho
adityamukho merged commit 0bd6a55 into main Mar 26, 2026
13 checks passed
@adityamukho
adityamukho deleted the feature/phase-7-3-disjunction branch March 26, 2026 11:03
Sign up for free to join this conversati 6369 on 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.

2 participants

0