View a markdown version of this page

Translate queries to DuckDB - Amazon Athena

Translate queries to DuckDB

Translate Athena engine version 3 queries to DuckDB's SQL dialect, and review the changes. Translation rewrites a query in DuckDB's SQL dialect, so that you don't change functions and syntax by hand, and lists the changes. Translation doesn't run the query.

The migration agent translates queries in the following ways:

  • On demand – In the query editor, choose Translate query. The result opens on the Translate results tab. You don't need to turn on the Athena migration agent setting.

  • Queries that you run – When the Athena migration agent setting is on, the migration agent translates each query that succeeds in the workgroup. The result appears on the Recent queries tab.

  • Queries that you save – When the Athena migration agent setting is on, the migration agent translates each saved query when you create or update it. The result appears on the Saved queries tab.

To turn on the Athena migration agent setting, see Before you start.

In the console

  1. Open the Athena console at https://console.aws.amazon.com/athena/.

  2. In the query editor, choose an engine version 3 workgroup.

  3. Enter the engine version 3 query that you want to translate.

  4. Choose Use migration agent, and then choose Translate query. Athena opens the Translate results tab with the change summary and the original and translated SQL. If the migration agent can't translate the query, the tab shows Translation failed with the reason.

    The Translate results tab, with the change summary and the original and translated SQL side by side.

For example, the migration agent translates the following query:

SELECT category, CARDINALITY(ARRAY_AGG(DISTINCT product_name)) AS product_count FROM products GROUP BY category

The translated query is:

SELECT category, ARRAY_LENGTH(ARRAY_AGG(DISTINCT product_name)) AS product_count FROM products GROUP BY category

The Change summary shows "CARDINALITY(ARRAY_AGG(DISTINCT product_name)) -> ARRAY_LENGTH(ARRAY_AGG(DISTINCT product_name))".

View translation results

The Recent queries tab shows the translations of the queries that you run when the Athena migration agent setting is on, and of the queries that an assessment reads. The Saved queries tab shows the translations of your saved queries. A query that you translate on demand appears only on the Translate results tab.

To view a translation
  1. Open the Athena console at https://console.aws.amazon.com/athena/.

  2. In the query editor, choose the engine version 3 workgroup.

  3. Choose the Recent queries tab or the Saved queries tab. The Translation status column shows each query's status, such as Translated, No translation needed, Needs review, Validated, or Failed.

  4. Choose a query. A split view opens with the change summary and the original and translated SQL.

The Recent queries tab with a translated query selected. The split view shows the change summary and the SQL.

A query with the status Needs review (TRANSLATION_NEEDS_REVIEW) means that the migration agent isn't confident in its translation, or didn't produce one. Choose the query on the Recent queries or Saved queries tab, and then review and edit the translated SQL. If the migration agent didn't produce a translation, the translated SQL panel shows the original query unchanged, and you rewrite it yourself. Then validate the query.