Link Search Menu Expand Document
Start for Free

Virtual Transparency

This page discusses Virtual Transparency, a virtual graph facility to query all virtual graphs over the default graph or set of named graphs.

Page Contents
  1. Overview
  2. Configuration
  3. Query Semantics
  4. Dataset Specification
  5. Features and Options

Overview

Virtual graphs provide a facility for accessing external data sources by mapping them to individual named graphs. The example queries shown previously all specify the source of the data using the virtual graph name. This fine-grained declaration can be useful in some circumstances but it’s also desirable to query over the set of all graphs without enumerating them individually. Virtual transparency is a feature that, when enabled, will include results from virtual graphs in queries over the default or set of named graphs.

Configuration

How does it work? First you need to set the virtual.transparency database option to true.

When this is enabled, queries are evaluated not only over local graphs, but also over accessible virtual graphs. The set of accessible virtual graphs is determined by the virtual graph access rules. It may differ by database and user.

Query Semantics

The example queries shown previously use explicit graph blocks to name the source graph of the data, e.g.:

SELECT * {
   GRAPH <virtual://dept> {
      ?person a emp:Employee ;
           emp:name "SMITH"
   }
}

In contrast, a query without a graph block would only return data from the local default graph:

SELECT * {
   ?person a emp:Employee ;
        emp:name "SMITH"
}

However, if virtual transparency is enabled, this query will return data from both the local default graph and any accessible virtual graphs. Note that this requires the query.all.graphs database configuration option be set to true.

Additionally, a graph block with a variable will bind to both local named graphs and any accessible virtual graphs. For instance, the original query can be restated to use a graph variable:

SELECT * {
   GRAPH ?g {
      ?person a emp:Employee ;
           emp:name "SMITH"
   }
}

The result would include results from the virtual graph, with ?g bound to <virtual://dept>, along with any results from local named graphs.

With virtual transparency, the key difference between including or omitting a graph block comes from how triple patterns are joined together. Just as a graph block over a set of local named graphs limits BGP matches to a single named graph, a graph block with virtual transparency limits BGP matches to a single local or virtual graph. To illustrate, consider the query with a graph block:

SELECT * {
   GRAPH ?g {
      ?person a emp:Employee ;
           emp:name "SMITH"
   }
}

If the set of employees is stored in a different virtual graph than the employee names, this query will return an empty result because the entire BGP will not match any set of triples in any individual graph. However, if we remove the graph block, each individual triple pattern will match triples from different graphs and these results will be joined together. The result is similar to what we would obtain by specifying the sources manually:

SELECT * {
   GRAPH <virtual://employees> {
      ?person a emp:Employee
   }
   GRAPH <virtual://names> {
      ?person emp:name "SMITH"
   }
}

Dataset Specification

Fine grained control of virtual graph selection is possible using SPARQL’s dataset specification. When virtual transparency is enabled, the dataset specification allows inclusion of virtual graphs in FROM and FROM NAMED clauses. Arbitrary mixing of local and virtual graphs is allowed. For instance, the following query will include results from multiple virtual graphs:

SELECT *
FROM <http://local-employees-graph>
FROM <virtual://names>
{
   ?person a emp:Employee ;
        emp:name "SMITH"
}

The Special Named Graph tag:stardog:api:context:virtual and tag:stardog:api:context:all can be used to refer to the set of all virtual graphs and the union of all virtual and local graphs, respectively.

Features and Options

Virtual transparency is compatible with all SPARQL operators with the exception of “zero or more” and “one or more” property paths. These constructs are supported on some DBMS platforms when placed inside the graph block specifying the virtual graph source.

A query hint is provided to disable virtual transparency for all or part of a query. Placing the hint #pragma virtual.transparency off in a SPARQL block will disable consideration of virtual graphs for that block.