View a markdown version of this page

Troubleshooting - Amazon Athena

Troubleshooting

How Athena reports errors

When you submit a query, Athena checks the request (query length and API parameters) but not the SQL. If your query has a syntax error, Athena accepts it, returns an execution ID, and then fails the query when it runs. Wait until the query reaches a final state, then read Status.AthenaError (which contains ErrorCategory, ErrorType, Retryable, and ErrorMessage) and Status.StateChangeReason.

  • Errors in Athena have ErrorCategory 1. For these errors, ErrorMessage is a general message. Use ErrorType to find the cause. For example, ErrorType 1 means that Athena ran out of memory while it ran the query.

  • Errors in your query, data, table, or permissions have ErrorCategory 2. For most of these errors, ErrorMessage explains the cause. For example, it can name a syntax error, a table that doesn't exist, or a statement that isn't supported.

Error messages use the wording from DuckDB. These messages differ from engine version 3 messages. Use ErrorCategory and ErrorType where you can. For the values that DuckDB returns, see Athena error catalog. Athena does not automatically retry queries that fail with a timeout, a transient error, or out-of-memory.

Check before you retry a write

If Athena loses contact with a running query, it fails with a transient-error message, and the statement may already have been applied. Before you retry INSERT, CTAS, UPDATE, DELETE, or a DDL statement, query for the rows it would have written, or list the newest Iceberg snapshots with iceberg_snapshots and compare their timestamps.

Reduce memory use

A query fails when it needs more resources than are available to it. The query shapes most likely to run out of memory are large unbounded sorts, GROUP BY with very many groups, several COUNT(DISTINCT ...) in one query, window functions over all rows, and large self-joins. To reduce memory use, add LIMIT when you sort, filter and project early, aggregate in a WITH clause before joining, compute distinct counts in separate queries, and split a large export into one statement per key range.

DuckDB query timeout errors

This section explains how to find out which timeout caused a query to fail and how to resolve it.

Timeouts are most common when you run long queries on large tables, or when your account submits many queries at the same time. A query on DuckDB fails with a timeout error if it waits in the queue for more than 30 minutes or runs for more than 60 minutes. For more information about these limits, see Query timeouts.

To find out which timeout applied, call GetQueryExecution and compare Statistics.QueryQueueTimeInMillis with Statistics.EngineExecutionTimeInMillis.

Depending on which timeout applied, take one of the following actions:

  • If the query timed out in the queue, it did not get compute capacity in time. Submit the query again. If you submit many queries at once, spread them out or run fewer at the same time.

  • If the query timed out while it was running, reduce the work that it does. Filter on partition columns, select only the columns that you need, and split large exports or INSERT statements into smaller ranges.

Athena does not retry timed-out queries automatically. For instructions on checking a write before you retry it, see Check before you retry a write.

Access denied when creating the service-linked role

If CreateWorkGroup or UpdateWorkGroup fails with Access denied when calling CreateServiceLinkedRole operation, or StartQueryExecution fails with the error code SLR_CREATION_ACCESS_DENIED, the Athena service-linked role doesn't exist in your account and your principal can't create it. Add permission for iam:CreateServiceLinkedRole to the principal, or ask an administrator to run aws iam create-service-linked-role --aws-service-name ops.athena.amazonaws.com. Then retry the call. For more information, see Athena service-linked role.

Known issues

The following are known issues in this Preview:

  • Hive CSV tables written by this engine store NaN and positive or negative infinity as nan, inf, and -inf in DOUBLE or REAL columns. Engine version 3 and other Hive SerDe readers return NULL for these values without reporting an error. Use Parquet or Iceberg, or write the CSV table with engine version 3, when other engines must read these values. See Non-finite values in Hive CSV tables.

  • ORDER BY can return rows out of order when the result has more than 122,880 rows.

  • You can read and query VARIANT values, but a query result can't contain a VARIANT value. To return VARIANT data, cast it to JSON or VARCHAR in your SELECT statement, for example SELECT * REPLACE (v::JSON AS v).

  • StartQueryExecution can return HTTP status code 200 for invalid SQL syntax, rather than HTTP status code 400 as on Athena engine version 3. A query string that contains more than one statement (separated by ;) fails with InvalidRequestException (MALFORMED_QUERY) and the message Only one sql statement is allowed. Run each statement as a separate query.

  • When you validate a DuckDB query in the query editor of an Athena engine version 3 workgroup, you can't use a client-side override for the query result location. To continue to validate queries, update the workgroup to use an Amazon Simple Storage Service (Amazon S3) query result location.

  • The aggregated migration report comes from a one-time assessment of past queries in your Athena engine version 3 workgroup. The report is not updated frequently for queries that you run after the assessment.

  • When you use your own Amazon S3 bucket as the query result location, GetQueryResults supports only SELECT statements.

  • In Amazon Athena query metrics in Amazon CloudWatch, ProcessedBytes is always 0 for queries that run on DuckDB. To see how much data a query scanned, use Statistics.DataScannedInBytes in the GetQueryExecution API response.

  • Queries on a table with a very large number of partitions can run slowly and can fail with a timeout error. To plan a query, DuckDB retrieves the metadata for all of the table's partitions from the AWS Glue Data Catalog, so planning time and memory use grow with the table's total partition count rather than with the number of partitions the query selects.

  • Multi-node execution is limited to data in the Parquet format at this time.

  • If a workgroup uses a query result location in your own Amazon S3 bucket and has Assign bucket owner full control over query results enabled, a query whose results are larger than 5 MB fails when it writes the results. To avoid this, use managed query results for the workgroup.

Iceberg reads

The following known issues affect reading Iceberg tables:

  • Tables whose manifests are zstd-compressed fail to load

  • A table fails to load if any old spec or sort order uses an unknown transform.

  • A V3 table fails to load when a struct, list or map column has a non-null default.

  • Reading a V3 unknown column fails when a data file contains its field.

  • An unfiltered LIMIT query runs out of memory on tables with very many manifests.

  • SELECT DISTINCT filename over iceberg_scan crashes.

  • allow_moved_paths fails when the path contains spaces

  • On a Parquet table with nested structs, a filter on a nested field is pushed into the DuckDB Parquet scan and reads 100% of the partition. Athena engine version 3 reads 27% for the same query.

Iceberg writes

The following known issues affect writing to Iceberg tables:

  • Every INSERT fails when compression-level is set with gzip or brotli.

  • Row-group, object-storage layout, delete-file, per-column stats and bloom, distribution-mode and WAP properties are ignored.

  • -0.0 and +0.0 are merged when both appear in one file or in a float identity partition.

Iceberg DDL statements

The following known issues affect DDL statements on Iceberg tables:

  • DuckDB accepts a non-null whole-STRUCT default, but writes the rows with NULL.

  • Renaming or dropping a column loses its per-column properties.

  • DuckDB accepts changes to a map key field, and these changes can make the table unreadable.

  • SET NOT NULL fails on a column that is already required.

  • DEFAULT now() gives every row the time of the ALTER.

  • Changing a V3 date column to timestamp breaks Spark reads. The change can also make DuckDB drop rows, and the default stays a date.