Database Reference
In-Depth Information
We start with the ROLLUP operation. As an example, consider the query
“Total household by Government Oce Region.” This is expressed using the
operations introduced in Chap. 3 as
ROLLUP(HouseholdCS, Geography
GOR, SUM(Household)).
The structure of the result represented as a QB4OLAP schema denoted
by ex:HouseholdByGOR is shown next:
ex:HouseholdByGOR a qb:DataStructureDefinition ;
qb:component [qb4o:level ex:GovernmentO ceRegion] ;
qb:component [qb4o:level ex:Year] ;
qb:component [qb:measure ex:Household ; qb4o:hasAggregateFunction qb4o:sum] .
ex:dataset-hh1 a qb:DataSet ; rdfs:label '' HouseholdinUKbyGOR '' @en ;
qb:structure ex:HouseholdByGOR .
The SPARQL query that implements the operation is shown next:
CONSTRUCT
{
?id a qb:Observation ; qb:dataSet ex:dataset-hh1 ; ex:Year ?year ;
ex:GovernmentO ceRegion ?gor ; ex:Household ?sumHhold .
}
WHERE
{{
SELECT ?gor ?year (SUM(?hhold) AS ?sumHhold)
(iri(concat( '' http://example.org/hhold#Roll-upGOR '' ,
strafter(?gor, '' http://example.org/hhold# '' ), '' '' ,
strafter(?year, '' http://example.org/hhold# '' ))) AS ?id)
WHERE { ?o qb:dataSet ex:dataset-hh ; ex:Year ?year ;
ex:Household ?hhold ; ex:UnitaryAuthority ?ua .
?ua skos:broader ?gor .
?gor qb4o:inLevel ex:GovernmentO ceRegion . }
GROUP BY ?gor ?year }}
In the WHERE clause of the subquery, a graph pattern matching is performed.
From the matching triples, the values that instantiate the ?gor and ?year
variables are returned and aggregated in the SELECT clause. It is important
to remark that new IRIs must be generated to identify each one of the new
observations resulting from the application of the operation. This is done in
the SELECT clause of the subquery with the strafter function, which returns
the substring of the first parameter that appears after the string in the second
parameter. Further, in the outer query, the CONSTRUCT clause is used since
it returns a graph, opposite to the SELECT clause, which returns literals.
Let us consider now the following slice operation:
SLICE(Sales, Geography, Country= '' England '' ),
which drops the dimension Geography by fixing a value in it. As in the previous
case, we first need to define the schema of the resulting cube as follows:
ex:HouseholdSlice a qb:DataStructureDefinition ;
qb:component [qb4o:level ex:Year] ;
qb:component [qb:measure ex:Household ; qb4o:hasAggregateFunction qb4o:sum] .
ex:dataset-hh2 a qb:DataSet ; rdfs:label '' Household in England by Year '' @en ;
qb:structure ex:HouseholdSlice .
 
Search WWH ::




Custom Search