Adding a Query Step

Follow the instructions below to add a step that runs a custom query to create, clean, conform, or transform data in a data layer.

When writing queries for Query Steps, Cambridge Semantics recommends that you open an additional instance of the Anzo application so that you can use the Model manager to view the ontology for the data set that the query runs against. Viewing the model enables you to review the classes and properties and copy any URIs to use in the query.

  1. In the Anzo application, expand the Blend menu and click Graphmarts. Anzo displays a list of the existing graphmarts. For example:

  2. On the Graphmarts screen, click the name of the graphmart that you want to change.
  3. Click the Data Layers tab. Anzo displays the existing data layers.
  4. Click the menu icon () on the layer for which you want to create a step, and then select Add Step/View. Anzo opens the Add step dialog box.

  5. Follow one of the options in this step, depending on whether you want to create a step from scratch or clone an existing query step for reuse:
    • If you want to create a new step, select Query Step, and then click OK. Anzo opens the Create query step screen. Proceed to the next step.

    • If you want to clone an existing step and add it to this layer, click the Existing Steps tab and follow these steps:
      1. Select the query step that you want to clone and click OK. Anzo displays the Clone dialog box, which asks if you want to copy the permissions from the existing step.

      2. On the Clone dialog box, click Yes to copy the permission configuration from the existing step or click No to copy the step without the permission configuration.

        Anzo clones the step, adds the copy to the layer, and returns to the Data Layers screen.

      3. On the Data Layers screen, click the menu icon () on the cloned step and select Edit. Anzo opens the Edit load data step screen. Proceed to the next step.
  6. On the Details tab, type a name for the step in the Title field and add an optional description in the Description field.
  7. By default the Enabled option is selected, indicating that the step is enabled and will run when the layer is loaded. If you want to disable the step so that it is not processed, clear the Enabled check box.
  8. Click the Source drop-down list and configure the source data for this step. 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 query runs against only the data that is generated in the layer to which this step belongs.
    • All Previous Layers Within Graphmart: Choosing this option means that the query runs against the data that is generated by all of the layers in the graphmart that precede this layer.
    • Previous Layer Within Graphmart: Choosing this option means that the query runs against only the data that is generated by the one layer that precedes this layer.
    • Layer Name: The Source drop-down list also includes options for specific layer names. You can choose a specific layer to run the query against only the data that is generated by that layer.

      You can remove any of the source options by clicking the X to the left of the option name.

  9. Click the Data models drop-down list and select the model or models to run this query against.
  10. Click the Query tab to compose the query that this step will run. The tab includes the syntax for writing SPARQL INSERT and DELETE queries. For example:
    DELETE{
      GRAPH ${targetGraph}{                
     }
    }
    INSERT{
      GRAPH ${targetGraph}{
     }
    }
    ${usingSources}
    WHERE{
    }

    The template includes target and source graph parameters (${targetGraph} and ${usingSources}). Using the configured Source data options from the Details tab, Anzo automatically populates the query with the appropriate target and source graph URIs when the query runs. Edit the template text as needed. See SPARQL Query Templates and Best Practices for more information. For information about the SPARQL syntax for INSERT and DELETE queries, see SPARQL 1.1 Update Language in the W3C SPARQL 1.1 Update specification.

    For information about incorporating data from a remote endpoint, see Blending Data from Remote Sources (Preview).

  11. Click Save to add the step to the data layer. Anzo adds the step as the last step in the layer. If you want to change the order of the steps, click the black bar on the left side of a step and drag it up or down.

Example Query Step

The example below uses a data set that includes data about people, including a birthday property. The Query step uses the data that is generated by previous layers to calculate and insert the age of each person using their birthday values. The image below shows the details for the step:

The image below shows the query for this step. The query inserts triples for the age of each person, which is calculated by subtracting the year in the birthday date value from the current year.

The p_Age property shown below was manually added to the data model for the data set.

Running the example query step populates the values for the p_Age property.

Related Topics