View a markdown version of this page

Validate translated queries - Amazon Athena

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

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

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

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

  4. 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.

Read the results

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 familyEngine version 3 typesDuckDB types
Integertinyint, smallint, integer, bigintTINYINT, SMALLINT, INTEGER, BIGINT, HUGEINT, UTINYINT, USMALLINT, UINTEGER, UBIGINT, UHUGEINT
Floating pointreal, doubleFLOAT, DOUBLE
DecimaldecimalDECIMAL, NUMERIC
Stringvarchar, char, jsonVARCHAR, CHAR, JSON
BooleanbooleanBOOLEAN
DatedateDATE
TimetimeTIME
Time with time zonetime with time zoneTIME WITH TIME ZONE
TimestamptimestampTIMESTAMP, TIMESTAMP_S, TIMESTAMP_MS, TIMESTAMP_NS
Timestamp with time zonetimestamp with time zoneTIMESTAMP WITH TIME ZONE
Intervalinterval year to month, interval day to secondINTERVAL
BinaryvarbinaryBLOB
UUIDuuidUUID
ArrayarrayList types, such as INTEGER[]
MapmapMAP
StructrowSTRUCT

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

To read the result of a validation, call the GetQueryExecution or BatchGetQueryExecution 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.

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.