YADI - Yet Another Datalog Interpreter

What is YADI?
Yet Another Datalog Interpreter (YADI) is a Datalog-to-SQL converter that transforms a Datalog query to an Abstract Syntax Tree to an SQL statement to an answer set of tuples.

A Datalog query against {R(A,B), S(B,C,D)} database looks like this:
    V(x,y) :- R(x,y) and S(y,_,_).
    Q(x,y) :- S(x,y,z) and V(z,t) and t>=3.
    ?- Q(x,y). 

where the two first lines define idb predicates and the third line provides the actual query, i.e. the idb in the result set.

Despite its multiple-rules form, the above Datalog query is a Conjunctive Query that can be translated into the following SQL statement:

    WHERE S1.B>=3; 

The purpose of the project is to develop a Command Line Interpreter for Datalog queries. It aims at converting Datalog queries into SQL statements. Then, a backend Relational Database is in charge of evaluating the query. 

So far, YADI is able to solve recursive Datalog programs with negation. Nevertheless, recursive programs must satisfy the following five conditions for being accepted and solved by YADI:

1.- No two predicates are mutually recursive; the only allowed form of recursion is self-recursion.
2.- A predicate cannot make a negative recursive call to itself.
3.- A predicate cannot contain more than one recursive goal (call to itself) in its body.
4.- If the predicate is defined by several rules (union of rules), then only one of the definitions can have a recursive call.
5.- Every recursive predicate must have a non-recursive definition (base case).

Because of this rules, the language accepted by YADI is more powerful than nonrecursive-datalog but less powerful than stratified-datalog.

YADI also accepts aggregate functions, they must be defined in the head of a rule, for example:

Q(x,y,sum(z)) :- P(x,y) and R(y,z).

Here the resulting set will consist of 'x,y' tuples and the sum of 'z' variables of these tuples. Aggregation comparison is also accepted by YADI, for example:

Q(x,y,count(z)) :- P(x,y) and R(y,z) and count(z) >= 10.

Please refer to the documentation for more information about YADI's expressive power.


For running YADI it is necessary to have access to a PostgreSQL database. As it can be seen below, when starting the program it will be necessary to indicate a username, database name, host, port and password. Obviously the provided user will need to have write/read permission on the provided database.


./yadi [OPTIONS]

  -h host     : database server host (default: "yadi")
  -p port     : database server port (default: "5432")
  -U user     : database user (default: "yadi")
  -w password : database user password (default: empty)
  -d dbname   : database name to connect to (default: "yadi")
  -db         : print debugging information
  -f file     : read program from file
  -help  Display this list of options
  --help  Display this list of options

Observe that the flag "-db" will make YADI print debugging information, such as the stratification of programs, generated SQL, database schema, etc.

Sample queries

The directory 'test' contains several test cases. Specifically, the directory 'test/sql' contains several sample databases. A script for setting automatically the testdb has been included, it can be invoked by running "make testdb". However the file 'test/database.conf' must be defined with the connection information, this file must have the following format:

Furthermore, the directory 'test/integration' contains several test cases. A script for automatically running the tests was also included, running 'make tests' will invoke it.

In summary, for setting the test DB and testing:

1.- Create the file 'test/database.conf' and fill in the required information.
2.- Run 'make testdb', this will set the test database.
3.- Run 'make tests', the tests will be run.


Contact Information and Contributing

In the case of bugs, feature requests, contributions and similar, please contact

Carlos Colmenares   <carlos.a.colmenares.r@gmail.com>

Based on the core code of maintainer:
  * Guillaume Raschia <guillaume.raschia@univ-nantes.fr>
Past colaborators of the project:
  * Mark Abspoel        <mail@markabspoel.nl>
  * Jose Robles Noriega <atease@vista.aero>
  * Hasan Saygin Arkan  <sayginarkan@gmail.com>

Up-to-date information should be available at:


Guillaume Raschia in Nantes, FR on Sept 28, 2012