Creating a Template with a Query-Driven Templated Step
Query-Driven Templated Steps are similar to Templated Steps in that they provide a way to create query templates that use parameters to represent key-value pairs. The queries are reusable across datasets because the existing parameters can be substituted for alternate key-value pairs. The difference between the two types of steps is that the key-value pairs for Templated Steps are user-defined. In Query-Driven Templated Steps, a parameter query is run that automatically generates the key-value pairs. Then the defined template query is run for each key-value solution from the parameter query. Follow the steps below to create a Query-Driven Templated Step.
- Go to the graphmart for which you want to add a step and then click the Data Layers tab.
- On the Data Layers tab, find the layer that you want to add the step to. Click the menu icon () for that layer and select Add Step/View. The Add Step/View dialog box is displayed with the New tab selected.
- To create a new Query-Driven Templated step, select Query Driven Templated Step and then click OK. If you want to clone an existing step, click the Existing Steps tab, select the step that you want to clone, and then click OK. Anzo creates or clones the step and displays the Details tab:
- On the Details tab, configure the following options as needed:
- Title: The required name of the step.
- Description: An optional short description of the step.
- Enabled: When creating a new step, the Enabled option is selected by default, indicating that the step is enabled and will run when the layer is loaded or refreshed. If you want to disable the step so that it is not processed, clear the Enabled checkbox.
- Source: The source data that this step should act upon. Steps can build upon the data generated by steps in other layers or can be self-contained, applying changes that relate only to the data defined in the layer that contains this step. You can select any number of the following options:
- Self: This option is selected by default and means that the step runs against only the data that is generated in the layer this step belongs to.
- All Previous Layers Within Graphmart: This option means that the step runs against the data that is generated by all of the successful layers that precede the layer this step is in. Any failed layers are ignored.
- Previous Layer Within Graphmart: This option means that the query runs against only the data that is generated by the one layer that precedes the layer this step is in.
- Layer Name: The Source drop-down list also includes options for specific layer names. You can choose a specific layer to act upon the data in that layer only.
- Data models: This required field specifies the model or models to associate with this step. The list displays all of the available models. By default, the field is set to Exclude System Data (). If you want to choose a system model, click the toggle button on the right side of the field to change it to Include System Data (). When system data is included, the drop-down list displays the system models in addition to the user-generated models.
- Pre-Run Generate Statistics: This option controls whether to initiate AnzoGraph's internal statistics gathering queries before running the query to pre-compile. The statistics gathering helps ensure that the AnzoGraph query planner generates ideal query execution plans for queries that are run against the graphmart.
- When you have finished configuring the Details tab, click the Parameters Query tab. This tab defines the query to use for determining the key-value pairs for the Source that was selected on the Details tab. The tab provides a template for writing a SPARQL SELECT DISTINCT query. Edit the template as needed.
Make sure that you include the
${fromSources}
parameter in the query. Anzo automatically populates the query with the appropriate source graph URIs according to the Source configured on the Details tab.If your query connects to a source that requires input of connection and authorization information, Cambridge Semantics recommends that you do not include the connection and authorization values directly in the query. Instead, replace those values with Context Variables from a Query Context. You can access Context Providers for each data source from the step's Query Context tab. For detailed information about query contexts and referencing variables in a query, see Using Query Contexts in Queries.
- When you have finished configuring the Parameters Query tab, click the Template tab. This tab contains the query to run for each of the key-value pairs identified by the Parameters Query. The template includes the syntax for writing SPARQL DELETE and INSERT queries and includes source and target graph parameters as well as the placeholder parameters from the Parameters Query.
By default, Anzo uses RDF encoding for parameters, meaning a parameter specified as
${param}
is translated as${rdf.param}
. If you do not want to use RDF encoding, you can specify plain text by addingtext.
before the parameter name, for example,${text.param}
. - Click Save to save the step configuration.
Anzo replaces the parameters at runtime. The query is executed n times, where n is the number of rows returned by the Parameters Query.
Once the Details tab is configured, the parameters query is in place, and the template is completed, the step can be run. Anzo replaces the parameters at runtime, and the query is executed n times, where n is the number of rows returned by the parameters query. For information about running this step conditionally by setting up an execution condition, see Defining Execution Conditions.