

# Migrate from Athena engine version 3 to DuckDB

The **Athena migration agent** helps you make the queries you run in an Athena engine version 3 workgroup compatible with DuckDB. You can use it in the Athena console or with the Athena API.

The migration agent provides several features that help you assess queries for compatibility, translate SQL from Athena engine version 3 to DuckDB's SQL dialect, and validate these translations:
+ **Assess** – Reads a workgroup's recent queries and reports how compatible they are with DuckDB.
+ **Translate** – Rewrites a query in DuckDB's SQL dialect and lists the changes, so that you don't rewrite queries by hand.
+ **Validate** – Runs the translated query on DuckDB and compares the row count and schema of its results with the original query's results.

Assessment and translation features don't alter the original SQL query you submit, run the translated query, or change your underlying data. Your queries keep running on engine version 3 until you submit them to a DuckDB workgroup.

## How it works
<a name="athena-duckdb-migration-agent-how-it-works"></a>

A typical migration has four steps: assess your queries, translate them, validate the translations, and then submit your queries to a DuckDB workgroup. Queries that aren't translated or that fail validation need your review and changes before they can run on a DuckDB workgroup.

![Diagram of the four migration steps, from assessing queries to moving them to a DuckDB workgroup.](https://docs.aws.amazon.com/athena/latest/ug/images/athena-duckdb-migration-agent-flow.png)



| Step | What Amazon Athena does | What you do | 
| --- | --- | --- | 
| 1. Assess | Reads up to 50,000 of the workgroup's recent queries and reports how ready they are. Writes the report to your Amazon S3 location. | Review your query patterns and how ready the workgroup is for DuckDB. | 
| 2. Translate | Rewrites a query in DuckDB's SQL dialect and lists the changes. Doesn't run the query. | Review the translated query and the proposed changes. | 
| 3. Validate | Runs the translated query on DuckDB and compares its result metadata with the original query's result. Runs write statements only as EXPLAIN. | Review the query, the query changes, and the data checks that verify the translated query. | 
| 4. Move to DuckDB workgroup | Runs your queries on DuckDB. | No action required. | 

## Before you start
<a name="athena-duckdb-migration-agent-before-you-start"></a>

The **Athena migration agent** setting controls which migration agent features are available in a workgroup. You turn it on for each workgroup. The following table shows what you can do when the setting is off or on.


| Setting | What you can do | 
| --- | --- | 
| Off (default) | Run a one-time assessment of the workgroup. Translate a single query on demand in the query editor. | 
| On | Assess the workgroup and translate single queries, the same as when the setting is off. In addition, Athena automatically translates every query that you run in the workgroup, and you can validate queries in the query editor. | 

**To turn on the setting in the console**

1. Open the Athena console at [https://console.aws.amazon.com/athena/](https://console.aws.amazon.com/athena/home).

1. In the navigation pane, under **Administration**, choose **Workgroups**.

1. Choose an engine version 3 workgroup, and then choose **Edit**.

1. Under **Athena migration agent**, choose the **Turn on** tile, and then choose **Save changes**.

The workgroup edit page shows the **Athena migration agent** setting with the **Turn on** tile selected.

![The workgroup edit page. In the Athena migration agent setting, the Turn on tile is selected.](https://docs.aws.amazon.com/athena/latest/ug/images/athena-duckdb-migration-agent-shot-1.png)


After you turn on the setting, the migration agent translates each query that succeeds in the workgroup. To see the translations, open the query editor, choose the workgroup, and then choose the **Recent queries** tab. The **Translation status** column shows each query's status, such as **Translated**, **No translation needed**, **Needs review**, **Validated**, or **Failed**. Choose a query to open a split view with the change summary and the original and translated SQL.

For an example of an original query, its translation, and the change summary as text, see [In the console](duckdb-migration-agent-translate.md#athena-duckdb-migration-agent-translate-console) in [Translate queries to DuckDB](duckdb-migration-agent-translate.md). The following screenshot shows the **Recent queries** tab with a translated query open in the split view.

![Recent queries tab with a translated query open in the split view.](https://docs.aws.amazon.com/athena/latest/ug/images/athena-duckdb-migration-agent-shot-7.png)


For more information about each status, see [Assess a workgroup for DuckDB compatibility](duckdb-migration-agent-assess.md).

## Getting started
<a name="athena-duckdb-migration-agent-getting-started"></a>

After you turn on the **Athena migration agent** setting, follow these steps to migrate a workgroup's queries to DuckDB:

1. Assess a workgroup to see how many of its queries can run on DuckDB. See [Assess a workgroup for DuckDB compatibility](duckdb-migration-agent-assess.md).

1. Translate queries to DuckDB's SQL dialect, and review the changes. See [Translate queries to DuckDB](duckdb-migration-agent-translate.md).

1. Validate the translated queries before you move them. See [Validate translated queries](duckdb-migration-agent-validate.md).

1. Assess, translate, and validate many queries at once with an AI assistant. See [Migrate queries in bulk with an AI assistant](duckdb-migration-agent-skill.md).

For information about how the migration agent handles your data, see [Security for the migration agent](duckdb-migration-agent-security.md).

**Topics**
+ [How it works](#athena-duckdb-migration-agent-how-it-works)
+ [Before you start](#athena-duckdb-migration-agent-before-you-start)
+ [Getting started](#athena-duckdb-migration-agent-getting-started)
+ [Assess a workgroup for DuckDB compatibility](duckdb-migration-agent-assess.md)
+ [Translate queries to DuckDB](duckdb-migration-agent-translate.md)
+ [Validate translated queries](duckdb-migration-agent-validate.md)
+ [Migrate queries in bulk with an AI assistant](duckdb-migration-agent-skill.md)
+ [Security for the migration agent](duckdb-migration-agent-security.md)