Fork me on GitHub
#datalog
<
2021-08-04
>
lilactown19:08:20

are there any resources on writing a datalog parser/query engine?

Ben Sless06:08:20

The datalog bnf can be translated to spec or malli (I have an example of the latter) You can then call parse/decode and bob's your uncle That takes care of parsing, at least

lilactown19:08:48

(by which I mean a datomic-like query syntax)

quoll19:08:30

Not that I know of, but what would you like to know?

lilactown19:08:44

I sort of assume there's a theoretical starting point that would be useful if I wanted to write my own

quoll19:08:43

You could start with my ClojureD talk from 2019?

lilactown19:08:16

I have been reading asami's source code but perhaps I'll begin again there 😄

quoll19:08:18

It starts a bit simplistically, but gets into the “how”

lilactown19:08:56

but I think i'd like to write my own parser, to understand it better

quoll19:08:37

Asami doesn’t actually parse. It just uses Clojure structures

quoll19:08:27

tweaks this a little to form the AST, does some algebra and reordering on it, and then executes it

lilactown19:08:05

that's essentially what I want to do, I think

quoll19:08:36

If you look at Asami, I recommend going back to an earlier iteration

quoll19:08:27

that did joins and filters only, but it was much easier to follow

quoll19:08:59

once you have that, then the latest code will make much more sense

lilactown19:08:12

I was getting a bit lost this morning in the planner distinctions and how that effected everything

quoll00:08:33

Also, the code I pointed you at doesn’t handle queries as you’re familiar with them. You’d be looking for the query function in code.clj line 294. After the storage object, this function takes 2 arguments: • output-pattern: this is the content of a :find clause and can be something like [?p ?v]patterns: this is the content of a :where clause, and can be something like [?e :age ?a] [(> ?a 20)] [?e ?p ?v]

quoll00:08:35

The plan-path function can be safely ignored. Just assume that the output plan value is the same as the input patterns value. It also returns resolution-map, but that’s a bit misleading. It’s just that the default planner used this map, and the first step of the query also happened to use this map, and I figured I could save myself a step by returning it and using it, rather than looking it up again.

quoll19:08:04

yes… I wouldn’t look at that AT ALL 🙂

quoll19:08:17

that just does the reordering

quoll19:08:22

you can turn it off

quoll19:08:27

(And we often do)

Ben Sless06:08:20

The datalog bnf can be translated to spec or malli (I have an example of the latter) You can then call parse/decode and bob's your uncle That takes care of parsing, at least