Amazon Athena query editor
This document explains how to use the Amazon Athena query editor to build and run SQL queries in Grafana.
Before you begin
Before you use the query editor, ensure you have the following prerequisites.
- Configure the Amazon Athena data source.
- Verify your IAM credentials have the required Athena, Glue, and S3 permissions.
Key concepts
If you’re new to Amazon Athena, the following terms are used throughout this documentation.
Query editor fields
The query editor provides resource selectors and a SQL code editor with context-aware autocompletion.
Resource selectors
Use the drop-down selectors at the top of the query editor to choose the query context. All selectors support template variables.
Format options
Select a format for the query results.
Write a query
The query editor provides a SQL code editor with context-aware autocompletion for table and column names. Write standard SQL queries to retrieve data from your Athena tables.
Table visualization example
Most Amazon Athena queries are best represented by a table visualization.
SELECT column_1, column_2 FROM my_table;Time series example
For time series and graph visualizations, select a column with a date or datetime type in ascending order and at least one numeric column.
SELECT
time,
value
FROM my_table
WHERE $__timeFilter(time)
ORDER BY time ASCMacros
Grafana provides macros that expand to Athena-compatible SQL at query execution time. Use macros to dynamically filter data based on the dashboard’s time range and other settings.
Inspect the query
Grafana macros aren’t valid Athena SQL, so a query that uses macros won’t work if copied and pasted directly into Amazon Athena. To view the fully interpolated query that works in Amazon Athena, click the Query Inspector button and select the Query tab.
Async query data support
Async query data support enables an asynchronous query handling flow. Queries are handled over multiple requests (starting, checking status, and fetching results) instead of starting and resolving a query in a single request. This is useful for queries that run for a long time and might otherwise time out.
Async query data support is enabled by default in all Amazon Athena data sources.
Async query caching
To enable query caching for async queries, you must meet the following requirements:
- Run Grafana version 10.1 or later.
- Set the feature toggles
useCachingServiceandawsAsyncQueryCachingtotrue. - Configure query caching for the Amazon Athena data source.
Query result reuse
Query result reuse lets Amazon Athena reuse query results from previous executions, reducing cost and query time. You can enable it per query by selecting the Enabled checkbox in the Query result reuse section of the query editor. You can also configure the Max Age in Minutes setting (default: 60 minutes) to control how old a cached result can be.
For more information, refer to the Amazon Athena documentation on reusing query results.
Note
Result reuse requires Amazon Athena engine version 3. For upgrade instructions, refer to Changing Athena engine versions.


