- Newest
- Most votes
- Most comments
I wasnt able to do this via Athena nor by Spark.sql's CREATE Table DDL.Only thing that worked is the Alter table
spark.sql("ALTER TABLE glue_catalog.develop.daily_salesWRITE ORDERED BY sale_date ASC")
Please refer to https://aws.amazon.com/blogs/aws/new-improve-apache-iceberg-query-performance-in-amazon-s3-with-sort-and-z-order-compaction/
answered 10 months ago
As far as I can tell, you have to do this in spark. something like spark.sql("ALTER TABLE db.tbl WRITE ORDERED BY event_date DESC")
The documentation for this is currently really inaccurate unfortunately.
answered 9 months ago
Today this can be done at creation or after using the CLI or API: https://aws.amazon.com/about-aws/whats-new/2026/02/s3-tables-partition-and-sort-order-createtable-api/ https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-maintenance.html
If your workflow requires the ability to set this with Athena, please comment with your use case to help us prioritise. Thank you
To set a sort order on an S3 Tables Iceberg table for sort or z-order compaction, you need to define a sort order in your Iceberg table properties first, which is a prerequisite for both compaction strategies.
For Apache Iceberg tables, you can define the sort order using the following SQL command:
ALTER TABLE glue_catalog.develop.daily_sales SET TBLPROPERTIES ( 'sort_order'='sale_date ASC' )
Alternatively, you can define the sort order at table creation time:
CREATE TABLE develop.daily_sales ( sale_date date, product_category string, sales_amount double ) PARTITIONED BY (month(sale_date)) TBLPROPERTIES ( 'table_type' = 'iceberg', 'sort_order' = 'sale_date ASC' );
After defining the sort order in your table properties, you can enable the appropriate compaction strategy:
-
For S3 Tables, if a table has a defined sort order, the
sortcompaction strategy is automatically applied during ongoing maintenance without additional configuration. -
To use
z-ordercompaction, you need to update the table maintenance configuration using the S3 Tables API and set the strategy toz-order.
For Iceberg tables in general purpose S3 buckets, you can configure AWS Glue Data Catalog to use either sort or z-order compaction during optimization by updating the compaction settings in the AWS Glue Data Catalog console.
Note that to set the compaction strategy to sort or z-order, you need the s3tables:GetTableData permission in addition to having a defined sort order in your table properties.
Sources
New: Improve Apache Iceberg query performance in Amazon S3 with sort and z-order compaction | AWS News Blog
Amazon S3 now supports sort and z-order compaction for Apache Iceberg tables - AWS
Maintenance for tables - Amazon Simple Storage Service
answered 10 months ago
Athena doesn't support CREATE_TABLE with sort for Iceberg.
CREATE TABLE develop.daily_sales (
sale_date date,
product_category string,
sales_amount double
)
PARTITIONED BY (month(sale_date))
WITH (
table_type = 'ICEBERG'
);
Instead, you can partition the table using desired column and sort the results while running the query.
SELECT *
FROM develop.daily_sales
ORDER BY sale_date;
Refer: https://repost.aws/questions/QUhDaLJyIIQ0C983MBpZ51Cg/athena-iceberg-sorted-tables
The table is already partitioned on the required columns (PARTITIONED BY (hour(created_at), type)).
My question is specifically about using Iceberg compaction and file sorting (as described in the AWS blog) to organize data and reduce scan size and query execution time. Query-time ORDER BY does not address this requirement.
Specifically asking about leveraging s3 tables's compaction and file sort capabilities, to help organize your data more efficiently
please review this post: https://aws.amazon.com/blogs/aws/new-improve-apache-iceberg-query-performance-in-amazon-s3-with-sort-and-z-order-compaction/
You can now use sort and z-order compaction to improve Apache Iceberg query performance in Amazon S3 Tables and general purpose S3 buckets. Two new compaction strategies: Sort and z-order To help organize your data more efficiently, Amazon S3 now supports two new compaction strategies: sort and z-order, in addition to the default binpack compaction. These advanced strategies are available for both fully managed S3 Tables and Iceberg tables in general purpose S3 buckets through AWS Glue Data Catalog optimizations.
Relevant content
asked 2 years ago
asked 2 years ago
asked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 4 months ago

CREATE TABLE develop.daily_sales ( sale_date date, product_category string, sales_amount double ) PARTITIONED BY (month(sale_date)) TBLPROPERTIES ( 'table_type' = 'iceberg', 'sort_order' = 'sale_date ASC' );