Skip to content

Conversation

PingLiuPing
Copy link
Contributor

@PingLiuPing PingLiuPing commented Oct 9, 2025

Description

Problem:
When setting iceberg.compression-codec=ZSTD (or LZ4) in iceberg.properties
and attempt to create a iceberg table with default file format, the system throws a cryptic error:
"NoSuchElementException: No value present" at IcebergUtil.populateTableProperties().

13:55:39 {"level":"error","benchmark_stage_id":"cleanup_sf100","query_file":"create-table/customer.sql","query_index":0,"cold_run":true,"sequence_no":0,"info_url":"https://xxxxxx.prestodb.dev/ui/query.html?20251009_125539_00038_24pui","query_id":"20251009_125539_00038_24pui","query_error":{"message":"No value present","error_code":65536,"error_name":"GENERIC_INTERNAL_ERROR","error_type":"INTERNAL_ERROR","retriable":false,"failure_info":{"type":"java.util.NoSuchElementException","message":"No value present","suppressed":[],"stack":["java.base/java.util.Optional.get(Optional.java:143)","com.facebook.presto.iceberg.IcebergUtil.populateTableProperties(IcebergUtil.java:1178)","com.facebook.presto.iceberg.IcebergHiveMetadata.beginCreateTable(IcebergHiveMetadata.java:385)","com.facebook.presto.iceberg.IcebergAbstractMetadata.createTable(IcebergAbstractMetadata.java:503)","com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorMetadata.createTable(ClassLoaderSafeConnectorMetadata.java:374)","com.facebook.presto.metadata.MetadataManager.createTable(MetadataManager.java:675)","com.facebook.presto.execution.CreateTableTask.internalExecute(CreateTableTask.java:229)","com.facebook.presto.execution.CreateTableTask.execute(CreateTableTask.java:96)","com.facebook.presto.execution.CreateTableTask.execute(CreateTableTask.java:78)","com.facebook.presto.execution.DDLDefinitionExecution.executeTask(DDLDefinitionExecution.java:67)","com.facebook.presto.execution.DataDefinitionExecution.start(DataDefinitionExecution.java:217)","com.facebook.presto.$gen.Presto_0_296_0d532be__0_296_202510071020_0d532be3____20251009_124343_1.run(Unknown Source)","com.facebook.presto.execution.SqlQueryManager.createQuery(SqlQueryManager.java:326)","com.facebook.presto.dispatcher.LocalDispatchQuery.lambda$startExecution$8(LocalDispatchQuery.java:210)","java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)","..."]}},"expected_row_count":1,"start_time":"2025-10-09T12:55:39Z","finish_time":"2025-10-09T12:55:39Z","duration_in_seconds":0.112960251,"time":"2025-10-09T12:55:39Z","message":"execution failed"}

The root case of this error message is ZSTD is a unsupported compression codec, and when executing this line

propertiesBuilder.put(PARQUET_COMPRESSION, getCompressionCodec(session).getParquetCompressionCodec().get().toString());,

For ZSTD and LZ4, getParquetCompressionCodec() returns Optional.empty() and calling .get() on empty Optional throws the confusing exception

Solution:
Added validation in IcebergUtil.populateTableProperties() to check codec
compatibility before calling .get() on Optional.

And also add unit tests to validate the compression codec.

Motivation and Context

Impact

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

If release note is NOT required, use:

== NO RELEASE NOTE ==

@PingLiuPing PingLiuPing requested review from a team, ZacBlanco and hantangwangd as code owners October 9, 2025 15:32
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Oct 9, 2025
@prestodb-ci prestodb-ci requested review from a team, ScrapCodes and aaneja and removed request for a team October 9, 2025 15:32
Copy link
Contributor

sourcery-ai bot commented Oct 9, 2025

Reviewer's Guide

This PR enhances error handling for unsupported compression codecs in Iceberg table creation by validating codec compatibility before accessing Optional values, replacing cryptic NoSuchElementExceptions with descriptive PrestoExceptions, and supplements the change with comprehensive unit tests.

Sequence diagram for improved error handling during Iceberg table creation

sequenceDiagram
participant "User"
participant "IcebergUtil.populateTableProperties()"
participant "HiveCompressionCodec"
participant "PrestoException"
User->>"IcebergUtil.populateTableProperties()": Create Iceberg table with compression codec
"IcebergUtil.populateTableProperties()"->>"HiveCompressionCodec": Check if codec is supported for file format
alt Codec supported
    "IcebergUtil.populateTableProperties()"->>"HiveCompressionCodec": Get compression codec value
    "IcebergUtil.populateTableProperties()"-->>User: Table created successfully
else Codec not supported
    "IcebergUtil.populateTableProperties()"->>"PrestoException": Throw descriptive error
    "IcebergUtil.populateTableProperties()"-->>User: Receive descriptive error message
end
Loading

File-Level Changes

Change Details Files
Add validation for unsupported compression codecs in table properties
  • Retrieve HiveCompressionCodec once before switch
  • Check isSupportedStorageFormat() before Optional.get() for PARQUET and ORC
  • Throw PrestoException with descriptive message when codec unsupported
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java
Add unit tests validating compression codec support and error messages
  • Test that creating tables with ZSTD/LZ4 for Parquet and ORC formats fails or succeeds as expected
  • Assert support flags in TestIcebergUtil for each codec and storage format
  • Verify presence or absence of Parquet compression codec Optional values
presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java
presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergUtil.java

Possibly linked issues

  • #N/A: The PR changes the error message from a vague 'NoSuchElementException' to a specific 'Compression codec not supported for Parquet format' when using ZSTD/LZ4, directly addressing the problem of unsupported codecs for Parquet format highlighted in the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java:1109-1107` </location>
<code_context>
         assertEquals(512, getTargetSplitSize(0, 512).toBytes());
     }
+
+    @Test
+    public void testCompressionCodecSupportForParquet()
+    {
+        assertThat(HiveCompressionCodec.NONE.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isTrue();
+        assertThat(HiveCompressionCodec.SNAPPY.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isTrue();
+        assertThat(HiveCompressionCodec.GZIP.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isTrue();
+
+        assertThat(HiveCompressionCodec.LZ4.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isFalse();
+        assertThat(HiveCompressionCodec.ZSTD.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isFalse();
+    }
+
+    @Test
</code_context>

<issue_to_address>
**suggestion (testing):** Missing test for case-insensitive codec values.

Add tests to confirm that codec values are correctly recognized regardless of case sensitivity.

Suggested implementation:

```java
    @Test
    public void testCompressionCodecSupportForParquet()
    {
        assertThat(HiveCompressionCodec.NONE.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isTrue();
        assertThat(HiveCompressionCodec.SNAPPY.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isTrue();
        assertThat(HiveCompressionCodec.GZIP.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isTrue();

        assertThat(HiveCompressionCodec.LZ4.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isFalse();
        assertThat(HiveCompressionCodec.ZSTD.isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isFalse();
    }

    @Test
    public void testCompressionCodecSupportForParquetCaseInsensitive()
    {
        // Case-insensitive checks for supported codecs
        assertThat(HiveCompressionCodec.valueOf("none".toUpperCase()).isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isTrue();
        assertThat(HiveCompressionCodec.valueOf("snappy".toUpperCase()).isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isTrue();
        assertThat(HiveCompressionCodec.valueOf("gzip".toUpperCase()).isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isTrue();

        assertThat(HiveCompressionCodec.valueOf("NONE")).isEqualTo(HiveCompressionCodec.NONE);
        assertThat(HiveCompressionCodec.valueOf("SnApPy".toUpperCase())).isEqualTo(HiveCompressionCodec.SNAPPY);
        assertThat(HiveCompressionCodec.valueOf("GZIP")).isEqualTo(HiveCompressionCodec.GZIP);

        // Case-insensitive checks for unsupported codecs
        assertThat(HiveCompressionCodec.valueOf("lz4".toUpperCase()).isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isFalse();
        assertThat(HiveCompressionCodec.valueOf("zstd".toUpperCase()).isSupportedStorageFormat(HiveStorageFormat.PARQUET)).isFalse;
    }

```

If `HiveCompressionCodec.valueOf()` does not handle case-insensitivity, you may need to implement a helper method or use a custom lookup to convert codec names to enum values in a case-insensitive way. Adjust the test accordingly if this is the case.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

assertEquals(512, getTargetSplitSize(0, 512).toBytes());
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a data provider for these to improve readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaneja Thanks.

if (compressionCodec.isSupportedStorageFormat(HiveStorageFormat.PARQUET)) {
propertiesBuilder.put(PARQUET_COMPRESSION, compressionCodec.getParquetCompressionCodec().get().toString());
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifying else explicitly here is redundant since we break right after. Consider inverting the if to make it a check-and-fail-if-not-supported flow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

}

@Test
public void testUnsupportedCompressionCodec()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a data provider for these to improve readability

Comment on lines 1126 to 1131
Session sessionWithLz4Orc = Session.builder(getSession())
.setCatalogSessionProperty("iceberg", "compression_codec", "LZ4")
.build();
assertQueryFails(sessionWithLz4Orc,
"CREATE TABLE test_unsupported_compression (x int) WITH (format = 'ORC')",
"Compression codec LZ4 is not supported for ORC format");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see, based on our current code logic, this statement will succeed. It seems a little weird but the compression codec will be set to NONE for the target Iceberg table.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, never mind. I just found you have invoke compressionCodec.isSupportedStorageFormat(HiveStorageFormat.ORC) to check and throw the exception.

@PingLiuPing PingLiuPing force-pushed the lp_fix_compression_codec branch from e866e90 to 4fb0995 Compare October 10, 2025 14:05
@PingLiuPing
Copy link
Contributor Author

@aaneja @hantangwangd Could you please have another look. Thanks.

Copy link
Member

@hantangwangd hantangwangd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix, lgtm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants