datalog: dl-magic-query handles mixed EDB+IDB relations (225/225)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
Bug: dl-magic-query was skipping EDB facts for relations that had
rules ("rule-headed"). When a single relation has both EDB facts
and rules deriving more (mixed EDB+IDB), the rewritten run would
miss the EDB portion entirely, producing too few or zero results.
Fix: copy ALL existing facts to the internal mdb regardless of
whether the relation has rules. EDB-only relations bring their
tuples; mixed relations bring both EDB and any pre-saturated IDB
(which the rewritten rules would re-derive anyway).
1 new test: link relation seeded with 3 EDB tuples plus a
recursive rule via via/2. dl-magic-query rooted at `a` returns
2 results (a→b direct, a→c via via(a,e), link(e,c)).
This commit is contained in:
@@ -397,15 +397,18 @@
|
|||||||
(mdb (dl-make-db))
|
(mdb (dl-make-db))
|
||||||
(rule-heads (dl-magic-rule-heads rules)))
|
(rule-heads (dl-magic-rule-heads rules)))
|
||||||
(do
|
(do
|
||||||
;; Copy EDB facts (relations not headed by any caller rule).
|
;; Copy ALL existing facts. EDB-only relations bring their
|
||||||
|
;; tuples; mixed EDB+IDB relations bring both their EDB
|
||||||
|
;; portion and any pre-saturated IDB tuples (which the
|
||||||
|
;; rewritten rules would re-derive anyway). Skipping facts
|
||||||
|
;; for rule-headed relations would leave the magic run
|
||||||
|
;; without the EDB portion of mixed relations.
|
||||||
(for-each
|
(for-each
|
||||||
(fn
|
(fn
|
||||||
(rel)
|
(rel)
|
||||||
(when
|
(for-each
|
||||||
(not (dl-member-string? rel rule-heads))
|
(fn (t) (dl-add-fact! mdb t))
|
||||||
(for-each
|
(dl-rel-tuples db rel)))
|
||||||
(fn (t) (dl-add-fact! mdb t))
|
|
||||||
(dl-rel-tuples db rel))))
|
|
||||||
(keys (get db :facts)))
|
(keys (get db :facts)))
|
||||||
;; Seed + rewritten rules.
|
;; Seed + rewritten rules.
|
||||||
(dl-add-fact! mdb (get rewritten :seed))
|
(dl-add-fact! mdb (get rewritten :seed))
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"lang": "datalog",
|
"lang": "datalog",
|
||||||
"total_passed": 224,
|
"total_passed": 225,
|
||||||
"total_failed": 0,
|
"total_failed": 0,
|
||||||
"total": 224,
|
"total": 225,
|
||||||
"suites": [
|
"suites": [
|
||||||
{"name":"tokenize","passed":26,"failed":0,"total":26},
|
{"name":"tokenize","passed":26,"failed":0,"total":26},
|
||||||
{"name":"parse","passed":18,"failed":0,"total":18},
|
{"name":"parse","passed":18,"failed":0,"total":18},
|
||||||
@@ -13,8 +13,8 @@
|
|||||||
{"name":"negation","passed":10,"failed":0,"total":10},
|
{"name":"negation","passed":10,"failed":0,"total":10},
|
||||||
{"name":"aggregates","passed":19,"failed":0,"total":19},
|
{"name":"aggregates","passed":19,"failed":0,"total":19},
|
||||||
{"name":"api","passed":20,"failed":0,"total":20},
|
{"name":"api","passed":20,"failed":0,"total":20},
|
||||||
{"name":"magic","passed":24,"failed":0,"total":24},
|
{"name":"magic","passed":25,"failed":0,"total":25},
|
||||||
{"name":"demo","passed":21,"failed":0,"total":21}
|
{"name":"demo","passed":21,"failed":0,"total":21}
|
||||||
],
|
],
|
||||||
"generated": "2026-05-08T10:36:02+00:00"
|
"generated": "2026-05-08T10:40:13+00:00"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# datalog scoreboard
|
# datalog scoreboard
|
||||||
|
|
||||||
**224 / 224 passing** (0 failure(s)).
|
**225 / 225 passing** (0 failure(s)).
|
||||||
|
|
||||||
| Suite | Passed | Total | Status |
|
| Suite | Passed | Total | Status |
|
||||||
|-------|--------|-------|--------|
|
|-------|--------|-------|--------|
|
||||||
@@ -13,5 +13,5 @@
|
|||||||
| negation | 10 | 10 | ok |
|
| negation | 10 | 10 | ok |
|
||||||
| aggregates | 19 | 19 | ok |
|
| aggregates | 19 | 19 | ok |
|
||||||
| api | 20 | 20 | ok |
|
| api | 20 | 20 | ok |
|
||||||
| magic | 24 | 24 | ok |
|
| magic | 25 | 25 | ok |
|
||||||
| demo | 21 | 21 | ok |
|
| demo | 21 | 21 | ok |
|
||||||
|
|||||||
@@ -197,6 +197,19 @@
|
|||||||
6)
|
6)
|
||||||
|
|
||||||
;; dl-magic-query: end-to-end driver, doesn't mutate caller's db.
|
;; dl-magic-query: end-to-end driver, doesn't mutate caller's db.
|
||||||
|
;; Mixed EDB + IDB: a relation can be both EDB-seeded and
|
||||||
|
;; rule-derived. dl-magic-query must include the EDB portion
|
||||||
|
;; even though the relation has rules.
|
||||||
|
(dl-mt-test! "magic mixed EDB+IDB"
|
||||||
|
(len
|
||||||
|
(dl-magic-query
|
||||||
|
(dl-program
|
||||||
|
"link(a, b). link(c, d). link(e, c).
|
||||||
|
via(a, e).
|
||||||
|
link(X, Y) :- via(X, M), link(M, Y).")
|
||||||
|
(list (quote link) (quote a) (quote X))))
|
||||||
|
2)
|
||||||
|
|
||||||
;; dl-magic-query falls back to dl-query for built-in,
|
;; dl-magic-query falls back to dl-query for built-in,
|
||||||
;; aggregate, and negation goals (the magic seed would
|
;; aggregate, and negation goals (the magic seed would
|
||||||
;; otherwise be non-ground).
|
;; otherwise be non-ground).
|
||||||
|
|||||||
Reference in New Issue
Block a user