feat(plugin-iceberg): Support top-level Iceberg V3 unknown type #28671
<!-- Generated by sourcery-ai[bot]: start review_guide -->
Reviewer's Guide
API
Add a connector capability that lets the engine distinguish connectors that support UNKNOWN columns.
presto-spi/src/main/java/com/facebook/presto/spi/connector/ConnectorCapabilities.java L25-30Uses of the API
Use the new capability to gate UNKNOWN columns in CREATE TABLE, ADD COLUMN, and CTAS, and plan NULL values for UNKNOWN outputs.
presto-main-base/src/main/java/com/facebook/presto/execution/AddColumnTask.java L52, L126-131presto-main-base/src/main/java/com/facebook/presto/execution/CreateTableTask.java L69, L144-150presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java L1621-1625, L1644-1653 (+5 small edits)presto-main-base/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java L123, L789-793presto-main-base/src/main/java/com/facebook/presto/sql/planner/QueryPlanner.java L141, L927, L1173-1181Implementation
Implement Iceberg UNKNOWN schema validation, V3 DDL handling, write constraints, and schema-evolution checks for the shared metadata path.
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java L446-472, L763-780, L1853-1858 (+3 small edits)presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java L376, L419-421presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergNativeMetadata.java L451, L461-463presto-iceberg/src/main/java/com/facebook/presto/iceberg/UnknownUtils.java L1-85Translate UNKNOWN between Iceberg, Presto, and Hive representations, and handle its partition/default metadata semantics.
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergPageSourceProvider.java L133, L482-484, L1233presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java L576-581, L1248-1251 (+3 small edits)presto-iceberg/src/main/java/com/facebook/presto/iceberg/TypeConverter.java L147-152, L440-446 (+3 small edits)Exclude top-level UNKNOWN columns from physical writers and provide a placeholder type for sort-spill files.
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergFileWriterFactory.java L127-134, L148-154, L276-287 (+8 small edits)presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergPageSink.java L75, L188-193, L613-620Teach the native Iceberg and Hive type converters to dispatch UNKNOWN types and preserve their field-name conversion behavior.
presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp L230presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnectorUtils.cpp L637-638, L889Validate UNKNOWN schemas before data-file rewrites so unsupported or zero-column rewrites fail rather than silently losing fields.
presto-iceberg/src/main/java/com/facebook/presto/iceberg/procedure/RewriteDataFilesProcedure.java L29, L223-226Configuration
Advertise UNKNOWN-column support from the Iceberg connector so engine-level DDL gates allow it.
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergConnector.java L50, L122Documentation
Document Iceberg V3 UNKNOWN-column support and its usage and limitations.
presto-docs/src/main/sphinx/connector/iceberg.rst L3320-3321, L3411-3412, L3417-3469Tests
Exercise Java Iceberg UNKNOWN-column DDL, reads, writes, planning, schema evolution, metadata, and unsupported cases.
presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergV3.java L986-1054, L1073-1236, L1292-1461 (+10 small edits)Verify interoperability with externally generated Iceberg tables and UNKNOWN-column behavior in Hive catalog DDL.
presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestUnknownColumnRead.java L1-99presto-iceberg/src/test/java/com/facebook/presto/iceberg/hive/TestIcebergSmokeHive.java L592-626presto-iceberg/src/test/resources/iceberg_v3/unknown_column/metadata/v1.metadata.json L1presto-iceberg/src/test/resources/iceberg_v3/unknown_column/data/00003-3-73d5357f-f3cd-443c-b64c-2b19492129a5-0-00001.parquetpresto-iceberg/src/test/resources/iceberg_v3/unknown_column/data/00006-6-73d5357f-f3cd-443c-b64c-2b19492129a5-0-00001.parquetpresto-iceberg/src/test/resources/iceberg_v3/unknown_column/data/00009-9-73d5357f-f3cd-443c-b64c-2b19492129a5-0-00001.parquetpresto-iceberg/src/test/resources/iceberg_v3/unknown_column/metadata/854b0ad5-6c71-46c1-91fc-8775d2bc9312-m0.avropresto-iceberg/src/test/resources/iceberg_v3/unknown_column/metadata/snap-7013766561753926116-1-854b0ad5-6c71-46c1-91fc-8775d2bc9312.avroCover UNKNOWN-column data-file rewriting on Java and native workers.
presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestRewriteDataFilesProcedure.java L1973-1996presto-native-execution/src/test/java/com/facebook/presto/nativeworker/iceberg/AbstractTestRewriteDataFilesProcedure.java L542-566Verify native-worker UNKNOWN-column reads, writes, query semantics, CTAS, metadata, and failure cases.
presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestPrestoNativeIcebergUnknownType.java L1-265Exercise UNKNOWN-column MERGE planning on native workers.
presto-native-tests/src/test/java/com/facebook/presto/nativetests/iceberg/AbstractTestNativeIcebergV3Dml.java L147-170Check that connectors without UNKNOWN-column capability reject UNKNOWN DDL and CTAS.
presto-tests/src/test/java/com/facebook/presto/tests/TestBlackHoleSmoke.java L353-374---
<details>
<summary>Tips and commands</summary>
Interacting with Sourcery
@sourcery-ai review on the pull request.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.@sourcery-ai anywhere in the pullrequest 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.@sourcery-ai summary anywhere inthe 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.
@sourcery-ai guide on the pullrequest to (re-)generate the reviewer's guide at any time.
@sourcery-ai resolve on thepull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore.
@sourcery-ai dismiss on the pullrequest 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:
summary, the reviewer's guide, and others.
Getting Help
</details>
<!-- Generated by sourcery-ai[bot]: end review_guide -->
``ROW``, ``ARRAY``, or ``MAP`` (for example, ``ROW(url VARCHAR, extra UNKNOWN)``) is not yet
Avoid Latin abbreviations. See the GitLab documentation style guide recommended word list entry for e.g. for discussion and alternatives.
view's query (for instance, ``SELECT id, CAST(NULL AS INTEGER) AS x FROM t``).
Avoid Latin abbreviations. See the GitLab documentation style guide recommended word list entry for e.g. for discussion and alternatives.
* Promoting an ``unknown`` column to a concrete type, such as ``ALTER TABLE ... ALTER COLUMN ... SET DATA TYPE``,
Avoid Latin abbreviations. See the GitLab documentation style guide recommended word list entry for e.g. for discussion and alternatives.
* **Note:** tables that contain an ``unknown`` column cannot be read by Presto versions
that predate rollback. Drop any ``unknown`` columns before rolling back a cluster.
As a suggestion, move the action you want the user to do to the beginning of the paragraph and follow the action with the explanation, like this:
Avoid adding unknown columns to tables in shared Hive metastore deployments. When using the HIVE catalog type, other Iceberg engines such as Spark or Flink cannot commit to a table that contains an unknown column, because Iceberg’s Hive metastore schema converter does not support the unknown type. This includes INSERT, expire_snapshots, rewrite_data_files, and rewrite_manifests.
Thank you for the documentation! Just a few notes.
@steveburnett Thanks for the review on the documentation. Comments addressed.
LGTM! (docs)
Pull updated branch, new local doc build, looks good. Thank you!
@mohsaka : What are the technical limitations because of which this isn't implemented in C++ ? Please can you scope them out.
For this PR specifically, the HiveTypeParser changes from here
https://github.com/facebookincubator/velox/pull/18775
As well as a few Prestissimo changes.
I see. We should be able to finalize and merge that PR. So there isn't any blocking issue as such. Thanks.
@aditi-pandit Velox PR opened here: https://github.com/facebookincubator/velox/pull/19685
Thanks @mohsaka. Had some nits and test suggestions.
1) Commit message is inaccurate in three places:
- "IcebergPageSourceProvider injects a NULL block for UNKNOWN columns": it doesn't. Nulls come from the missing-column path, and this file only changes predicate and default-value handling.
- "RewriteDataFilesProcedure rejects tables with UNKNOWN columns": it only rejects all-unknown tables or nested unknown.
- "LogicalPlanner/QueryPlanner emit bare NULLs": correct, but nullValueOfType exists only in QueryPlanner. testCtasWithUnknownColumn's comment also points to LogicalPlanner.nullValueOfType, which doesn't exist.
2) Add a release note to say "Iceberg supports Unknown columns write and read".
3) Add an engine-level test that a non-Iceberg connector without the capability still rejects CREATE TABLE (x UNKNOWN) and CTAS SELECT NULL x, e.g. with Hive or memory.
@unidevel imported this issue as lakehouse/presto #6627
It reads quite odd that finishCreateTable calls finishInsert table. If createTable allows for an all UNKNOWN table, then the validation logic doesn't belong to finishCreateTable.
This logic is repeated. Please abstract a common function for it.
Why did you add this ? Seems unrelated no ?
Why is initial default value of UNKNOWN not NULL ?
Nit : Maybe rename this to UnknownUtils ?
Refactored out the logic to prevent usage of finishInsert code to bypass.
Combined into validateUnknownColumnType
These tests were added because we need to make sure that UNKNOWN columns are rejected by connectors that have not been set up to support the UNKNOWN column type.
Actually you are right, it should be NULL, which is what deserializeIcebergValue returns for it. Removed the if case.
Renamed. Thanks!
why is this code in a try block ?
Why is this code in a try block ?
@mohsaka : Thanks for this code. It looks good.
Had a question in general. Several of the tests have a try block around a set of assertQuery... or assertQuerySucceeds calls. Why is it needed ?
Both this one and the other one are in try finally blocks to make sure that the table is at least attempted to be dropped after the execution of the test case. Either when it fails or succeeds.
Both this one and the other one are in try finally blocks to make sure that the table is at least attempted to be dropped after the execution of the test case. Either when it fails or succeeds.
@mohsaka : Thanks for this code. It looks good.
> Had a question in general. Several of the tests have a try block around a set of assertQuery... or assertQuerySucceeds calls. Why is it needed ?
@mohsaka : We've usually written tests with DROP IF EXISTS... CREATE TABLE... other SQL... DROP TABLE statements in sequence. So its possible that a table is not dropped if a certain statement fails. Though that was considered okay to aid debugging. I'm concerned that the try... catch block will catch failures that should be diagnosed.
Lets remove the blocks and be consistent with other tests.
> @mohsaka : Thanks for this code. It looks good.
> Had a question in general. Several of the tests have a try block around a set of assertQuery... or assertQuerySucceeds calls. Why is it needed ?
> @mohsaka : We've usually written tests with DROP IF EXISTS... CREATE TABLE... other SQL... DROP TABLE statements in sequence. So its possible that a table is not dropped if a certain statement fails. Though that was considered okay to aid debugging. I'm concerned that the try... catch block will catch failures that should be diagnosed.
> Lets remove the blocks and be consistent with other tests.
@aditi-pandit No problem! Removed all the try-finally, and placed the drops in line with the other statements.
Seems like this is supported for native engine now. Please can you fix the comment.
Removed "
worker cannot currently create or write tables with `
unknown` columns."I can verify that the updated PR has this comment removed in a local doc build.
LGTM! (docs)
Pull updated branch, new local doc build, looks good. Thank you!
Thanks @mohsaka. You can address them in a subsequent PR.
I have 2 tests comments
i. No test for QueryPlanner.nullValueOfType. The MERGE change is only reachable on native, because Java rejects MERGE on V3, and no test does MERGE or UPDATE on a table with an unknown column.
ii. No test for rewrite_data_files on a table with a top-level unknown column. The behaviour and the description disagree (see above), so a test would settle which is right.
Thanks @mohsaka
Failed to update imported issue:
Patch "https://github.ibm.com/api/v3/repos/lakehouse/presto/issues/6627": dial tcp 9.209.58.192:443: i/o timeout
aditi-pandit
mohsaka
Description
Split off from https://github.com/prestodb/presto/pull/28498, due to complexities of nested types. Individual PR's will be opened for MAP, ROW, and ARRAY support.
Adds support for reading and writing top-level Iceberg V3
unknowntype columns in the Java connector. Anunknowncolumn always holdsNULL; it is never stored in data files and always reads back asNULL.DDL support (CREATE TABLE / ADD COLUMN / CREATE TABLE AS SELECT):
SUPPORTS_UNKNOWN_COLUMN_TYPEconnector capability gates DDL inCreateTableTask,AddColumnTask, andStatementAnalyzer. The Iceberg connector advertises this capability.ALTER TABLE ADD COLUMN ... UNKNOWNis accepted at top level; adding anunknownfield nested inside aROW,ARRAY, orMAP(viaADD COLUMN parent.field) is always rejected.IcebergAbstractMetadata.validateUnknownColumnsForCreateTablehelper.Write path:
UnknownFields.fileSchema(Schema)strips top-levelunknowncolumns from the schema written to Parquet/ORC data files.IcebergFileWriterFactoryusesfileSchemawhen constructing the file writer, so data files contain only concrete columns.UnknownFields.validateWritable(Schema)rejects writes when the resulting file schema would be empty (see "All-unknown table" section below).LogicalPlannerandQueryPlannerreplaceunknownoutput columns withNULLliterals so the engine never tries to encode anunknownvalue.unknownwithBOOLEANas a placeholder, since Presto'sOrcType.toOrcTypedoes not handleunknown— the values are alwaysNULLso the placeholder type has no semantic effect.RewriteDataFilesProcedureskips tables withunknowncolumns (rewrite would silently drop them; the restriction can be lifted when the procedure is made aware offileSchema).Read path:
IcebergPageSourceProviderinjects aNULLblock for anyunknowncolumn rather than attempting to read it from the data file.TypeConvertermaps IcebergUnknownTypeto PrestoUnknownType.IcebergUtil.deserializeIcebergValueshort-circuits forunknownto avoid a spurious "Invalid partition type" error.All-unknown table INSERT is rejected:
If a table's schema consists entirely of
unknowncolumns, stripping them from the file schema produces a zero-columnMessageType. Both parquet-mr and Iceberg Java reject this:ParquetFileWriterconstructor):InvalidSchemaException: Cannot write a schema with an empty groupParquetWriter.ensureWriterInitialized): hits the same parquet-mr exception on the first non-empty flushPresto matches this behavior.
validateWritablethrowsNOT_SUPPORTEDbefore any I/O:A table with at least one non-
unknowncolumn writes and reads normally:Limitations (this PR — top-level only):
unknownnested insideROW,ARRAY, orMAPis not yet supported on the write path and is rejected. Read support for pre-existing nestedunknowncolumns (written by other engines) is added in a follow-up PR.unknowncolumns should be avoided. Presto'sDROP COLUMNrejects any column referenced by any partition spec (including historical ones), so a table partitioned on anunknowncolumn can never have that column dropped, making cluster rollback impossible.HIVEcatalog type): other Iceberg engines (Spark, Flink) cannot commit to a table that contains anunknowncolumn, because Iceberg's Hive metastore schema converter does not support theunknowntype. Avoid addingunknowncolumns to tables in shared Hive Metastore deployments.Motivation and Context
Iceberg Format Version 3 introduces the
unknowntype (spec §4.7). Tables written by other Iceberg engines (Spark, Flink) may containunknowncolumns, and Presto must be able to read them. This PR enables Presto to participate in those workflows and to create V3 tables withunknowncolumns of its own.Impact
User-facing changes:
CREATE TABLE,ALTER TABLE ADD COLUMN, andCTASnow acceptUNKNOWNas a column type on Iceberg V3 tables.unknowncolumn (written by any Iceberg engine) returnsNULLfor that column instead of failing.INSERTinto a table with anunknowncolumn works; the column must beNULLor omitted.INSERTinto a table where every column isUNKNOWNis rejected with a clear error (consistent with parquet-mr and Iceberg Java behavior).Rollback note: a table that contains an
unknowncolumn cannot be read by Presto versions that predate this feature. Drop anyunknowncolumns before rolling back a cluster. Rolling back while anyunknown-column table exists causesinformation_schema.columnsand JDBCgetColumnsto fail for the entire schema containing that table (and for the whole catalog on unfiltered listings). Use the following query to find all affected tables before rolling back:Test Plan
TestIcebergV3— end-to-end tests for the new functionality:-
testReadUnknownColumn(PARQUET, ORC) — reads a pre-existing table fixture written with anunknowncolumn.-
testWriteUnknownColumn(PARQUET, ORC) — CREATE + INSERT + SELECT round-trip with a mixed table.-
testWriteTableOfOnlyUnknownColumns(PARQUET, ORC) — verifies that INSERT into an all-unknown table is rejected withNOT_SUPPORTED.-
testDropLastNonUnknownColumnRejectsWrite— drops the last non-unknown column then confirms INSERT is rejected.-
testAddColumnToAllUnknownTableRestoresWritability— confirmsALTER TABLE ADD COLUMNon an all-unknown table succeeds and subsequent INSERT works.-
testUnknownColumnWithSort— exercises the sort-spill ORC placeholder path.-
testAddFieldUnknownRejected— confirms thatADD COLUMN parent.nested_field UNKNOWNis rejected.-
testUnknownColumnPredicates,testUnknownColumnScalarFunctions— query semantics.TestUnknownColumnRead— reads a real Iceberg table fixture (Parquet files + Avro manifest) generated by an external Iceberg engine.TestIcebergSmokeHive.testUnknownColumnDDLHiveCatalog— smoke test for the Hive catalog DDL path.Contributor checklist
Release Notes
Summary by Sourcery
Support top-level Iceberg V3 UNKNOWN columns in the Java connector while keeping them virtual, always NULL, and excluded from physical data files.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: