Pre-Compile a Query (Pre-Compile Query Step)

The first time a user runs an analytic query against Graph Lakehouse, Graph Lakehouse performs a code compilation process to generate the code for running that query. It then executes the query using that compiled code, and the same code is reused for subsequent runs of the query. If you determine that a particular query has a long code compilation time, you can add that query to a Pre-Compile Query Step. That way the query is run during the graphmart load and the compiled code is available before an end-user runs that query. Follow the steps below to create a Pre-Compile Query Step.

  1. Go to the graphmart for which you want to add a step and then expand its Data Layers list.
  2. In the Data Layers list, find the layer that you want to add the step to. Click the menu icon () for that layer and select Add Step/View. For example:

    The Add Step/View dialog box is displayed with the New tab selected.

  3. To create a new Pre-Compile Query Step, select Pre-Compile Query 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. Graph Studio creates or clones the step and displays the Details tab:

  4. 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.
    • If the precompile query fails, the layer will be marked as failed: This option controls whether loading the data layer that contains this step is completed or aborted if this step fails. Select this option if you want Graph Studio to fail the layer if this step fails.
    • If the precompile query fails, the whole graphmart will be marked as failed: This option controls whether loading the graphmart is completed or aborted if this step fails. Select this option if you want Graph Studio to fail the entire graphmart if this step fails.
    • 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 the data that is in the parent layer.
      • All Previous Layers Within Graphmart: This option means that the step runs against the data in 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 the data that is in the one layer that precedes the layer this step is in.
      • Layer Name: The Source drop-down list also includes options for layer names. You can choose a specific layer to act upon the data in that layer.
    • Pre-Run Generate Statistics: This option controls whether to initiate Graph Lakehouse's internal statistics gathering queries before running the query to pre-compile. The statistics gathering helps ensure that the Graph Lakehouse query planner generates ideal query execution plans for queries that are run against the graphmart.
  5. When you have finished configuring the Details tab, click the Query tab. This tab contains the query to pre-compile. The tab provides a template for writing a SPARQL SELECT query. You can edit the template to write the query, or you can paste in query contents that you copied from a log file, dashboard, the Query Builder, etc.

    Make sure that you include the ${fromSources} parameter in the query. Graph Studio automatically populates the query with the appropriate source graph URIs according to the Source configured from the Details tab.

    If your query connects to a source that requires input of connection and authorization information, Altair 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.

  6. Click Save to save the step configuration.

Once the Details tab is configured and the query is written, the step can be run. For information about running this step conditionally by setting up an execution condition, see Defining Execution Conditions.