Configuring Contexts for Data Source Connections

When you use the Graph Data Interface (GDI) for Data Virtualization, you may connect to Data Sources that require input of sensitive connection and authorization information such as keys, tokens, and user credentials. When configuring a Data Layer (or Step), you have the option to use a Context to store the sensitive information as key-value pairs. Queries can then reference the keys from the Context so that the sensitive details are abstracted from any requests that are sent to the Data Source. This topic provides information on configuring Contexts and referring to Context keys in a query.

Configuring a Context

Contexts are configured from the Context tab that is available when creating or editing a Data Layer or Step. The image below shows the Context tab for a Data Layer.

Context Providers

Connections in Anzo implement the Context Provider interface. For example, File Store connections, Anzo Data Store connections, and Data Source connections provide contexts (in the form of JSON objects) that contain key-value pairs which define connection details such as URLs, database names, usernames and passwords, tokens, etc. These contexts are passed to the Data Source when a request is made against that source. To use one of the Anzo-generated Context Providers that was created for a pre-existing connection, select that provider from the drop-down list.

If you specify a Context Provider, the key-value pairs from the selected provider are not populated in the Context Key list on the screen. However, the keys are used automatically when a query is run against that provider.

Context Keys

Context Keys are user-defined key-value pairs that are not associated with a particular Context Provider. To add a key and define its value, click the Add Key button. Then specify the Key Name and Key Value in the Create Context Key dialog box. Click Create to add the key-value pair to the Context.

When defining Context Keys at the Data Layer level, make sure that the Key Names are unique. A Data Layer may have different Steps that virtualize data from different sources and reference the same Context. The image below, for example, creates URL, username, and password Context Keys.

Referencing Context Keys in a Query

The format that you use for referencing a Context Key in a query depends on the type of AnzoGraph plugin or extension that is being called by the query. Generally, Data Layer Contexts are only used in Steps that contain Graph Data Interface (GDI) queries. When referencing Context Keys in GDI queries, use the following format:

{{@<context_key_name>}}

For example, the following GDI query references three Context Keys: adventureworks-url, adventureworks-username, and adventureworks-password.

PREFIX s:     <http://cambridgesemantics.com/ontologies/DataToolkit#>
PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>
PREFIX owl:   <http://www.w3.org/2002/07/owl#>
PREFIX anzo:  <http://openanzo.org/ontologies/2008/07/Anzo#>
PREFIX zowl:  <http://openanzo.org/ontologies/2009/05/AnzoOwl#>
PREFIX dc:    <http://purl.org/dc/elements/1.1/>

​SELECT DISTINCT *
​WHERE
  {
    SERVICE <http://cambridgesemantics.com/services/DataToolkit>
      {
        ?data a s:DbSource ;
			s:url "{{@adventureworks-url}}" ;
			s:username "{{@adventureworks-username}}" ;
			s:password "{{@adventureworks-password}}" ;
			s:selector "[dbo].[FILM]" ;
			?year ("[YEAR]" xsd:int);
			?length (xsd:int) ;
			?title (xsd:string) ;
			?subject ("[dbo].[FILM].[SUBJECT]" xsd:string) ;
			?actor ("[ACTOR]" xsd:string) ;
			?actress (xsd:string) ;
			?director (xsd:string) ;
			?popularity (xsd:int) ;
			?awards (xsd:string) ;
			?image (xsd:string) .
			FILTER(?year >= 1990 && ?year < 2000)
			FILTER(?subject = "Drama" || ?subject = "Action")
			FILTER(?length <= 90)
  }
}
Related Topics