Repository navigation
Phase 3 Complete: Datalog with Recursive Rules - #5
Merged
Merged
Conversation
Strategic pivot after Phase 2 completion: transitioning from GQL-inspired implementation to Datalog query language with bi-temporal support as a first-class feature. ## Changes ### README.md - Updated project tagline: "SQLite of bi-temporal graph databases" - Replaced GQL examples with Datalog query syntax - Added "Why Datalog?" section explaining the pivot rationale - Updated roadmap summary (12-15 months vs 24-30 with GQL) - Added comparison table (Minigraf vs XTDB, Cozo, Datomic, GraphLite) - Emphasized bi-temporal as core feature, not addon - Added learning resources for Datalog and temporal databases ### PHILOSOPHY.md - Added "Why Datalog?" section at the top - Explained 5 key reasons for pivot: simpler, temporal-native, more powerful, faster to production, unique positioning - Updated "What Minigraf IS" to include bi-temporal and Datalog - Updated target use cases (audit-heavy apps, event sourcing as primary) - Updated Evolution Strategy with new phase breakdown (3-7) - Added Datomic, XTDB, Cozo to inspirations - Removed GQL spec compliance from non-goals ### ROADMAP.md - Complete rewrite reflecting Datalog-focused roadmap - Phase 1-2: Archived as complete (GQL implementation) - Phase 3: Datalog Core (EAV model, recursive rules) - NEXT - Phase 4: Bi-temporal Support (transaction + valid time) - Phase 5: ACID + WAL (moved after bi-temporal) - Phase 6: Performance & Indexes - Phase 7: Cross-platform (WASM, mobile, bindings) - Phase 8: Ecosystem & Tooling - Detailed technical approach for each phase - Timeline: 12-15 months to v1.0 (vs 24-30 with GQL) - Added "Why This Roadmap is Better" section ### CLAUDE.md - Updated project overview to emphasize Datalog + bi-temporal - Added strategic pivot explanation - Updated architecture section for Phase 3 transition - Documented current (property graph) vs future (EAV) data models - Added bi-temporal Fact structure for Phase 4 - Updated query language examples (GQL archived, Datalog target) - Added migration strategy for Phase 3 - Updated comparison to similar projects - Emphasized philosophy alignment throughout ## Rationale After completing Phase 2 and evaluating the competitive landscape: 1. GraphLite already provides mature GQL implementation 2. Datalog offers simpler implementation path (proven patterns) 3. Bi-temporal support is natural in Datalog (time as dimension) 4. Unique market positioning: single-file bi-temporal Datalog (gap exists) 5. Faster to production: 12-15 months vs 24-30 months GQL implementation archived at `archive/gql-phase-2` branch. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add Entity-Attribute-Value (EAV) data model types alongside existing property graph types as first step of Datalog implementation. ## New Types ### Core EAV Types: - `EntityId` - UUID-based entity identifiers - `TxId` - u64 transaction IDs for versioning - `Attribute` - String-based attribute names (`:person/name` style) - `Value` - Extended enum supporting: - String, Integer, Float, Boolean (like PropertyValue) - Ref(EntityId) - NEW: References to other entities - Keyword(String) - NEW: Keywords like `:status/active` - Null - `Fact` - Core EAV triple: (Entity, Attribute, Value, TxId, Asserted) ### Fact Structure: - Immutable facts with transaction tracking - `asserted` flag for retractions (instead of deletions) - Support for assertion and retraction operations - Maintains full history for temporal queries ## Implementation Details - Added comprehensive accessor methods for Value enum - Factory methods for Fact creation (new, retract, with_asserted) - Full serde support for serialization - PartialEq implementations for testing ## Tests Added (6 new tests): - `test_value_creation_and_accessors` - All Value variants - `test_fact_creation` - Basic fact assertions - `test_fact_retraction` - Fact retractions - `test_fact_with_ref_value` - Entity references (graph edges) - `test_fact_equality` - Fact comparison logic - `test_value_types` - Serialization/deserialization ## Migration Strategy Property graph types (Node, Edge, PropertyValue) preserved for backward compatibility during Phase 3 transition. EAV types added alongside, exported from lib.rs with clear comments. All 9 tests passing (3 existing + 6 new). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Change TxId from simple counter to timestamp (milliseconds since UNIX epoch) for natural chronological ordering and better Phase 4 preparation. ## Changes - TxId now represents milliseconds since UNIX epoch - Added helper functions: - `tx_id_now()` - Get current timestamp as TxId - `tx_id_from_system_time()` - Convert SystemTime to TxId - `tx_id_to_system_time()` - Convert TxId back to SystemTime - Exported helpers from lib.rs for public use ## Benefits 1. **Natural ordering** - TxIds are chronologically ordered by default 2. **Human-readable** - Can convert to datetime for debugging 3. **Phase 4 ready** - Consistent with bi-temporal valid_time (also timestamps) 4. **No collision** - Millisecond precision sufficient for Phase 3 single-threaded usage ## Tests Added - `test_tx_id_timestamp` - Verifies chronological ordering and round-trip conversion - `test_tx_id_ordering` - Confirms sequential TxIds are strictly increasing All 11 tests passing. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Merge Phase 3 Datalog Core implementation from main branch. Resolved conflict in src/lib.rs by keeping FactStorage export. All 81 tests passing. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace GQL-focused demo with comprehensive Datalog examples: - Transact facts with keyword entities - Multi-pattern queries with variable unification - Graph relationships using entity references - Retractions and updates - Complex queries (friends, employment) Also document: - Backward compatibility with GQL syntax - Key differences between Datalog and GQL - Future Phase 4+ features Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Simplify REPL to Datalog-only: - Remove GraphStorage and GQL executor from REPL - REPL now only accepts Datalog syntax - Simplified Repl struct to only use FactStorage - Updated main.rs to create FactStorage instead of GraphStorage - Removed GQL backward compatibility notes from demo_commands.txt Changes: - src/repl.rs: Removed all GQL imports and execution paths - src/main.rs: Changed from GraphStorage to FactStorage - demo_commands.txt: Removed GQL syntax examples and comparison Note: GQL parser/executor code remains in the library for potential library users, but is no longer accessible via the REPL. All 81 tests passing. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
After successfully implementing Phase 3 (Datalog Core), we no longer need the Phase 1-2 GQL implementation. This commit removes all GQL-related code to simplify the codebase and eliminate backward compatibility burden. Removed: - Property graph types (Node, Edge, PropertyValue, Property) - GraphStorage in-memory storage for property graphs - GQL parser (src/query/parser.rs) - GQL executor (src/query/executor.rs) - Minigraf high-level API (src/minigraf.rs) - GQL-based - PersistentGraphStorage (src/storage/persistent.rs) - GQL examples (examples/embedded.rs, examples/file_storage.rs) - GQL integration tests (tests/*.rs) Kept (Datalog Phase 3+): - FactStorage (EAV model storage) - Datalog types (Fact, Value, EntityId, TxId, Attribute) - Datalog parser, executor, and pattern matcher - REPL (now Datalog-only) - Storage backend abstraction (FileBackend, MemoryBackend) - All Datalog tests (56 tests passing) The codebase is now fully committed to Datalog as the query language, with no GQL legacy code remaining. GQL is preserved in git history (archive/gql-phase-2 branch and gql-phase-2-complete tag). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed a critical bug where queries using keyword entities (like :alice) would fail to match facts in storage. The issue was in the pattern matcher's match_component function, which didn't handle the case where a keyword entity needs to be converted to a UUID before comparing with stored facts. Changes: - Updated match_component in src/query/datalog/matcher.rs to convert keyword entities to UUIDs using edn_to_entity_id before comparison - Keywords can now match both Value::Keyword (for attributes) and Value::Ref (for entities, after UUID conversion) This enables queries like: (query [:find ?name :where [:alice :person/name ?name]]) to correctly match facts transacted with keyword entities. Known limitation (Phase 3): Queries return all asserted facts including historical versions. Proper temporal filtering (e.g., filtering out retracted facts) is planned for Phase 4 (bi-temporal support). Verified with manual REPL testing - keyword entities now work correctly. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added optional file-based persistence to the REPL, allowing users to save and load Datalog facts from .graph files. The REPL now supports both in-memory (default) and file-based storage modes. New Features: - CLI argument parsing using clap crate (--file/-f option) - PersistentFactStorage wrapper for FactStorage with StorageBackend - File format: Page 0 = header, Page 1+ = serialized facts - Auto-save on REPL exit when using file-based storage - Data persists across REPL sessions Changes: - Added clap dependency to Cargo.toml - Created src/storage/persistent_facts.rs with PersistentFactStorage - Updated src/main.rs to parse CLI args and support both storage modes - Updated src/lib.rs to export FileBackend and PersistentFactStorage - Updated src/storage/mod.rs to include persistent_facts module Usage: # In-memory mode (default, no persistence) cargo run # File-based mode (persists to .graph file) cargo run -- --file mydb.graph # Help cargo run -- --help Architecture: - In-memory: FactStorage with Arc<RwLock<Vec<Fact>>> - File-based: PersistentFactStorage wraps FactStorage + FileBackend - Both modes share same REPL and query execution code - FactStorage cloning shares underlying data via Arc (zero-copy) Tested: - In-memory mode works as before - File-based mode persists and loads facts correctly - Data survives REPL restarts - All 59 library tests pass Phase 3 milestone: Basic persistence for Datalog facts complete. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Switched from bincode (unmaintained/abandoned) to postcard for fact serialization. bincode was completely abandoned in late 2024 after its maintainer faced harassment, and the 3.0.0 release intentionally breaks builds to alert users. Why postcard: - Actively maintained, moving toward v1.0 release - Lightweight and embedded-focused (aligns with philosophy) - Better size characteristics than bincode - Drop-in replacement with minimal code changes - Serde-based, familiar API Changes: - Updated Cargo.toml: bincode 1.3 -> postcard 1.0 (with alloc feature) - Updated src/storage/persistent_facts.rs: - bincode::deserialize -> postcard::from_bytes - bincode::serialize -> postcard::to_allocvec - Updated CLAUDE.md with serialization notes and rkyv evaluation plan - Added note to evaluate rkyv in Phase 5/6 for zero-copy deserialization when implementing WAL or memory-mapped database access Testing: - All 59 library tests pass - File persistence works correctly with postcard format - Data loads/saves correctly across REPL sessions - Binary size unchanged (1.2MB) Why postcard over rkyv now: - Lightweight and embedded-focused (aligns with philosophy) - Drop-in replacement for bincode - Active development (v1.0+ releases) - Simpler than rkyv (no zero-copy complexity yet) - Good balance of performance and simplicity Why not rkyv now: - Heavy dependency that spreads through codebase - Adds complexity without immediate performance need - Better suited for Phase 5/6 (WAL, memory-mapped access) - Can evaluate when performance optimization becomes critical Breaking Change Note: - File format is NOT backward compatible with bincode - .graph files created with bincode cannot be read with postcard - This is acceptable in Phase 3 (pre-v1.0, no backwards compat promise yet) - Users must recreate databases if using file-based storage All 59 tests pass. Persistence works correctly. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace GQL-focused demo with comprehensive Datalog examples: - Transact facts with keyword entities - Multi-pattern queries with variable unification - Graph relationships using entity references - Retractions and updates - Complex queries (friends, employment) Also document: - Backward compatibility with GQL syntax - Key differences between Datalog and GQL - Future Phase 4+ features Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Simplify REPL to Datalog-only: - Remove GraphStorage and GQL executor from REPL - REPL now only accepts Datalog syntax - Simplified Repl struct to only use FactStorage - Updated main.rs to create FactStorage instead of GraphStorage - Removed GQL backward compatibility notes from demo_commands.txt Changes: - src/repl.rs: Removed all GQL imports and execution paths - src/main.rs: Changed from GraphStorage to FactStorage - demo_commands.txt: Removed GQL syntax examples and comparison Note: GQL parser/executor code remains in the library for potential library users, but is no longer accessible via the REPL. All 81 tests passing. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
After successfully implementing Phase 3 (Datalog Core), we no longer need the Phase 1-2 GQL implementation. This commit removes all GQL-related code to simplify the codebase and eliminate backward compatibility burden. Removed: - Property graph types (Node, Edge, PropertyValue, Property) - GraphStorage in-memory storage for property graphs - GQL parser (src/query/parser.rs) - GQL executor (src/query/executor.rs) - Minigraf high-level API (src/minigraf.rs) - GQL-based - PersistentGraphStorage (src/storage/persistent.rs) - GQL examples (examples/embedded.rs, examples/file_storage.rs) - GQL integration tests (tests/*.rs) Kept (Datalog Phase 3+): - FactStorage (EAV model storage) - Datalog types (Fact, Value, EntityId, TxId, Attribute) - Datalog parser, executor, and pattern matcher - REPL (now Datalog-only) - Storage backend abstraction (FileBackend, MemoryBackend) - All Datalog tests (56 tests passing) The codebase is now fully committed to Datalog as the query language, with no GQL legacy code remaining. GQL is preserved in git history (archive/gql-phase-2 branch and gql-phase-2-complete tag). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed a critical bug where queries using keyword entities (like :alice) would fail to match facts in storage. The issue was in the pattern matcher's match_component function, which didn't handle the case where a keyword entity needs to be converted to a UUID before comparing with stored facts. Changes: - Updated match_component in src/query/datalog/matcher.rs to convert keyword entities to UUIDs using edn_to_entity_id before comparison - Keywords can now match both Value::Keyword (for attributes) and Value::Ref (for entities, after UUID conversion) This enables queries like: (query [:find ?name :where [:alice :person/name ?name]]) to correctly match facts transacted with keyword entities. Known limitation (Phase 3): Queries return all asserted facts including historical versions. Proper temporal filtering (e.g., filtering out retracted facts) is planned for Phase 4 (bi-temporal support). Verified with manual REPL testing - keyword entities now work correctly. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added optional file-based persistence to the REPL, allowing users to save and load Datalog facts from .graph files. The REPL now supports both in-memory (default) and file-based storage modes. New Features: - CLI argument parsing using clap crate (--file/-f option) - PersistentFactStorage wrapper for FactStorage with StorageBackend - File format: Page 0 = header, Page 1+ = serialized facts - Auto-save on REPL exit when using file-based storage - Data persists across REPL sessions Changes: - Added clap dependency to Cargo.toml - Created src/storage/persistent_facts.rs with PersistentFactStorage - Updated src/main.rs to parse CLI args and support both storage modes - Updated src/lib.rs to export FileBackend and PersistentFactStorage - Updated src/storage/mod.rs to include persistent_facts module Usage: # In-memory mode (default, no persistence) cargo run # File-based mode (persists to .graph file) cargo run -- --file mydb.graph # Help cargo run -- --help Architecture: - In-memory: FactStorage with Arc<RwLock<Vec<Fact>>> - File-based: PersistentFactStorage wraps FactStorage + FileBackend - Both modes share same REPL and query execution code - FactStorage cloning shares underlying data via Arc (zero-copy) Tested: - In-memory mode works as before - File-based mode persists and loads facts correctly - Data survives REPL restarts - All 59 library tests pass Phase 3 milestone: Basic persistence for Datalog facts complete. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Switched from bincode (unmaintained/abandoned) to postcard for fact serialization. bincode was completely abandoned in late 2024 after its maintainer faced harassment, and the 3.0.0 release intentionally breaks builds to alert users. Why postcard: - Actively maintained, moving toward v1.0 release - Lightweight and embedded-focused (aligns with philosophy) - Better size characteristics than bincode - Drop-in replacement with minimal code changes - Serde-based, familiar API Changes: - Updated Cargo.toml: bincode 1.3 -> postcard 1.0 (with alloc feature) - Updated src/storage/persistent_facts.rs: - bincode::deserialize -> postcard::from_bytes - bincode::serialize -> postcard::to_allocvec - Updated CLAUDE.md with serialization notes and rkyv evaluation plan - Added note to evaluate rkyv in Phase 5/6 for zero-copy deserialization when implementing WAL or memory-mapped database access Testing: - All 59 library tests pass - File persistence works correctly with postcard format - Data loads/saves correctly across REPL sessions - Binary size unchanged (1.2MB) Why postcard over rkyv now: - Lightweight and embedded-focused (aligns with philosophy) - Drop-in replacement for bincode - Active development (v1.0+ releases) - Simpler than rkyv (no zero-copy complexity yet) - Good balance of performance and simplicity Why not rkyv now: - Heavy dependency that spreads through codebase - Adds complexity without immediate performance need - Better suited for Phase 5/6 (WAL, memory-mapped access) - Can evaluate when performance optimization becomes critical Breaking Change Note: - File format is NOT backward compatible with bincode - .graph files created with bincode cannot be read with postcard - This is acceptable in Phase 3 (pre-v1.0, no backwards compat promise yet) - Users must recreate databases if using file-based storage All 59 tests pass. Persistence works correctly. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit completes Phase 3 by implementing recursive Datalog rules with semi-naive evaluation, comprehensive testing, and full documentation. New Features: - Recursive rules with semi-naive fixed-point evaluation - Transitive closure queries (multi-hop reachability) - Cycle handling (converges correctly with cycles) - RuleRegistry for thread-safe rule management - RecursiveEvaluator with delta-based iteration - WhereClause enum to support rule invocations in queries New Files: - src/query/datalog/rules.rs: RuleRegistry implementation - src/query/datalog/evaluator.rs: RecursiveEvaluator with semi-naive algorithm - tests/complex_queries_test.rs: 10 integration tests for complex queries - tests/recursive_rules_test.rs: 9 integration tests for recursive rules - tests/concurrency_test.rs: 7 concurrency tests for thread safety - demo_recursive.txt: Comprehensive demo of recursive rules Test Coverage: 123 tests (94 unit + 26 integration + 3 doc) - Complex queries (3+ patterns, self-joins, entity references) - Recursive rules (transitive closure, cycles, long chains, family trees) - Concurrency (50+ concurrent threads, no deadlocks, RwLock consistency) Updated Documentation: - TEST_COVERAGE.md: Phase 3 completion report with ~92% coverage - CLAUDE.md: Reflected Phase 3 completion status Phase 3 Success Criteria: ALL MET - Rules registration and invocation working - Transitive closure correct - Fixed-point convergence verified - 123 comprehensive tests (exceeded 80+ goal) - Documentation complete Ready for Phase 4 (Bi-temporal Support). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The scan-pr job was failing due to deprecated actions/upload-artifact version. Keeping scan-scheduled job for periodic vulnerability scanning.
This reverts commit 27fe557.
Updated both scan-scheduled and scan-pr jobs to use the latest version (v2.3.1) which resolves the deprecated actions/upload-artifact warnings. Commit SHA: 375a0e8ebdc98e99b02ac4338a724f5750f21213
The updated OSV-Scanner reusable workflow requires actions:read permission. This resolves the 'actions: none' error in the workflow runs.
Replace or_insert_with(Vec::new) with the more idiomatic or_default(). This is the recommended pattern for inserting default values in Rust. Fixes code scanning alert in PR #5.
9 tasks done
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.
Phase 3 Completion: Datalog with Recursive Rules ✅
This PR completes Phase 3 of Minigraf by implementing recursive Datalog rules with semi-naive evaluation, comprehensive testing, and full documentation.
🎯 What's New
Core Features Implemented
Architecture
src/query/datalog/rules.rs(150 lines) - RuleRegistry implementationsrc/query/datalog/evaluator.rs(630+ lines) - RecursiveEvaluatorsrc/query/datalog/types.rs- WhereClause enum (Pattern | RuleInvocation)src/query/datalog/executor.rs- Integrated RecursiveEvaluatorsrc/query/datalog/parser.rs- Parse rule invocations in queries📊 Test Coverage
Total Tests: 123 (up from 59 at start of Phase 3)
New Integration Test Suites
tests/complex_queries_test.rs(10 tests)tests/recursive_rules_test.rs(9 tests)tests/concurrency_test.rs(7 tests)Coverage: ~92% (estimated)
🎬 Demo
New demo script showing recursive rules in action:
cargo run < demo_recursive.txtDemonstrates:
✅ Phase 3 Success Criteria - ALL MET
(rule ...)syntax(predicate ?args)syntax📈 Code Changes
Files Created
src/query/datalog/rules.rssrc/query/datalog/evaluator.rstests/complex_queries_test.rstests/recursive_rules_test.rstests/concurrency_test.rsdemo_recursive.txtDocumentation Updated
TEST_COVERAGE.md- Phase 3 completion reportCLAUDE.md- Phase 3 status and features🚀 What This Enables
Recursive Queries
Family Trees
Handles Cycles Correctly
🔍 Quality Assurance
Thread Safety
Cycle Handling
Performance
📝 Next Steps
Phase 4: Bi-temporal Support (Next)
:as-of tx-id)valid_from,valid_to):valid-at timestamp)🎉 Ready to Merge
Status: ✅ Production-ready for Phase 3 scope
All tests passing, documentation complete, demo working.
Confidence Level: High - Comprehensive test coverage and quality assurance.
🤖 Generated with Claude Code