Skip to content

Fix OPTIMIZE failing with uppercase Iceberg column names#28888

Closed
kinolaev wants to merge 1 commit into
trinodb:masterfrom
kinolaev:fix-iceberg-optimize-lowercase-column-names
Closed

Fix OPTIMIZE failing with uppercase Iceberg column names#28888
kinolaev wants to merge 1 commit into
trinodb:masterfrom
kinolaev:fix-iceberg-optimize-lowercase-column-names

Conversation

@kinolaev
Copy link
Copy Markdown
Member

@kinolaev kinolaev commented Mar 26, 2026

Description

IcebergMetadata.getColumnHandles() stored data column handles with original-case keys from the Iceberg schema, but ColumnMetadata lowercases all names in its constructor. When getColumnHandlesForOptimize() (introduced in 480) looked up columns by their ColumnMetadata names, the case-insensitive lookup failed for tables with uppercase column names.

The fix lowercases the key in getColumnHandles() to match the convention already enforced by MetadataManager at the engine boundary, and to match what ColumnMetadata.getName() returns.

Release notes

## Iceberg
* Fix failure when column name contains uppercase characters in OPTIMIZE procedure. ({issue}`28888`)

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 26, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@github-actions github-actions Bot added jdbc Relates to Trino JDBC driver iceberg Iceberg connector labels Mar 26, 2026
@kinolaev kinolaev force-pushed the fix-iceberg-optimize-lowercase-column-names branch from 61d60cd to 1aca866 Compare March 26, 2026 16:14
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 26, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@findepi findepi requested a review from ebyhr March 26, 2026 19:55
@ebyhr ebyhr force-pushed the fix-iceberg-optimize-lowercase-column-names branch from 1aca866 to 989dfa3 Compare March 26, 2026 23:05
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 26, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Mar 26, 2026

@kinolaev Thanks for detecting this bug quickly. Have you already submitted CLA?

@ebyhr ebyhr removed the jdbc Relates to Trino JDBC driver label Mar 26, 2026
@kinolaev
Copy link
Copy Markdown
Member Author

Yes, around 16:30 utc

@ebyhr ebyhr requested a review from chenjian2664 March 27, 2026 02:47
@ebyhr ebyhr force-pushed the fix-iceberg-optimize-lowercase-column-names branch from 989dfa3 to c28b14b Compare March 27, 2026 02:56
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 27, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@chenjian2664
Copy link
Copy Markdown
Contributor

chenjian2664 commented Mar 30, 2026

IMO, update the getColumnHandles isn't ideally, it expand the scope - since analyzer and planner depends on the method, though I am not very strong about it.

Instead can we consider update getColumnHandlesForOptimize to get the schema directly, sth like:

                for (IcebergColumnHandle columnHandle : getTopLevelColumns(SchemaParser.fromJson(table.getTableSchemaJson()), typeManager)) {
                    columnHandles.add(columnHandle);
                }

                if (supportsRowLineage(((IcebergTableHandle) tableHandle).getFormatVersion())) {
                    columnHandles
                            .add(rowIdColumnHandle())
                            .add(lastUpdatedSequenceNumberColumnColumnHandle());
                }

cc @ebyhr @dain @findepi

@ebyhr ebyhr force-pushed the fix-iceberg-optimize-lowercase-column-names branch from c28b14b to 59a99dc Compare April 1, 2026 03:24
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 1, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

IcebergMetadata.getColumnHandles() stored data column handles with
original-case keys from the Iceberg schema, but ColumnMetadata
lowercases all names in its constructor. When getColumnHandlesForOptimize()
(introduced in 480) looked up columns by their ColumnMetadata names, the
case-insensitive lookup failed for tables with uppercase column names.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Sergei Nikolaev <kinolaev@gmail.com>
@ebyhr ebyhr force-pushed the fix-iceberg-optimize-lowercase-column-names branch from 59a99dc to ac34cb6 Compare April 1, 2026 03:27
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 1, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Apr 1, 2026

Perhaps, the default implementation of SPI has the same problem:

default Set<ColumnHandle> getColumnHandlesForTableExecute(ConnectorSession connectorSession, ConnectorTableHandle tableHandle, ConnectorTableExecuteHandle connectorTableExecuteHandle)
{
Map<String, ColumnHandle> columnHandles = getColumnHandles(connectorSession, tableHandle);
return getTableMetadata(connectorSession, tableHandle).getColumns().stream()
.filter(not(ColumnMetadata::isHidden))
.map(ColumnMetadata::getName)
.map(columnName -> {
ColumnHandle columnHandle = columnHandles.get(columnName);
if (columnHandle == null) {
throw new TrinoException(GENERIC_INTERNAL_ERROR, format("No handle found for column '%s' in table execute", columnName));
}
return columnHandle;
})
.collect(toUnmodifiableSet());
}

# spark
CREATE TABLE test (X int) USING delta LOCATION 's3://test-bucket/test';
INSERT INTO test VALUES 1;
INSERT INTO test VALUES 2;

# trino
ALTER TABLE test EXECUTE optimize;
No handle found for column 'x' in table execute

@findepi
Copy link
Copy Markdown
Member

findepi commented Apr 1, 2026

Perhaps, the default implementation of SPI has the same problem

@ebyhr can you please file an issue?
if this is a recent regression, this might need to be a release blocker 🤔

@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Apr 2, 2026

@findepi Sure, filed #28970 with a release blocker label.

@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Apr 2, 2026

Let me continue the work at #28972 because it requires more work. I added @kinolaev as the co-author.

@ebyhr ebyhr closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

iceberg Iceberg connector

Development

Successfully merging this pull request may close these issues.

4 participants