Skip to content

ICEBERG - OPTIMIZE FOR HIDDEN PARTITIONS

0

Hello. OPTIMIZE command has a ability to run against specific partitions only:

OPTIMIZE [db_name.]table_name REWRITE DATA USING BIN_PACK
  [WHERE predicate]

MY Iceberg Table has hidden partitioning with truncate function: PARTITIONED BY (col1, truncate(1000, col2)) How can run OPTMIZE for specific partition only? I tried running:

OPTIMIZE Table REWRITE DATA USING BIN_PACK 
WHERE col1='value' and col2=169000
OPTIMIZE Table REWRITE DATA USING BIN_PACK 
WHERE col1='value' and truncate(1000, col2)=169000

Both fail with:

GENERIC_INTERNAL_ERROR: Unexpected FilterNode found in plan; probably connector was not able to handle provided WHERE expression. You may need to manually clean the data at location 's3://aws-athena-query-results-.......' before retrying. Athena will not delete data in your account.

Athena engine version 3

FYI: SHOW CREATE TABLE Table; output is

CREATE TABLE  [db_name.]Table(
  col1 string,
  col2 int,
  ...)
PARTITIONED BY (`col1`, truncate(1000, `col2`))
LOCATION 's3://....'
TBLPROPERTIES (
  'table_type'='iceberg',
  'write_compression'='snappy',
  'format'='parquet'
);

UPDATE:

OPTIMIZE Table REWRITE DATA USING BIN_PACK 
WHERE col1='value' AND col2 >= 169000 AND col2 < 170000

Doesn't work either with same error.

asked 2 years ago1.2K views

2 Answers
0

The issue you're encountering is related to how Athena handles hidden partitions in Iceberg tables when using the OPTIMIZE command. When you use hidden partitioning with a transform function like truncate, Athena doesn't directly expose these partitions in the same way as regular partitions.

For Iceberg tables with hidden partitioning, the OPTIMIZE command doesn't support filtering on the transformed partition columns directly. The WHERE clause in the OPTIMIZE command is meant to work with visible partition columns or data columns, not the hidden partition values created by transform functions.

To work around this limitation, you can try the following approach:

  1. Instead of using the transformed column in the WHERE clause, use the original column with a range that corresponds to the hidden partition you want to optimize. For example:
OPTIMIZE Table REWRITE DATA USING BIN_PACK 
WHERE col1='value' AND col2 >= 169000 AND col2 < 170000

This will target the specific partition you're interested in (169000) without directly referencing the hidden partition column.

  1. If you need to optimize multiple specific partitions, you can use OR conditions to include them:
OPTIMIZE Table REWRITE DATA USING BIN_PACK 
WHERE col1='value' AND 
((col2 >= 169000 AND col2 < 170000) OR 
 (col2 >= 170000 AND col2 < 171000))
  1. If you need to optimize a large number of partitions, you might need to run multiple OPTIMIZE commands, each targeting a subset of partitions.

Remember that while this approach doesn't directly reference the hidden partition column, it should effectively target the data within the desired partitions. However, be aware that this method might not be as efficient as directly specifying partitions in tables with visible partitioning.

If you continue to experience issues or if this approach doesn't meet your needs, you may need to consider restructuring your table to use visible partitions instead of hidden partitions, or consult with AWS support for more specific guidance on optimizing Iceberg tables with hidden partitions in Athena.
Sources
Optimize Iceberg tables - Amazon Athena
Troubleshoot Athena Apache Iceberg table errors | AWS re:Post

answered 2 years ago

AWS
SUPPORT ENGINEER

reviewed 2 years ago

  • I tried running:

    OPTIMIZE Table REWRITE DATA USING BIN_PACK 
    WHERE col1='value' AND col2 >= 169000 AND col2 < 170000
    

    But still same error: GENERIC_INTERNAL_ERROR: Unexpected FilterNode found in plan; probably connector was not able to handle provided WHERE expression. simply running

    OPTIMIZE Table REWRITE DATA USING BIN_PACK 
    WHERE col1='value'
    

    works fine

0

Unfortunatelly above solution doesnt work. Seems there is a bug.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.