Introducing a new way to review your PRs.

Read the announcement

frappe / insights

Open Source Business Intelligence Tool

View on GitHub

25 documents · Updated Nov 23, 2026

docs / data-exploration

Data exploration and query building

Data exploration lets an engineer or analyst turn source data into a useful result through a saved analytical query. The experience connects source selection, ordered data operations, query execution, and result review in one workspace. It supports visual query building as well as native SQL and script-based analysis.

Analytical query model

Query sources

A query starts from either a table in a configured data source or another query in the same workbook. A query used as a source makes saved work reusable and lets later queries build on an earlier result. The source selector shows only sources and workbook queries that the user can use, and it avoids direct circular links between workbook queries.

The data source list is backed by synced table metadata. A user can search the list or refresh it when the source schema changes. A table preview uses the same access rules as query execution, so exploration does not expose rows or columns that the user could not query.

References: frontend/…/SourceSelectorDialog.vue• L28-116 frontend/…/DataSourceTableList.vue• L19-65 frontend/…/WorkbookQueryList.vue• L14-27 insights/…/data_sources.py• L37-113

Query operations

The visual builder represents a query as an ordered list of operations. Each operation changes the current table expression, so the order defines the meaning of the result and gives the user a visible path from source to output.

The operation set covers the main analytical actions:

  • Combine sources with joins or unions.
  • Select, remove, rename, or convert columns.
  • Filter rows with rules or expressions.
  • Calculate new columns.
  • Summarize measures by dimensions.
  • Sort, limit, or pivot the result.

The builder can inspect an earlier point in the list. This supports step-by-step review and lets controls ask for the columns that exist before the operation being edited. Query history also supports undo and redo while the user composes the list.

References: frontend/…/query.types.ts• L90-189 frontend/…/query.ts• L318-475 frontend/…/QueryBuilder.vue• L13-45 frontend/…/QueryOperations.vue• L26-47

Query interfaces

The query workspace offers three interfaces for the same analytical goal. The visual interface builds the ordered operation list. The native interface runs SQL against a selected data source. The script interface runs a Python script and can use saved variables and live log output.

The interface choice changes how the query is composed, but all three interfaces share the query result view, execution status, and query details. The visual builder runs after operations change. SQL and script queries run when the user chooses Run or Execute, which gives the user control over more expensive work.

For the detailed interaction rules, see Query editor and execution.

References: frontend/…/Query.vue• L18-41 frontend/…/NativeQueryEditor.vue• L18-41 frontend/…/ScriptQueryEditor.vue• L14-46

Query execution

Query translation

The server turns the saved query description into a table expression before it runs. It resolves a table source or a query source, applies each operation in order, and includes temporary filters from the result view when needed. A query source is built as part of the current query, so dependent saved queries can form a reusable analytical chain.

The same build path serves visual operations and the native or script query forms. It can stop at the active operation, which supports previews and editing. The server rejects circular query dependencies before they can become a saved relationship and also guards against cycles during query building.

For the server-side helpers and dependency rules, see Query utilities.

References: insights/…/insights_query_v3.py• L81-151 insights/…/ibis_utils.py• L53-173 insights/…/query_utils.py• L44-71 insights/…/query_utils.py• L101-181

Execution lifecycle

Execution is a paged request that returns the generated SQL, result columns, rows, elapsed time, and whether the result came from an aggregate query. The client keeps only the newest execution result, so a slower request cannot replace a newer one after the user changes the query.

The following flow shows how a composed query reaches the result view.

flowchart LR
    A[Source and operations] --> B[Build table expression]
    B --> C{Cached result?}
    C -->|Yes| D[Return cached page]
    C -->|No| E{Data store or live source}
    E --> F[Run query]
    F --> G[Cache eligible result]
    D --> H[Return columns and rows]
    G --> H
    H --> I[Format and present result]

Results can use cached data for speed or a live connection for fresher data. Live requests are limited on the server; the client queues work, gives waiting requests a priority, and retries a busy response for a limited time.

References: insights/…/insights_query_v3.py• L153-191 insights/…/ibis_utils.py• L911-991 frontend/…/execution_queue.ts• L44-83 frontend/…/query.ts• L176-265

Query freshness

Each query can choose between a live connection and the data store when that feature is enabled. Live mode favors current source data. Data-store mode favors faster reads and can combine data from multiple sources, but its tables can be out of date until they are refreshed.

This choice belongs to the query and affects both source resolution and execution. The workspace makes the trade-off explicit before the user changes it.

References: frontend/…/QueryInfo.vue• L9-24 insights/…/insights_query_v3.py• L141-151 insights/…/ibis_utils.py• L934-951

Result presentation

Result table

The result table is the main feedback surface for a query. It displays typed columns and formatted rows, then adds pagination when the result is larger than the preview page. The table can fetch a total row count separately, which avoids making every first result request scan the full result.

The table also supports column actions that feed back into the query: sorting adds an order operation, filtering adds temporary filters or builder filters, and renaming or column creation updates the visual query. A filter on a result that fits on one page can run in the browser without another server request.

References: frontend/…/QueryDataTable.vue• L40-85 frontend/…/QueryDataTable.vue• L126-188 frontend/…/query.ts• L268-298 frontend/…/query.types.ts• L192-229

Result formatting

The client keeps raw rows for query actions and derives formatted rows for display. Date and time dimensions use the selected granularity, while text values are cleaned for table presentation. Column metadata also identifies possible measures so later analytical controls can offer suitable summaries.

Execution status shows whether the result came from cache or how long the query took. This gives the user a simple signal about freshness and query cost without exposing the internal execution path.

References: frontend/…/helpers.ts• L111-153 frontend/…/helpers.ts• L154-228 frontend/…/query.ts• L221-250 frontend/…/QueryExecutionStatus.vue• L10-25

Result actions

The result view connects analysis to follow-up work. Users with download access can export the current query result as CSV or Excel. A summarized or pivoted row can open a drill-down query with filters derived from the selected dimensions and measure. The result can also be used to configure alerts.

These actions create a new view of the same analytical intent rather than changing the saved query unexpectedly. Drill-down is available only when the system can relate the selected result back to summarized data.

References: frontend/…/QueryDataTable.vue• L87-124 frontend/…/QueryDataTable.vue• L198-245 frontend/…/query.ts• L584-687 frontend/…/query.ts• L773-823

Change checklist

When these files or sections are changed, remember to consider these:

  • When query operation types or their fields change, update the shared query model, the visual operation controls, and the server operation builder together.
  • When source or table permissions change, keep table selection, table preview, schema lookup, and query execution on the same permission boundary.
  • When result paging or temporary filters change, keep the result table, count request, query execution arguments, and cache behavior aligned.
  • When live and data-store routing changes, review both the query freshness control and the server path that selects the execution backend.
  • When query-source links change, preserve dependency tracking and the cycle checks used during save and build.

Important failure modes

TriggerConsequenceGuard
A source table has not been synced into the table listThe user cannot select it in the builderRefresh the source table metadata before composing the query
A query links to itself or to a dependent query that leads back to itThe query cannot be saved or builtValidate the dependency graph and reject the cycle
A live query reaches the server concurrency limitThe request receives a busy response and the result stays unavailable until retry or failureQueue a bounded number of client requests and retry busy responses with backoff
A query exceeds the configured live execution timeThe query fails instead of returning a partial resultNarrow the time range or add a more specific filter
A result export is requested without the required download or export permissionThe export is deniedCheck the user role, download setting, and query permissions before execution
A drill-down is requested from unsummarized dataNo drill-down query can be createdAllow drill-down only when summarized or pivoted operations provide row context

Key files

FileWhy to read it
frontend/…/Query.vueShows how the workspace selects the visual, SQL, or script query interface.
frontend/…/query.tsDefines the shared query state, operation flow, execution requests, result state, and follow-up actions.
frontend/…/QueryBuilder.vueShows the main visual builder layout and its automatic execution behavior.
frontend/…/SourceSelectorDialog.vueShows how users choose a data source table or a workbook query.
frontend/…/QueryDataTable.vueShows how rows, paging, filters, sorting, export, and drill-down connect to the query state.
insights/…/insights_query_v3.pyShows the server boundary for building, executing, counting, and exporting query results.
insights/…/ibis_utils.pyShows the shared path for turning a query expression into a paged, cached, or live result.
insights/…/data_sources.pyShows how source tables, schemas, previews, and source permissions support exploration.
insights/…/query_utils.pyShows how query and table dependencies are found and kept safe.