ObdalibQuestEtables - ConstantB/ontop-spatial GitHub Wiki

Embedded Query (a.k.a. EQL-Lite, Epistemic Query)

A powerful feature of Quest is the support for embedded queries, i.e., general SQL queries that use embedded SPARQL or UCQ queries as tables in the FROM clause of the SQL query. The SQL is not restricted, and any SQL constructs allowed by the RDBMS that you use are supported. The embedded SPARQL or UCQ queries are restricted as described in the previous sections.

An embedded table in the FROM clause is given with the following syntax:

($SPARQL/ $UCQ) 
')' $NAME

Where $SPARQL and $UCQ are SPARQL and UCQ queries respectively (as defined in Quest documentation) and $NAME is a the temporal name for the result of the nested query. Variables outside of the embedded table must be references using the syntax $NAME.VARIABLENAME. For example, the following is a valid embedded query:

SELECT view1.x, view1.project FROM etable ( 
    PREFIX : <http://ontology.org/example#>
    SELECT ?x ?project ?salary 
         WHERE { ?x a :Employee; 
                      :works-for ?project;
                      :has-salary ?salary .
          }
) view1 WHERE view1.salary > 27436

Note that etable can be used several times in the query, as well as real tables from the database schema. Using embedded tables you can express negation and use the full power of SQL over the results of ontological queries.

For example, a query for all Employees that we DONT KOWN THE PROJECT FOR WHICH THEY WORK (note the difference in the SELECT of the etables):

SELECT view1.emp, FROM etable ( 
    PREFIX : <http://ontology.org/example#>
    SELECT ?emp
         WHERE { ?emp a :Employee; 
                      :works-for ?project;
          }
) view1 WHERE (view1.emp) NOT IN etable(
   PREFIX : <http://ontology.org/example#>
    SELECT ?emp ?project 
         WHERE { ?emp a :Employee; 
                      :works-for ?project;
          }
) view2

Etables are a slightly "relaxed" implementation of EQL-Lite query language, as defined in the article "EQL-Lite: Effective first-order query processing in description logics", that you can find here.

⚠️ **GitHub.com Fallback** ⚠️