datalog

lilactown 2021-08-04T19:27:20.000700Z

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

Ben Sless 2021-08-07T06:19:20.013500Z

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

lilactown 2021-08-04T19:27:48.001200Z

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

quoll 2021-08-04T19:28:30.001700Z

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

lilactown 2021-08-04T19:29:44.002200Z

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

quoll 2021-08-04T19:30:43.003Z

You could start with my ClojureD talk from 2019?

lilactown 2021-08-04T19:31:16.003500Z

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

quoll 2021-08-04T19:31:50.003700Z

https://youtu.be/tbVwmFBnfo4

quoll 2021-08-04T19:32:18.004300Z

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

lilactown 2021-08-04T19:32:30.004500Z

ty!

lilactown 2021-08-04T19:33:00.004800Z

I also just found https://github.com/lambdaforge/datalog-parser

lilactown 2021-08-04T19:33:56.005200Z

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

quoll 2021-08-04T19:35:37.005700Z

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

quoll 2021-08-04T19:36:27.006500Z

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

lilactown 2021-08-04T19:37:05.006800Z

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

quoll 2021-08-04T19:37:36.007600Z

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

quoll 2021-08-04T19:38:06.007900Z

Specifically… https://github.com/threatgrid/naga/tree/d149904da8ecb510ddbbb5b73824c74da4b05d77/src/naga/storage/memory

👍🏻 1
quoll 2021-08-04T19:38:27.008500Z

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

quoll 2021-08-04T19:38:59.009200Z

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

lilactown 2021-08-04T19:39:12.009500Z

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

quoll 2021-08-05T00:12:33.010500Z

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]

quoll 2021-08-05T00:16:35.010700Z

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.

quoll 2021-08-04T19:40:04.009800Z

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

quoll 2021-08-04T19:40:17.010Z

that just does the reordering

quoll 2021-08-04T19:40:22.010200Z

you can turn it off

quoll 2021-08-04T19:40:27.010400Z

(And we often do)