Live data from Hacker News

Ask HN: Why GraphQL APIs but no Datalog APIs?

news.ycombinator.com

71–80 of 111 posts

Re: Ask HN: Why GraphQL APIs but no Datalog APIs?

#71
It's all about the data manipulation capabilities that our current programming languages and libraries provide. Datalog and GraphQL are both graph query languages, but they differ significantly in the datastructures they return.

GraphQL queries describe Tree unfoldings of graphs, and thus return trees.

Datalog describes recursive conjunctive queries on hypergraphs (relational model) without or limited negation, and thus return a set or bag of hypergraph edges.

The reason why GraphQL is so successful is that it fits well with Reacts data-model (trees) and the way it performs its efficient delta updates (tree walking). Furthermore its somewhat easier to implement (albeit not simpler). Consider that there are very few actual GraphQL query engines for actual data (e.g. DGraph DB), instead GraphQL backends implement resolver functions which compute the "graph"/tree on the fly, based on side effects. Resolvers are what you'd call a computable in prolog or datalog knowledge bases and even though I work full time on incremental query evaluation in said knowledge bases I don't have a clue on how to make those efficient without resorting to the Big Cannon of Differential Dataflow.

Datalog queries don't return trees, they return relations a.k.a. hypergraph edges, and that simply doesn't map well to the datastructures (maps/dicts and lists/vectors/arrays, JSON and other tree description formalisms) that we have in basically every mainstream programming language that isn't prolog or some variant on logic programming. So the query results are hard to work with, and you'd want a LINQ style embeddable datalog query engine in your language of choice to work with the returned data, which is a much bigger undertaking.

So to recap: Datalog is great if you have it everywhere and your language is build around it and hypergraphs, but alas most languages we use today are build around trees, and graphql is a tree language.

Re: Ask HN: Why GraphQL APIs but no Datalog APIs?

#72
post #70
post #4

For context, I'm a frontend development lead who oversees a number of projects of different shape and size. My personal and very subjective opinion is it's simply hype. If you say "Datalog" to a frontend developer, they will either hear "obsolete" or just not know what you mean. If you say "GraphQL", they hear "+5 CV points". Obviously that is slightly tongue in cheek, but the marketing side of it is a very real fact…

Github's api [1] makes sense to me - there are lots and lots of query patterns and the previous Rest api results in quite a bit of link chasing and bandwidth burning. It would actually be interesting to see if someone could design a very good Rest api for gh-like usage. 1: https://developer.github.com/v4/

8 closed brackets in their first example query.

query { repository(owner:"octocat", name:"Hello-World") { issues(last:20, states:CLOSED) { edges { node { title url labels(first:5) { edges { node { name

              }
            }
          }
        }
      }
    }
  }
}

https://developer.github.com/v4/guides/forming-calls/

Re: Ask HN: Why GraphQL APIs but no Datalog APIs?

#73
post #6

Earlier quoted context omitted.

What's the best example of modern Datalog?

A good way to try Datalog is to use a state-of-the-art Prolog system that supports SLG resolution (tabling). SLG resolution is an evaluation strategy of Prolog programs that provides favourable termination properties compared to SLDNF resolution which is Prolog's default execution strategy. A great example for this is XSB Prolog, since it has pioneered and refined many of these techniques and serves as an example and…

> A great example for this is XSB Prolog,

I'm really sorry but it honestly cannot be. I was curious because Datalog/Prolog based technologies are intriguing so I clicked on that link.

https://xsb.com/xsb-prolog seems to have no download but links to

http://xsb.sourceforge.net/ which claims version 3.8 (October 2017) is current and links to

http://xsb.sourceforge.net/downloads/downloads.html which does not specify a version but offers a tar.gz that contains version 3.7 from July 2016.

Going back to sourceforge and heading to the SVN https://sourceforge.net/p/xsb/src/HEAD/tree/trunk/XSB/ states version 3.9, November 2019 and looks pretty active commit-wise.

Okay, let's do that. Checking out trunk, I see perl and C scrolling by. While I have no problem with Perl, I know quite a few developers - especially in the web context - that find it rather off-putting. I get a README that tells me to read the manual in order to install. Fair enough. Opening that ( http://xsb.sourceforge.net/manual1/manual1.pdf ) gives me a 622 page PDF from October 2017. Chapter 2:

"Make sure that after you have obtained XSB, you have uncompressed it by following the instructions found in the file README." There were no such instructions. But well, configure and make are in build, that's fine and the rest of the instructions are clear.

I was confused why configure looked for mysql and make did something with Java but whatever, both worked great out of the box. Let me check the binary. I get a REPL, claiming to be version 3.8 from October 2017 and despite having 7 lines of output I have no idea how to quit out of that process, so I turn to Google which gives me http://xsb.sourceforge.net/shadow_site/manual1/node14.html

Neither ctrl^c, nor ctrl^d work, and halt + return is ignored. I go ahead, kill the process and delete the directory.

Alternatives to the above? That original site tells me to contact some organisation, "xsb prolog" on Google turns up ancient results.

Now compare that with https://graphql.org/graphql-js/

Just like many of these rather research centric languages, it does not matter how cool their tech is if that's the first experience people get. In my view experiences like the above are why they fail to gain adoption in today's world, not some technical aspect or technique. At least unlike much of the linked data and SPARQL world this thing compiled out of the box and I would have been up and running in about 10 minutes if I had any intention to continue.

Re: Ask HN: Why GraphQL APIs but no Datalog APIs?

#75
post #2

That's a very justified question! In my opinion, Datalog or — more generally — Prolog is where many querying APIs will eventually arrive, because this syntax has many nice advantages: It is very convenient, expressive and readable, programs and queries can be easily parsed and analyzed with Prolog's built-in mechanisms, there is an ISO standard for it etc. When semantic web formalisms were discussed, Prolog was somet…

> notations which are no longer a subset of ISO Prolog and therefore also not Datalog.

This is false. Datalog is not (or no longer) about prolog like syntax, Datalog as used nowadays in research, describes the semantics for a logic which includes conjunctive queries and recursion, often denoted as an abstract syntax consisting of rules with a body and head, no ascii syntax attached.

> Thus, they also do not immediately benefit from recent advances in Prolog systems in that they cannot directly be parsed and interpreted by them.

This is like saying, that Javascript can benefit from updates to the Java virtual machine. Prolog and Datalog require radically different evaluation strategies and implementations.

Re: Ask HN: Why GraphQL APIs but no Datalog APIs?

#76
post #13

Earlier quoted context omitted.

This was (is?) what the semantic web dream was all about, and I find it funny that it took a corporation (FB) developing a clone before others discovered the concept. Semantic web data would be published as RDF data and clients would consume this data using a SPARQL query engine to get whichever shape of data that they desired.

To clarify: I mean that Prolog was under consideration to be used for what SPARQL was then developed, as a more readable and simpler query and also modeling language. Several researchers working in this area considered the development of SPARQL to be a missed opportunity for better formalisms, since Prolog could have been used instead . And, yes, to many who have worked with RDF, SPARQL and the various notations that…

> easily processable

> formal reasoning based on well known logical rules

Oof, I do not know any serious researcher of logic who would support that claim.

Prolog is, due to its age and heritage, inherently side/effectful and undecidable/turing-complete.

SPARQL has big fat warts, for sure, design by committee, bulky syntax, way too long spec, way too many capabilities, and questionable decidability (looking at you MAYBE clause), BUT at its heart it's non recursive conjunctive queries over regular path expressions.

CJ over PathRegex are a really elegant way to describe arbitrarily nested datastructures with flat queries, and are a lot more intuitive and concise than the corresponding datalog query.

Edit: Not saying that prolog doesn't have its place btw, it's a neat language with awesome capabilities, but is NOT a query language.

Re: Ask HN: Why GraphQL APIs but no Datalog APIs?

#77
post #6

Earlier quoted context omitted.

A good way to try Datalog is to use a state-of-the-art Prolog system that supports SLG resolution (tabling). SLG resolution is an evaluation strategy of Prolog programs that provides favourable termination properties compared to SLDNF resolution which is Prolog's default execution strategy. A great example for this is XSB Prolog, since it has pioneered and refined many of these techniques and serves as an example and…

> A great example for this is XSB Prolog, I'm really sorry but it honestly cannot be. I was curious because Datalog/Prolog based technologies are intriguing so I clicked on that link. https://xsb.com/xsb-prolog seems to have no download but links to http://xsb.sourceforge.net/ which claims version 3.8 (October 2017) is current and links to http://xsb.sourceforge.net/downloads/downloads.html which does not specify a v…

That sucks. XSB is old code and I believe it was meant mostly as a proof of concept even at the time it was written. I doubt many people use it, even in research, nowadays.

I believe what triska meant about XSB is that it demonstrated the benefits of SLG resolution, by being a proof of concept like I say. So yes, XSB would be more of academic interest.

If you want a modern Prolog to play around with you should try Swi-Prolog. From the conclusion of your comment I'm assuming you haven't tried it because you wouldn't have trouble "getting up and running" in 10 minutes. Or 5 or so. Seriously, Swi's maintainers (triska is a contributor) have gone out of their way to make it useable.

Anyway, if you put in all this work to get XSB working I think you should definitely give Swi-Prolog a try. Sunk cost fallacy, innit.

Here's the link:

https://www.swi-prolog.org/Download.html

On windows, there's an installer. On Linux you can yum-install or apt-get etc an earlier version and try it out, then if you like it you can follow the Download page's links to figure out how to install a newer version (that does take a bit more work).

If you're stuck with Prolog, there's a discourse group, here:

https://swi-prolog.discourse.group/

People there are always happy to help newcomers (and will never send you to RTFM).

But be warned that learning Prolog is not easy. I help with markings and labs for Prolog courses at my university and students always have a hard time with it, until some things start to click.

EDIT: "halt." should work at any Prolog prompt. The "." is a statement terminator. You probably didn't get anything after "halt return" because you missed the dot.

EDIT II: Oh, I forget. You can try Swi-Prolog on Swish (Prolog notebooks):

https://swish.swi-prolog.org

So no need to install anything but keep in mind that some stuff is limited for security reasons (you can do a lot of damage with a language that lets you rewrite it on the fly).

Re: Ask HN: Why GraphQL APIs but no Datalog APIs?

#78
post #2

That's a very justified question! In my opinion, Datalog or — more generally — Prolog is where many querying APIs will eventually arrive, because this syntax has many nice advantages: It is very convenient, expressive and readable, programs and queries can be easily parsed and analyzed with Prolog's built-in mechanisms, there is an ISO standard for it etc. When semantic web formalisms were discussed, Prolog was somet…

What's the best example of modern Datalog?

Certainly not the best, but worth mentioning the Python implementation pydatalog.

https://sites.google.com/site/pydatalog/home

Re: Ask HN: Why GraphQL APIs but no Datalog APIs?

#79
post #6

Earlier quoted context omitted.

A good way to try Datalog is to use a state-of-the-art Prolog system that supports SLG resolution (tabling). SLG resolution is an evaluation strategy of Prolog programs that provides favourable termination properties compared to SLDNF resolution which is Prolog's default execution strategy. A great example for this is XSB Prolog, since it has pioneered and refined many of these techniques and serves as an example and…

> A great example for this is XSB Prolog, I'm really sorry but it honestly cannot be. I was curious because Datalog/Prolog based technologies are intriguing so I clicked on that link. https://xsb.com/xsb-prolog seems to have no download but links to http://xsb.sourceforge.net/ which claims version 3.8 (October 2017) is current and links to http://xsb.sourceforge.net/downloads/downloads.html which does not specify a v…

>Just like many of these rather research centric languages, it does not matter how cool their tech is if that's the first experience people get. In my view experiences like the above are why they fail to gain adoption in today's world, not some technical aspect or technique. At least unlike much of the linked data and SPARQL world this thing compiled out of the box and I would have been up and running in about 10 minutes if I had any intention to continue.

Just what I was thinking as I read the parent. This is the real answer to the OP's question.

Re: Ask HN: Why GraphQL APIs but no Datalog APIs?

#80
post #70

Earlier quoted context omitted.

Github's api [1] makes sense to me - there are lots and lots of query patterns and the previous Rest api results in quite a bit of link chasing and bandwidth burning. It would actually be interesting to see if someone could design a very good Rest api for gh-like usage. 1: https://developer.github.com/v4/

8 closed brackets in their first example query. query { repository(owner:"octocat", name:"Hello-World") { issues(last:20, states:CLOSED) { edges { node { title url labels(first:5) { edges { node { name } } } } } } } } https://developer.github.com/v4/guides/forming-calls/

And some people says that lisp like languages use too much parenthesis...
Post reply on HN