ObdalibQuestTutorialEtableFunction - ConstantB/ontop-spatial GitHub Wiki

Querying with ETABLE Function

<< Back to Tutorial Index

Table of Contents

The ETABLE function enables users to query data aggregation from different data views. The syntax is similar to the SQL language with an additional keyword ETABLE at the beginning of each view. Therefore, unlike many SQL queries, this function only works for data views and it has no effect to database tables. Users need to define the data view in SPARQL and then incorporate it to the query string. We are going to present several examples using the OBDA model from the BookPublication tutorial.

Example Queries

  1. A very basic example for projecting all columns in a data view.
select * from ETABLE (
PREFIX : <http://meraka/moss/exampleBooks.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select distinct ?x ?y where {?x rdf:type :Author. ?x :name ?y}) view1

2. Count how many books which are audio books.

select COUNT(x) from ETABLE (
PREFIX : <http://meraka/moss/exampleBooks.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select distinct ?x where {?x rdf:type :AudioBook.}) view1

3. Count how many books written by L.C. Higgs.

select COUNT(title) from ETABLE (
PREFIX : <http://meraka/moss/exampleBooks.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select ?title where {?x :writtenBy ?y; :title ?title. ?y :name 'L.C. Higgs'}) view1

4. Present the newest edition number for each book.

select title, MAX(ed_number) from ETABLE (
PREFIX : <http://meraka/moss/exampleBooks.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select ?title ?ed_number where {
    ?x rdf:type :Book; :title ?title; :hasEdition ?y. 
    ?y :editionNumber ?ed_number.}) view1
group by title


Important Note:

  • The ETABLE function works well in both Virtual and Classic mode as long as the users use the generic aggregation functions (i.e., MAX, MIN, AVG, COUNT, SUM).
  • Other functions that are not generic may fail in the Classic mode due to DBMS compatibility. We employ H2 database engine for Classic mode.
⚠️ **GitHub.com Fallback** ⚠️