Dictionary queries

The Queries step holds the SQL that fills a Dictionary. Each source system gets one query, and each source system can be used once per dictionary. Use the step to write the query, check that it returns a Source ID column, fix a failing query with AI, and go back to an earlier version. The other steps are on Dictionary general settings, Define table columns and Dictionary data mapping.

Add a query for a source system

The step shows the Data Sources panel on the left and the SQL editor on the right.

  1. Open a dictionary and go to the Queries step.
  2. Click Add Data Source in the panel. When every source system already has a query, the button is disabled and its tooltip reads "All available data sources are already in use. Each data source can only be used once."
  3. Pick a source system in the Add Data Source window. Search the list with Search sources…: the badge beside Source Systems shows how many sources you can still pick ("N available"), or the matches as "N found" while you search. A source that already has a query shows an In use badge and cannot be picked. Click Clear to drop a selection you changed your mind about.
  4. Check the Query Preview panel on the right. Before you pick, it prompts "Select a data source to preview the new query."; with a source selected, it notes that a new draft query will be created and lists the next steps: write your SQL in the editor, validate the query before saving the dictionary, and use Ctrl+Enter to validate quickly.
  5. Click Add Query. The button reads Adding... while the query is created, and the new query opens in the editor.

The window shows "No source systems available" when there are no source systems to pick, and a line with "No sources match" and your search text when a search finds nothing. Once a source is selected, a summary confirms your choice and a notice repeats the rule: "Each data source can only be used once across all queries." When every source system is taken, the window warns: "All available data sources are already in use. Each data source can only be used once." To use another source system, create it first, as described on Semantic sources, source systems and logical models.

The step starts empty: the panel reads "No sources yet" and the editor area reads "No query selected" until you add a query.

Write and validate the query

  1. Write the SELECT statement in the editor. It must return a column named exactly Source ID; the other rules are in the guidelines window below.
  2. Click Validate in the editor header, or press Ctrl+Enter. The editor becomes read-only while the check runs, and the button reads Validating.
  3. When the query passes, the button turns green and reads Validated, and the rows the query returns open in the Query Data Preview window. The preview does not show run statistics.
  4. When a check fails, the Query Validation Error window opens with the details. The next section lists the checks, and the one after it shows how to fix a query with AI.

Each query in the panel carries a status badge: Validated, Needs fix (it has SQL and a source system but has not passed), or Draft (it has no SQL yet). The open query also shows Validated or Not validated in the editor header. Editing the SQL clears the validated state, so validate again before you save; if you put the text back exactly as it was saved, its saved state returns.

What DataMind OS checks

Validation runs three checks on your query before it is sent, in this order:

  1. The query is not empty.
  2. It contains select; capital letters are ignored.
  3. It contains Source ID character for character, including the capital letters.
MessageWhat to do
Query cannot be emptyWrite a query.
Query must be a SELECT statementWrite the query as a SELECT.
Query must include "Source ID" field (exact match required)Return a column named exactly Source ID.
Error validating queryThe check did not go through. Try again.

The result is checked on the server as well; the rules and their messages are on Dictionaries.

Fix a failed query with AI

  1. The Query Validation Error window opens when validation fails. It shows the message under Error Details.
  2. Optionally, describe what you were trying to do in Additional Context (optional).
  3. Click Fix with AI; the button reads Fixing... while DataMind OS prepares a corrected query.
  4. Review the proposal in the Query Difference Checker: Current Query on one side, AI Suggested Query on the other.
  5. Click Apply Changes to put the suggestion into the editor, then validate again: the suggestion clears the validated state, and it must pass the checks on its own.

If the dictionary is not saved yet, the fix is refused: a Cannot fix query toast says "Save the dictionary first, then try Fix with AI again." If no corrected query comes back, a Fix with AI failed toast appears, with the reason or "Failed to generate a fixed query"; edit the SQL yourself or try again.

Review earlier versions

History in the editor header (tooltip Query history) opens the saved versions of the query. The button appears when the dictionary is saved and the query has a source system.

Check the query guidelines

The Query guidelines button at the bottom of the panel opens Query Guidelines, the rules for writing dictionary SQL queries:

The footer reads "Ctrl+Enter to validate quickly"; click Got it to close the window.

Remove a data source

Hover a row in the Data Sources panel and click the remove button that appears. A query you added in this session disappears from the list straight away; a query that was already saved is marked for deletion and is removed when you save the step. A step with no queries is refused both on save and on the way out; the messages are in the section below.

Save the step

Click Apply to save the step once it has changes, or move on with Next; Revert discards the unsaved changes.

Questions, answered

Why is Validate greyed out?

It needs a query with text and a source system. It is disabled when the editor is empty, when no source system is chosen, while a check is already running, and once the query is validated. Edit the SQL to make it available again.

What do the Validated, Needs fix and Draft badges mean?

Validated means the query passed its checks. Needs fix means it has SQL and a source system but has not passed. Draft means it has no SQL yet. The editor header shows the open query as Validated or Not validated.

Does editing the query clear its Validated state?

Yes. Any change to the SQL clears the state, and the query must be validated again before saving. If you restore the text exactly as it was saved, the saved state comes back.

Can two queries use the same source system?

No. Each source system can be used once per dictionary. A source that already has a query appears with an In use badge in the picker, and when every source is taken, Add Data Source is disabled: "All available data sources are already in use. Each data source can only be used once." To add another query, create another source system first; see Semantic sources, source systems and logical models.

How do I merge several tables from one source into a query?

Write the merge with UNION DISTINCT, as the Combining data guideline asks; that keeps one row per value. Every query must still return the same field count and names as the dictionary's other queries.

My query passed, but the preview says no rows. What now?

It still counts as validated: the query ran and returned nothing. The preview shows No data available and says "This query executed successfully but did not return any rows." Change the SQL if you expected rows, then validate again.

Why does Fix with AI say it cannot fix my query?

Because the dictionary is not saved yet. The fix is refused with Cannot fix query: "Save the dictionary first, then try Fix with AI again." Save the dictionary, then open the query and try again.

Can I go back to an earlier version of a query?

Yes, when the query has saved versions: open History in the editor header, pick a version, and click Replace. The editor takes that SQL back, and the validated state clears, so validate before you save. Compare shows the version against the current query first.

How do I remove a query?

Hover its row in the Data Sources panel and click the remove button. A query added in this session vanishes from the list; a saved query is removed when you save the step.

Why can't I continue past the Queries step?

The step needs at least one data source, and every query must be validated. Otherwise it refuses with a Validation Error that names the check: "Please add at least one data source before proceeding" or "Please validate all queries before proceeding".