rust-lang / rust-lang/datafrog
Datalog query with leapjoin
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 899
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
Hey, I'm just playing around with datafrog and trying to translate some basic datalog queries to the equivalent Rust code. I am wondering what something like the following snippet looks like in datafrog?
node(1, 'A').
node(2, 'B').
node(3, 'C').
node(4, 'D').
edge(1, 2).
edge(2, 3).
edge(3, 1).
edge(1, 4).
depthTwo(W1, W2) :-
page(T1, W1),
page(T2, W2),
link(T1, T2).
I'm mostly interested in leapjoin and have tried something like:
let mut iteration = Iteration::new();
let pages: Relation<_> = vec![
(1, "super.com"),
(2, "page.com"),
(3, "subpage.com"),
(4, "minpage.com"),
]
.into();
let edges: Relation<(u32, u32)> = vec![(1, 2), (2, 3), (3, 1), (1, 4)].into();
let edges_rev: Relation<_> = edges.iter().map(|&(from, to)| (to, from)).collect();
let var = iteration.variable::<(u32, &str)>("var");
var.insert(pages.clone());
while iteration.changed() {
var.from_leapjoin(
&var,
// So I technically would like to filter by the edges
// but the nodes i want to filter by are not really there yet?
// And I can't extend with nodes and filter with the edges
edges_rev.extend_with(|&(a, _)| a),
//
|&(a, b), &c| (a, b),
);
}
But I can't quite wrap my head around how the leapers work even after reading the comment given in the source code of the repo. Any pointers would be appreciated!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Iteration, Variable, and from_leapjoin entry points shown in the issue, then read the leaper comments in the source code. Compare the supplied pages and edges relations with the documented leapjoin inputs; done means a clear Rust equivalent or usage explanation for the Datalog query.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100