asami

Asami, the graph database https://github.com/threatgrid/asami
Steven Deobald 2021-06-04T01:51:59.072800Z

https://github.com/threatgrid/asami/wiki/Introduction#multiple-answers => To see this, let's look for all of the _*:first-name*_s again. ... renders a little weirdly on GitHub. Took me a minute to parse "Part 1/2" ~= "Pattern 1 / 2" (in the table) in this section: https://github.com/threatgrid/asami/wiki/Introduction#part-2-1 ... maybe labels on the patterns themselves would help with clarity? (Ditto Part 3... though I think by the time a person gets that far, the references to the query triples is obvious.) @quoll This is a great intro! I don't think I've seen these kinds of query / image pairings before. They really do a nice job of demonstrating what each clause is doing. šŸ™‚

quoll 2021-06-04T01:55:55.074200Z

Thanks for the first one. Fixed. The second oneā€¦ I was just breaking it down into partsā€¦ it didnā€™t occur to me exactly that there was a one-to-one with patterns. Should I rename the sections ā€œPattern 1ā€, ā€œPattern 2", ā€œPattern 3ā€?

Steven Deobald 2021-06-04T01:56:24.074500Z

That would work too, yup.

Steven Deobald 2021-06-04T01:56:57.075500Z

It's not as though it's impenetrable as-is... but it did cause me to backtrack on my first pass.

quoll 2021-06-04T01:57:13.075900Z

Iā€™m kinda running on fumes right now. I started it yesterday afternoon, and finished it this evening.

quoll 2021-06-04T01:58:37.077300Z

Oh, I know why I was calling it parts! I have a bullet point list of the requirements, and I was aligning it with that!

Steven Deobald 2021-06-04T01:58:58.077400Z

It's very readable. It's late, 35 degrees celsius, and I'm full of hamburgers. But I could still breeze through it nodding "yup, yup" to myself the whole way.

Steven Deobald 2021-06-04T01:59:26.077600Z

Ah, in the Goal section

quoll 2021-06-04T01:59:58.077800Z

yes

quoll 2021-06-04T02:00:11.078400Z

but it aligns with patterns already. So Iā€™m good making the change (already done)

šŸš€ 1
Steven Deobald 2021-06-04T02:01:02.079300Z

Looking forward to the next instalment. šŸ™‚

quoll 2021-06-04T02:01:16.079600Z

I gave me 2 days off writing code, so it was a nice change

quoll 2021-06-04T02:01:50.080300Z

Iā€™ve been meaning to write it for a while, but when a colleague said that they didnā€™t really get these graph queries, then I decided that I had to get it done

quoll 2021-06-04T02:03:16.081100Z

Iā€™ve been hearing from friends with ADHD recently that colored images help them stay connected with the material, so I worked on that a lot

quoll 2021-06-04T02:03:42.081400Z

Itā€™s SOOOO tempting to put more and more and more info in there

quoll 2021-06-04T02:04:11.082100Z

Likeā€¦ I want to compare these patterns to SPARQL Basic Graph Patterns (BGPs), because theyā€™re basically the same

quoll 2021-06-04T02:04:27.082500Z

which also explains how I want to extend the syntax to work like that

2021-06-04T09:45:12.098400Z

I think thatā€™s true; I suspect itā€™s compounded by the fact that itā€™s usually a subset of prolog syntax. And prolog syntax is ISO standardised; but you have to pay to access the standard, and canā€™t republish it, and consequently canā€™t really define a proper formal subset. So I suspect folk just hack something that works & looks like prolog.

2021-06-04T09:47:09.098600Z

Also I guess itā€™s rooted in academic literature; and academics are usually more interested in papers, and creating their own implementations than shared standards.

quoll 2021-06-04T02:07:28.082700Z

e.g.

[:find ?title
 :where {:first-name "Sally"
         :last-name "Smith"
         :title ?title}]
c.f.
SELECT ?title
WHERE {:first-name "Sally";
       :last-name "Smith";
       :title ?title}

quoll 2021-06-04T02:08:20.082900Z

equivalent to:

[:find ?title
 :where [?n :first-name "Sally"]
        [?n :last-name "Smith"]
        [?n :title ?title]]

Steven Deobald 2021-06-04T02:13:05.083100Z

Hmmmmm.

Steven Deobald 2021-06-04T02:14:14.083300Z

I think unless Asami actually works like that, I wouldn't include alternate syntax in your intro guide... I could definitely see that get confusing for new users.

quoll 2021-06-04T02:15:06.083500Z

Oh goodness, no! Sorryā€¦ that was me going off on a wild tangent!

šŸ˜… 1
Steven Deobald 2021-06-04T02:15:37.083700Z

Relatedly, I have been fantasizing about writing up a SPARQL / Datalog / edn Datalog flavours (Datomic, Asami, Crux) / SQL comparison sheet.

quoll 2021-06-04T02:16:05.084Z

Asami doesnā€™t do that now, though Iā€™d like it to. But if it did do that then I still would not put it into an introduction

Steven Deobald 2021-06-04T02:16:15.084200Z

hehe

quoll 2021-06-04T02:16:26.084400Z

That intro document specifically avoids a LOT

quoll 2021-06-04T02:16:52.084600Z

It doesnā€™t show any of the projection options (in fact, I kind of gloss over the return type of the q function)

quoll 2021-06-04T02:17:06.084800Z

It doesnā€™t show filter, or aggregates, or any of that stuff

quoll 2021-06-04T02:17:31.085Z

If you give a person too much in one go, then itā€™s too much

quoll 2021-06-04T02:18:07.085200Z

I wanted to get the reader to a point of issuing basic but useful queries

quoll 2021-06-04T02:18:37.085400Z

I think that once you have a handle on how patterns and conjunctive joins work, then the rest of it comes much easier

quoll 2021-06-04T02:19:24.085600Z

I wasnā€™t even going to include the _ syntax until I realized that it helped me to explain the template nature of the patterns

šŸ‘ 1
quoll 2021-06-04T02:19:59.085800Z

Also, my colleague who was struggling with it explained that seeing ?varname everywhere was the most confusing part

quoll 2021-06-04T02:20:09.086Z

The ? characters were throwing them off

Steven Deobald 2021-06-04T02:20:36.086200Z

I agree. The concepts are actually surprisingly simple for a first-time user, which can be confusing in its own right. If someone is accustomed to cobbling together lumpy SQL queries, tiny clauses each potentially representing its own join can feel pretty alien.

quoll 2021-06-04T02:21:00.086500Z

So I tried to introduce variables more carefully, and I was told that it worked. (whew!)

quoll 2021-06-04T02:21:58.086700Z

Yesā€¦ this is a thing that has frustrated me for many years. Itā€™s actually quite simple (as in, there are few connected parts), and yet it still eludes many people.

Steven Deobald 2021-06-04T02:22:15.086900Z

> The ? characters were throwing them off I had this problem too, back in 2014. I couldn't actually say why, though. Like, I understood what the ?var pattern meant, intellectually, but I couldn't visually parse it for the longest time.

Steven Deobald 2021-06-04T02:23:43.087100Z

> as in, there are few connected parts Yeah, it's a bit of a paradox. Because we're so accustomed to more complex query languages, we're expecting complications where there aren't any.

quoll 2021-06-04T02:24:24.087300Z

When we built TQL (Tucana Query Language) for Tucana/Kowari/Mulgara then we used $ instead. But then RDQL (RDF Data Query Language) used ?. So when SPARQL first came out it allowed either (committees FTW!)

quoll 2021-06-04T02:24:59.087500Z

I think the popularity of Jena made most people move towards the ? syntax

quoll 2021-06-04T02:25:23.087700Z

I donā€™t know why Rich went that way though. Maybe because SPARQL tends to use it? He did say that it was an influence

quoll 2021-06-04T02:26:05.087900Z

BTW, Asami is basically a SPARQL engine that uses edn for parsing šŸ™‚

āž• 1
Steven Deobald 2021-06-04T02:26:09.088100Z

Makes sense. Hakan said the Crux Datalog implementation had a massive SPARQL overlap, too.

Steven Deobald 2021-06-04T02:26:52.088400Z

We just adapted the Learn Datalog Today tutorial to Crux: http://opencrux.com/tutorials/ (right hand side) ... but I'm realizing that the visuals you've come up with here are actually better introductory material.

Steven Deobald 2021-06-04T02:27:06.088600Z

I actually think a middle-ground between the two approaches would be a lot of fun.

quoll 2021-06-04T02:27:12.088800Z

Iā€™ve been thinking that I need to bring in Instaparse and parse SPARQL. It can just generate Clojure data structures, and it will work

1
Steven Deobald 2021-06-04T02:27:58.089Z

"Solve for XYZ query, execute it, and see the small graph visualization on the other side of the screen highlight what you've done." kind of thing.

quoll 2021-06-04T02:28:21.089300Z

That would be nice!

quoll 2021-06-04T02:28:42.089500Z

BTW, youā€™re going to see me studiously avoiding the use of the term ā€œDatalogā€ šŸ™‚

Steven Deobald 2021-06-04T02:28:52.089700Z

Need some GSoC students to build these fun toys.

šŸ‘ 1
Steven Deobald 2021-06-04T02:29:24.089900Z

Ha! Fair. I think we've progressively started labelling it "EDN Datalog" more and more often internally.

quoll 2021-06-04T02:29:43.090100Z

I could live with that

quoll 2021-06-04T02:30:57.090400Z

I only know of a single Clojure implementation of https://en.wikipedia.org/wiki/Datalog#Syntax

quoll 2021-06-04T02:31:14.090700Z

(Note that my link is to the ā€œSyntaxā€ portion of that page)

Steven Deobald 2021-06-04T02:35:46.091Z

Yeah, I was harassing Hakan for a Crux parser that could handle horn clauses much earlier, but his pushback is that there isn't a good standard for "true" Datalog syntax anyway... which feels like a legitimate reason not to chase it. He basically made me read the What you Always Wanted to Know About Datalog (And Never Dared to Ask) paper and I gave up. šŸ˜‰

quoll 2021-06-04T03:00:15.091500Z

Lol. Thatā€™s VERY old!

quoll 2021-06-04T03:00:27.092Z

I have it somewhere printed out

quoll 2021-06-04T03:00:40.092500Z

From the early 2000s

quoll 2021-06-04T03:01:37.093900Z

BTW, if you know of any other Datalog parsers in Clojure Iā€™d be interested please

mdallastella 2021-06-04T08:29:34.096Z

Morning, I was playing with some algorithms for top sorting, I just stumble upon a possible "issue" other users can meet:

mdallastella 2021-06-04T08:30:18.096400Z

(def db-uri "asami:<mem://graph>")

(def data
  [{:db/ident :t1 :task/name "Task 1" :task/requires [{:db/ident :t3}]}
   {:db/ident :t2 :task/name "Task 2" :task/requires [{:db/ident :t1}]}
   {:db/ident :t3 :task/name "Task 3" :task/requires [{:db/ident :t1} {:db/ident :t2}]}
   {:db/ident :t4 :task/name "Task 4" :task/requires [{:db/ident :t2} {:db/ident :t3}]}
   {:db/ident :j1 :job/name "Job 1"}])

(defn build-db
  [db-uri]
  (d/create-database db-uri)
  (let [conn (d/connect db-uri)]
    (d/transact conn data)
    (d/entity (d/db conn) :t3 true)))

mdallastella 2021-06-04T08:31:09.097Z

Expanding :t3 results in a Execution error (StackOverflowError) at zuko.schema/eval9645$vartest? (schema.cljc:35). null

mdallastella 2021-06-04T08:32:51.098100Z

Probably it's not an Asami duty to inform the user that the graph is circular

mdallastella 2021-06-04T08:33:05.098300Z

But it can happen

quoll 2021-06-04T11:25:54.100500Z

Ohā€¦. I have entity loading based on our datasets, and it never occurred to me to worry about that. Thank you!

1