All Collections
Creating a Model
Introduction to the Queries Editor
Introduction to the Queries Editor
Ori Sagi avatar
Written by Ori Sagi
Updated this week

Pecan’s Queries Editor is where you’ll transform historical data into an AI-ready dataset that your model can train itself on and continually make predictions for.

This is done by creating SQL queries in the Editor. Pecan uses these queries to automatically generate AI-ready tables that can be fed into your model. Your model is then able to interpret the data, learn from it, train itself, and make predictions for future datasets.

The tables generated by these queries (also known as ETA tables) essentially communicate your predictive question through your data. For example, your queries might tell the following story: “Here's what a churned customer looks like in the data. Based on this, how likely is it that other customers will churn?”

To guide you through the Queries Editor and how to use it, this article contains an overview of each of its sections.

SQL Editor

The “SQL Editor” tab is where you’ll prepare queries that define the Entity, Target and Attribute components of your dataset, generating input tables that tell Pecan what to look for and measure.

What’s important to remember is that these SQL queries are not your model itself, but rather, a way to make your data machine-readable.

Some important things to note:

  • Clicking Keyboard shortcuts will reveal shortcuts that make it easier to build your SQL queries.

  • Clicking Compiled will preview how your final query appears once populated with the contents of the variables used.

  • The syntax “-->” denotes a common table expressions (CTE) that can be used to reference the related result set within the query itself. It also serves as anchor text within the query, appearing as a clickable subitem in the left-side panel.

Building ETA queries

In the Queries Editor, clicking on each of “Entity”, “Target” and “Attributes” will open up the relevant SQL queries that define your predictive question. The question you wish to answer, and thus the model you wish to create, determine the “ingredients” that go into building these queries.

For a deeper dive into building Entity, Target and Attribute queries in the Queries Editor, see Building your ETA queries with SQL.

Or, for an overview of how to work with the Queries Editor and build queries for specific use-cases, go to:

When you’re finished building a query, click Save and run to generate an input table that will be used to train your model. Each query may run successfully, or you may encounter an error that needs to be resolved.

Once you’ve successfully run all three queries, you have an AI-ready dataset, as represented by input tables at the bottom of your screen. Click Create model so Pecan can begin training, validating and testing your model based on the provided data. (At this stage, you’ll also be able to configure some advanced settings.)

Common errors when running a query

  • A syntax error related to the way your SQL query has been built

  • A runtime error, which may result from an issue Pecan’s server infrastructure

  • A validation error, which indicates that a problem in the table or data will cause the AI process to fail

    • For example: having duplicate columns or rows, lacking a particular column, an imbalanced distribution of records over time, etc.

Schema

This panel displays all of the tables that are available for you to use in your model. They are available because you previously connected Pecan to their parent data source and imported them.

Variables

Variables are customizable properties that can be injected into SQL queries. They are defined per flow and are located in the right-side panel of the Queries Editor.

Model variables contain strings or numbers that impact how a query functions, and help define your predictive question – such as what to predict, for whom, for what period, and how frequently.

Variables can be added, edited, or deleted. Each variable needs to be defined in order for it to be functional. For example, you can indicate the number of days beyond the marker date you wish to make a prediction for by entering this number under the prediction_window variable.

If you’re working from a template, your flow will already contain a list of preset variables that have default values (which can be adjusted).

At any given time, you can click the “Compiled” tab at the top of the Editor to see how the values of variables appear within your SQL.

For everything you need to know about variables – such as how to define and use them, how to create new ones, and what each preset variable means – see Creating and using variables.

Input tables (a.k.a. ETA Tables)

Once you successfully run each query, an input table will be generated and previewed at the bottom of the screen.

Together, your Entity, Target and Attributes tables make up a complete training dataset – ready to be fed into your Pecan model so it can begin to recognize patterns and relationships between data entries.

  • The Entity table sets out who and when predictions will be generated for

  • The Target table defines what you want to predict

  • Attributes tables provide information that forms the basis of your predictions.

Once you click Create model, the tables will be joined, and the training, validation and testing process will begin.

Advanced settings

Once you click Create model, you’ll be presented with Advanced settings that enable you to override automatic AI decisions in the pipeline.

Once you ready to proceed, click Create model to kickstart the model-training process.

Did this answer your question?