Skip to content

[#10750] feat(trino-connector): Support CTAS (CREATE TABLE AS SELECT)#10757

Open
laserninja wants to merge 1 commit intoapache:mainfrom
laserninja:feat/10750-ctas-support
Open

[#10750] feat(trino-connector): Support CTAS (CREATE TABLE AS SELECT)#10757
laserninja wants to merge 1 commit intoapache:mainfrom
laserninja:feat/10750-ctas-support

Conversation

@laserninja
Copy link
Copy Markdown
Collaborator

What changes were proposed in this pull request?

Support CTAS (CREATE TABLE AS SELECT) in the Gravitino Trino connector by
implementing beginCreateTable(), finishCreateTable(), and the associated
page sink provider and handle wrapper.

The key design choice is that beginCreateTable() first creates the table in
the Gravitino catalog, then delegates data writing to the internal connector's
beginInsert() path. This avoids double table creation in the original
connector.

Files changed:

  • GravitinoMetadata.javabeginCreateTable() creates table via Gravitino, then calls internalMetadata.beginInsert(); getNewTableLayout() delegates to internal
  • GravitinoOutputTableHandle.javanew handle wrapper that wraps ConnectorInsertTableHandle (implements ConnectorOutputTableHandle)
  • GravitinoMetadata{435,440,446,452,469,478}.java — version-specific finishCreateTable() delegating to finishInsert()
  • GravitinoPageSinkProvider.javacreatePageSink(OutputTableHandle) unwraps to insert handle and uses insert-path sink
  • JsonCodec.java — registered ConnectorOutputTableHandle in AbstractTypedJacksonModule for polymorphic serialization

Why are the changes needed?

CTAS is a standard SQL pattern commonly used during lakehouse migrations, ETL
development, and exploratory data work. Without it, users must use a two-step
CREATE TABLE + INSERT INTO pattern, which introduces a failure mode where
partial table registrations can be left behind if the insert fails.

Fix: #10750

Does this PR introduce any user-facing change?

Yes. Users can now execute CREATE TABLE ... AS SELECT queries through the
Gravitino Trino connector. Previously this returned:
This connector does not support creating tables with data.

How was this patch tested?

  • Added testCreateTableAsSelect test in TestGravitinoConnector
  • All existing tests pass across all 6 Trino SPI version modules (435–478)
  • Ran ./gradlew spotlessApply for formatting compliance

@laserninja laserninja marked this pull request as draft April 13, 2026 06:49
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 13, 2026

Code Coverage Report

Overall Project 65.15% -0.34% 🟢
Files changed 12.4% 🔴

Module Coverage
aliyun 1.73% 🔴
api 47.14% 🟢
authorization-common 85.96% 🟢
aws 1.1% 🔴
azure 2.6% 🔴
catalog-common 10.2% 🔴
catalog-fileset 80.02% 🟢
catalog-hive 80.98% 🟢
catalog-jdbc-clickhouse 79.06% 🟢
catalog-jdbc-common 42.89% 🟢
catalog-jdbc-doris 80.28% 🟢
catalog-jdbc-hologres 54.03% 🟢
catalog-jdbc-mysql 79.23% 🟢
catalog-jdbc-oceanbase 78.38% 🟢
catalog-jdbc-postgresql 82.05% 🟢
catalog-jdbc-starrocks 78.27% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 45.07% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 87.16% 🟢
catalog-lakehouse-paimon 77.71% 🟢
catalog-model 77.72% 🟢
cli 44.51% 🟢
client-java 77.63% 🟢
common 49.35% 🟢
core 81.41% 🟢
filesystem-hadoop3 76.97% 🟢
flink 40.55% 🟢
flink-runtime 0.0% 🔴
gcp 14.2% 🔴
hadoop-common 10.39% 🔴
hive-metastore-common 45.82% 🟢
iceberg-common 50.73% 🟢
iceberg-rest-server 65.89% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 23.88% 🔴
lance-rest-server 57.84% 🟢
lineage 53.02% 🟢
optimizer 82.95% 🟢
optimizer-api 21.95% 🔴
server 85.89% 🟢
server-common 70.38% 🟢
spark 32.79% 🔴
spark-common 39.09% 🔴
trino-connector 33.44% -3.53% 🔴
Files
Module File Coverage
trino-connector JsonCodec.java 16.95% 🔴
GravitinoMetadata.java 11.9% 🔴
GravitinoOutputTableHandle.java 0.0% 🔴
GravitinoPageSinkProvider.java 0.0% 🔴

…ELECT)

Implement beginCreateTable/finishCreateTable in the Gravitino Trino
connector to support CREATE TABLE AS SELECT queries.

The approach creates the table in Gravitino catalog first, then
delegates data writing to the internal connector's insert path,
avoiding double table creation in the original connector.

Changes:
- GravitinoMetadata: beginCreateTable delegates to beginInsert
- GravitinoOutputTableHandle: wraps ConnectorInsertTableHandle
- GravitinoPageSinkProvider: routes output handle to insert sink
- JsonCodec: register ConnectorOutputTableHandle for Jackson
- Version-specific finishCreateTable in all 6 SPI subclasses
- TestGravitinoConnector: add testCreateTableAsSelect test

Closes apache#10750
@laserninja laserninja force-pushed the feat/10750-ctas-support branch from 61dab9d to 1d6aa6f Compare April 13, 2026 16:47
@laserninja laserninja marked this pull request as ready for review April 13, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Support CTAS (CREATE TABLE AS SELECT) in Gravitino Iceberg connector

1 participant