Introducing a new way to review your PRs.

Read the announcement

getredash / redash

Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.

View on GitHub

20 documents · Updated Nov 11, 2026

docs / querying-and-data-sources

Querying and data source integration

Redash turns a saved or ad hoc query into a controlled request against a configured data source. It checks access and parameters, selects the data source's query runner, executes the work through a background job, stores the returned table, and delivers that result through the HTTP API.

Query lifecycle

The query lifecycle connects the saved query, its data source, the execution worker, and the result API. A request can return a cached result at once or return a job for work that must run in the background. The background job model is shared with other long-running work described in Background jobs and scheduling.

flowchart LR
    A[Query request] --> B[Resolve query and data source]
    B --> C[Validate access and parameters]
    C --> D[Apply query options]
    D --> E{Usable recent result?}
    E -->|Yes| F[Return cached result]
    E -->|No| G[Queue query job]
    G --> H[Runner executes query]
    H --> I[Store query result]
    I --> J[Link latest result to saved queries]
    J --> K[Return result through API]

The same path supports saved queries and ad hoc queries. A saved query can point to its latest stored result. Results are also linked by query hash and data source, so matching saved queries can use the new result.

References: redash/…/query_results.py• L59-113 redash/…/execution.py• L32-123 redash/…/execution.py• L197-263 redash/…/__init__.py• L756-795

Query requests

The query API accepts query text or a saved query identifier together with a data source identifier. It enforces the caller's query and data source permissions before it starts work. Saved-query creation and refresh also require access to the selected data source, so a query cannot be bound to a source that the caller cannot use.

Query changes can include parameter definitions and query-backed dropdowns. Redash checks access to each related dropdown query before it saves or runs the query. The HTTP contract and job endpoints are described in Backend HTTP API.

The API reports one of two normal execution states:

  • A matching cached result is returned when the requested age allows it.
  • A background job is returned when the system must execute the query.

The query job can later be checked through the job endpoint. A caller can cancel a running job through the same job interface.

References: redash/…/query_results.py• L143-188 redash/…/query_results.py• L217-285 redash/…/query_results.py• L399-412 redash/…/queries.py• L221-245 redash/…/queries.py• L452-479 redash/…/api.py• L228-249

Scheduled query refresh

Scheduled refresh uses the same execution path as an interactive request. The scheduler selects outdated saved queries, applies their stored parameter values, applies the query's automatic limit setting, and places the work on the data source's scheduled queue. It skips disabled organizations, detached queries, paused data sources, and refreshes disabled by configuration. Invalid values or detached dropdown queries are recorded as refresh failures instead of being sent to the source.

References: redash/…/maintenance.py• L33-117

Data source configuration

A data source is an organization-owned target with a type and protected connection options. Its type identifies the query runner and its configuration schema defines which options are valid. Administrators create and edit data sources. Access rules then decide which users and groups may run queries against them.

Each runner supplies the connection settings that its external system needs. For example, a Databricks source requires a host, HTTP path, and access token. It can also set a catalog and a statement timeout, while query annotation is optional. These settings shape both how Redash reaches the source and how the source handles query work.

Data source management also supports two related operations:

  • A connection test checks that the configured target can be reached.
  • A schema request asks the runner for table and column information. The result is cached for later use unless a refresh is requested.

An administrator can pause a data source. The query API then refuses new work until the source resumes. Deleting a source detaches its queries and removes its stored results.

References: redash/…/data_sources.py• L31-98 redash/…/data_sources.py• L101-184 redash/…/data_sources.py• L187-248 redash/…/__init__.py• L112-124 redash/…/__init__.py• L196-228 redash/…/__init__.py• L245-284 redash/…/databricks.py• L79-104

Query runner selection

A query runner is the connector boundary between Redash and one external data system. The data source type selects a registered runner, and the data source options construct that runner for the request. Only runners whose dependencies are available enter the registry. This keeps one execution contract across SQL systems, APIs, files, spreadsheets, graph stores, and local data.

The runners translate source-specific queries and responses into a common table with columns and rows. The main source groups are:

Source groupQuery purposeCommon result behavior
SQL and analytical databasesRun SQL against hosted or local dataApply the shared SQL rules and map source types to Redash column types
Document and graph systemsRun a native query language against records or graphsFlatten or normalize source fields into table columns
Files and spreadsheetsRead a remote CSV, Excel workbook, or Google SheetInfer or map column types and return tabular rows
Business and query APIsRead paged records or endpoint resultsFollow the source response shape and normalize it for result storage

SQL runners can add an automatic limit when the query requests it. Some connectors also enforce a source-specific row cap and mark the result as truncated. Databricks maps its native scalar types to Redash types and marks a result as truncated when it exceeds its configured row limit. The detailed connector catalog and runner contract are covered in Query runner platform.

References: redash/…/__init__.py• L128-287 redash/…/__init__.py• L290-357 redash/…/__init__.py• L360-435 redash/…/__init__.py• L438-483 redash/…/arango.py• L30-95 redash/…/corporate_memory.py• L31-59 redash/…/corporate_memory.py• L148-179 redash/…/couchbase.py• L74-154 redash/…/csv.py• L23-115 redash/…/databricks.py• L62-174 redash/…/duckdb.py• L50-170 redash/…/exasol.py• L65-160 redash/…/excel.py• L25-113 redash/…/google_spreadsheets.py• L183-261 redash/…/salesforce.py• L64-205 redash/…/sparql_endpoint.py• L27-216

Parameter handling

A parameterized query is query text with named placeholders and a parameter schema. Before execution, Redash checks supplied values against that schema and renders them into the query. It supports scalar and list values, date values, number values, fixed choices, pattern checks, and values loaded from another query's latest result.

Parameter safety affects access. Queries with free text parameters are not safe for shared or read-only execution. A saved query can run with view-only access only when its parameter definitions pass the safety check. Missing or invalid values stop the request before it reaches the data source.

Query-backed parameters create a dependency between the current query and the dropdown query that supplies its values. Redash checks access to that related query and rejects the request when the related query is detached from a data source. The same access rule applies when a query is created or updated through the query API. Query creation checks the data source and dropdown-query access before it stores the new query. Query updates apply the same checks when the data source or parameter definitions change. A refresh collects parameter values from the request, builds the parameterized query, and passes the saved query's automatic-limit setting into execution.

References: redash/…/parameterized_query.py• L32-51 redash/…/parameterized_query.py• L117-193 redash/…/query_results.py• L263-285 redash/…/queries.py• L169-190 redash/…/queries.py• L227-247 redash/…/queries.py• L336-380 redash/…/queries.py• L458-479

Query execution

Execution runs in a background worker so the HTTP request does not need to hold the database connection while the external system works. The job reloads the data source and resolves the submitting user before it calls the runner's execution boundary. Runner annotations carry only controlled identity and execution fields, which gives operators context without placing free-form job metadata into query text.

Redash prevents duplicate active jobs for the same query hash and data source. Each job uses the data source's normal or scheduled queue and has a configured time limit. A failed or timed-out run reports an execution error. A successful run records its duration and retrieval time before it becomes available to result consumers. The worker releases the duplicate-job lock on both successful and failed execution paths.

References: redash/…/execution.py• L24-123 redash/…/execution.py• L134-147 redash/…/execution.py• L174-235 redash/…/execution.py• L243-274 redash/…/execution.py• L290-316

Result storage and delivery

Each successful execution creates a query result with the data source, query hash, query text, returned table, runtime, and retrieval time. Redash updates every active saved query with the same hash and data source to point to that result. This makes the result available through both a query identifier and a result identifier.

Query results can also act as data for another query. The query-results runner loads cached or newly executed dependent results into a temporary table, checks access in the dependent query's organization, and runs the parent query over those tables. This creates a controlled link between query composition and the normal result shape.

The result API can return JSON for application use or CSV, TSV, and XLSX for download. API-key access receives only the fields needed for public result use. Access checks still apply to stored results, and a query-linked fetch must match the saved query's hash when the caller uses an API key.

For the result shape, cache lookup, and output formats, see Query results and serialization.

References: redash/…/__init__.py• L311-383 redash/…/execution.py• L243-263 redash/…/query_results.py• L46-107 redash/…/query_results.py• L161-221 redash/…/query_results.py• L287-396 redash/…/query_result.py• L75-124

Change checklist

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

  • Keep the data source type registry, import list, optional dependency checks, and configuration schema aligned. A removed or unavailable runner can leave existing data sources unable to execute.
  • Keep query hash inputs consistent across parameter rendering, automatic limits, cache lookup, result storage, and latest-result linking. A mismatch can return an old result or leave a saved query without its new result.
  • Keep parameter safety rules aligned with both interactive access checks and shared or API result access. A change in parameter definitions can change who may execute a saved query.
  • Keep the job metadata contract aligned between request enqueueing and worker user or query resolution. Missing query or API identity can change permissions and result ownership.
  • Keep result fields and column types aligned with JSON, delimited-file, and spreadsheet serializers. A new runner result shape must remain readable by every supported delivery format.
  • Keep runner annotation fields stable when a connector uses source-side caching. Databricks removes changing job identifiers from annotations so equivalent runs can reuse its source result cache.
  • Keep JSON data source base-URL checks aligned with URL joining and pagination. A new pagination mode must not allow a later page to leave the configured origin.
  • Keep dependent-query access checks aligned between cached results and fresh parameterized results. A change in one path can expose a result that the other path would reject.
  • Keep query creation and update checks aligned. A new query must validate its data source and dropdown dependencies before storage, while an update must re-check any changed data source or parameter definitions.
  • Keep refresh request parsing aligned with parameter rendering and automatic-limit handling. A change to one can make manual refresh differ from scheduled execution.

Important failure modes

TriggerConsequenceGuard
The data source is pausedNew query work is rejected before enqueueingResume the source after the pause reason is resolved
The configured runner is unavailable or no longer registeredThe data source cannot execute queriesInstall the required runner dependency or move the source to a supported type
A required parameter is missing or its value fails the schemaThe query does not execute and the API returns an error job responseSupply values that match the saved parameter definitions
A query-backed parameter points to a detached queryDropdown validation cannot load allowed valuesAttach the related query to an available data source
A runner raises an error or exceeds the time limitNo query result is stored and the job reports failureCheck the data source and query within the configured execution limit
A runner-specific row cap is reachedThe result is stored with only part of the source data and is marked truncatedReview the runner's row limit before using the result for complete data work
A Databricks statement timeout is reachedThe warehouse cancels the statement and the job reports an execution failureSet a suitable source timeout and keep the query within that limit
A local analytical source blocks a query's external accessA query that needs a file, network, or extension resource failsEnable only the external access needed by the data source
A JSON page points outside the configured data source originThe request is rejected before the next page is fetchedKeep endpoint and pagination links within the source base URL
A dependent query is detached or the caller lacks source accessA query-results composition run fails before the parent query runsKeep dependent queries attached and grant access to each source
A caller requests a result without access to its data sourceThe result is not deliveredGrant the required data source or query permission
A query changes after its result is cachedAPI-key lookup can reject the old result as a hash mismatchExecute the current query or request the matching result identifier
A query update uses an old revisionThe update is rejected to prevent a stale writeReload the query and apply the change to its current version
A query is created or updated with an inaccessible data source or dropdown queryThe saved query is rejected before it can runGrant access to each referenced source and dropdown query

Key files

FileWhy to read it
redash/…/query_results.pyShows the public execution, cache, job, permission, and result-delivery flow.
redash/…/queries.pyShows saved query creation, updates, data source binding, parameter dependencies, and refresh requests.
redash/…/data_sources.pyShows data source creation, validation, schema access, connection tests, and pause controls.
redash/…/__init__.pyDefines the relationships among data sources, saved queries, and stored query results.
redash/…/parameterized_query.pyDefines parameter validation, rendering, safety, and query-backed dropdown values.
redash/…/execution.pyShows background job de-duplication, runner execution, result storage, and latest-result updates.
redash/…/__init__.pyDefines runner registration, shared result types, SQL limits, HTTP access, and the connector boundary.
redash/…/duckdb.py and redash/…/databricks.pyIllustrate SQL sources that map native types to Redash types, apply source settings, and may cap returned rows.
redash/…/csv.py, redash/…/excel.py, and redash/…/google_spreadsheets.pyIllustrate file and spreadsheet sources that turn remote tabular data into query results.
redash/…/salesforce.pyIllustrates a business API source that follows pages and flattens related records.
redash/…/corporate_memory.py and redash/…/sparql_endpoint.pyIllustrate graph query sources that normalize SPARQL results for Redash.
redash/…/query_results.pyShows how one query can use cached or parameterized results from other queries as temporary tables.
redash/…/query_result.pyShows how stored table data becomes JSON-oriented or downloadable output.