google / mangle

Apache License 2.0
1.09k stars 38 forks source link

FR: Java Wrapper? #36

Open vorburger opened 2 months ago

vorburger commented 2 months ago

Context, just for background: I've just started reading up on Datalog for my explorations in https://github.com/enola-dev/enola/issues/842 over on Enola.dev.

I'm hoping to be playing around with some Datalog implementations over the next few weeks or so - including this cool project!

FYI I'm also intending to check-out Soufflé, AbcDatalog & Flix.dev... if this project has any sort of "Comparison to Alternatives" doc (AKA "why this?"), or you would want to use this as an opportunity to write something like that, please shout!

One quick question: Have you ever considered offering some sort of Java Wrapper to expose the current Go or future Rust based code?

Soufflé (written in C++) "supports" Java integration via SWIG. (There may be better alternatives.)

Hypothetically speaking, would this be something you think could make sense? Or N/A No Go, never going to happen, here? Just asking!

An alternative may be to write out facts to a file and "shell exec out" and re-read output... doable, but less fun & efficient.

@burakemir @mihaimaruseac 👋🏽

burakemir commented 2 months ago

Thanks for checking out Mangle!

Yes, I think we should have a doc pointing to the various existing great datalog implementations esp. now that there is also a Rust implementation. There are many good Rust datalog libraries out there for various scenarios, ascent, crepe of cozodb. Wikipedia also mentions a few: https://en.wikipedia.org/wiki/Datalog#Datalog_engines

Making it possible to use Mangle from Java and python makes a lot sense. Exposing a C-interface to SWIG is a tried and tested way to do this, provided one has a stable API and can integrated into one's build system.

For building systems in Java that use datalog, an easier alternative may be to set up a separate server process and use a form of RPC or socket communcation. There is a demo of this approach here, with a gRPC service https://github.com/burakemir/mangle-service

In my experience, one often is able to precompute all facts that one might be interested in (or the facts are stored in some form of DB), and then wants to run particular queries where the processing and results comfortably fit in memory of a single machine. For that, the query server approach will work well, maybe better than SWIG.

vorburger commented 2 months ago

I see! Thank You. Yeah, that approach (i.e. Mangle as a server in a separate process) makes great sense (forget e.g. SWIG).

I'll have a closer look and poke at https://github.com/burakemir/mangle-service some day.