

# Validate translated queries

Validation checks that a translated query works on DuckDB before you move it, so that you find problems early. Validation translates an engine version 3 query, runs the original on engine version 3 and the translated query on DuckDB, and compares the row count, column count, column names, and data types of the results, not the row values. If the translated query fails, the migration agent can adjust it and run it again.

Validation doesn't change your data. Read queries, such as SELECT, WITH, SHOW, and DESCRIBE statements, run on both engine version 3 and DuckDB. Statements that change data or catalog objects, such as data manipulation language (DML) write statements and data definition language (DDL) statements, run only as `EXPLAIN`, so the migration agent checks the syntax and the query plan.

**Important**  
Validation runs the original query again on engine version 3, even if the migration agent already translated an earlier run of it. This includes validating a query from the **Recent queries** tab. The original query doesn't run again only if the migration agent applies the result of an earlier validation of a query with the same structure.  
A query can pass every check and still return different values, because some expressions return a different result without an error. Before you move a query, compare its values.

## In the console
<a name="athena-duckdb-migration-agent-validate-console"></a>

**To validate a query**

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

1. In the query editor, choose an engine version 3 workgroup that has the migration agent setting on.

1. Enter the engine version 3 query that you want to validate.

1. Choose **Use migration agent**, and then choose **Validate query**. Athena opens the **Validate results** tab.  
![The Validate results tab, with the Syntax, Row count, Column count, Column name, and Column datatype checks and the SQL.](https://docs.aws.amazon.com/athena/latest/ug/images/athena-duckdb-migration-agent-shot-6.png)

### Read the results
<a name="athena-duckdb-migration-agent-validate-results"></a>

The **Validate results** tab shows a tag for each check: **Syntax**, **Row count**, **Column count**, **Column name**, and **Column datatype**. Each tag shows whether that check passed.

A passing validation checks the query against your current data. Review the query for any future additions to the input tables.

When you validate a query, the migration agent updates its status from the result. A passing validation sets it to **Translated** or **No translation needed**, and a failed validation or a failed check sets it to **Needs review**. In the query editor, the **Translation status** column shows the validation result instead, such as **Validated** or **Failed**. Before you move a query, **validate it, or check its results with your own data quality checks**.

The **Column datatype** check compares the type of each column by type family:
+ Types in the same family pass, for example `bigint` and `HUGEINT`.
+ Types in different families fail, for example `bigint` and `DECIMAL(38,0)`.

The following table lists the type families.


| Type family | Engine version 3 types | DuckDB types | 
| --- | --- | --- | 
| Integer | tinyint, smallint, integer, bigint | TINYINT, SMALLINT, INTEGER, BIGINT, HUGEINT, UTINYINT, USMALLINT, UINTEGER, UBIGINT, UHUGEINT | 
| Floating point | real, double | FLOAT, DOUBLE | 
| Decimal | decimal | DECIMAL, NUMERIC | 
| String | varchar, char, json | VARCHAR, CHAR, JSON | 
| Boolean | boolean | BOOLEAN | 
| Date | date | DATE | 
| Time | time | TIME | 
| Time with time zone | time with time zone | TIME WITH TIME ZONE | 
| Timestamp | timestamp | TIMESTAMP, TIMESTAMP\_S, TIMESTAMP\_MS, TIMESTAMP\_NS | 
| Timestamp with time zone | timestamp with time zone | TIMESTAMP WITH TIME ZONE | 
| Interval | interval year to month, interval day to second | INTERVAL | 
| Binary | varbinary | BLOB | 
| UUID | uuid | UUID | 
| Array | array | List types, such as INTEGER[] | 
| Map | map | MAP | 
| Struct | row | STRUCT | 

If you validated a query with the same structure before, the migration agent applies that earlier result, and the change summary says so.

If validation can't finish, the tab shows **Validation failed** with the reason. If a check fails, edit the query and validate it again, using the **Change summary** to see what the migration agent changed. To find a result later, choose the query on the **Recent queries** tab.

## View the compatibility result with the API
<a name="athena-duckdb-migration-agent-validate-api"></a>

To read the result of a validation, call the [GetQueryExecution](https://docs.aws.amazon.com/athena/latest/APIReference/API_GetQueryExecution.html) or [BatchGetQueryExecution](https://docs.aws.amazon.com/athena/latest/APIReference/API_BatchGetQueryExecution.html) API operation. For each query that the migration agent translated, the `QueryExecution` object in the response includes a `CompatibilityResult` object.

The `CompatibilityResult` object contains the following fields.

`Id`  
The ID of the translation, in the form `t-{{uuid}}`.  
Type: String

`TargetQuery`  
The translated query. Empty when `Status` is `FAILED`.  
Type: String

`Status`  
The status of the translation, and of the validation if one ran. A query whose `Confidence` is `TRANSLATION_NEEDS_REVIEW` can still have the status `SUCCEEDED`.  
Type: String  
Valid values: `SUCCEEDED` \| `FAILED`

`Confidence`  
How well the query translated. For more information, see [Assess a workgroup for DuckDB compatibility](duckdb-migration-agent-assess.md).  
Type: String  
Valid values: `NO_TRANSLATION_NEEDED` \| `TRANSLATED_TO_TARGET_DIALECT` \| `TRANSLATION_NEEDS_REVIEW`

`ResultSummary`  
A JSON-formatted summary of the translation and validation. Parse it, and then read its `Summary` field for the list of changes.  
Type: String

`SourceQueryExecutionId`  
The ID of an earlier query execution whose translation the migration agent reused for this query, if any.  
Type: String

`TargetQueryExecutionId`  
The ID of the query execution that ran the translated query on DuckDB during validation.  
Type: String

`TargetQueryExecutionAttempts`  
The IDs of all the query executions that the migration agent ran to validate the translated query. Present only when the query was validated.  
Type: Array of strings

A query execution has no `CompatibilityResult` if the setting was off when it ran, if the query failed, or if the translation hasn't finished. To see `CompatibilityResult`, use a client version that includes the updated Athena API model. See [Regions and availability](duckdb-availability.md).