Skip to content

feat(datafusion): Add DDL support with PRIMARY KEY constraint syntax#237

Merged
JingsongLi merged 5 commits intoapache:mainfrom
JingsongLi:ddl
Apr 12, 2026
Merged

feat(datafusion): Add DDL support with PRIMARY KEY constraint syntax#237
JingsongLi merged 5 commits intoapache:mainfrom
JingsongLi:ddl

Conversation

@JingsongLi
Copy link
Copy Markdown
Contributor

Purpose

  • Add PaimonDdlHandler for CREATE TABLE, ALTER TABLE (ADD/DROP/RENAME COLUMN, RENAME TABLE)
  • Add PaimonTableFactory for CREATE EXTERNAL TABLE via DataFusion TableProviderFactory
  • Extend PaimonCatalogProvider/SchemaProvider with CREATE/DROP SCHEMA and DROP TABLE
  • Add arrow_to_paimon_type and arrow_fields_to_paimon to paimon::arrow for Arrow-to-Paimon type conversion
  • Support PRIMARY KEY (col, ...) constraint syntax in CREATE TABLE DDL

Brief change log

Tests

API and Format

Documentation

match &statements[0] {
Statement::CreateTable(create_table) => self.handle_create_table(create_table).await,
Statement::AlterTable {
name, operations, ..
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Statement::AlterTable has an if_exists flag, but it is ignored here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch.


let identifier = resolve_identifier(&cmd.name)?;

// Build Paimon schema from the CREATE EXTERNAL TABLE command.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My understanding is that both CREATE TABLE and CREATE EXTERNAL TABLE create managed Paimon tables here, rather than true external tables. It looks like two SQL entry points for creating the managed Paimon tables. Is that right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, let' ban EXTERNAL.

@littlecoder04
Copy link
Copy Markdown
Contributor

+1

Copy link
Copy Markdown

@leaves12138 leaves12138 left a comment

Choose a reason for hiding this comment

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

Nice work. The DDL support is well-structured and the mock-based tests in ddl.rs are thorough.

Highlights:

  1. PaimonDdlHandler cleanly intercepts CREATE TABLE and ALTER TABLE while delegating everything else to the inner SessionContext. The three-part name resolution (catalog.db.table → strip catalog prefix) is correct.

  2. Arrow↔Paimon type conversion in crates/paimon/src/arrow/mod.rs covers all the common types with roundtrip tests. The mapping of Utf8/LargeUtf8/Utf8View → VarChar and Binary/LargeBinary/BinaryView → VarBinary is sensible.

  3. Integration tests in ddl_tests.rs using FileSystemCatalog + TempDir provide good end-to-end coverage for CREATE TABLE with PK, partitions, and WITH options.

Minor notes (non-blocking):

  • sql_data_type_to_arrow doesn't handle ARRAY, MAP, or ROW types — those will hit the _ => Err(...) fallback. Users would need to use programmatic API for complex types in DDL. Worth a doc mention.
  • The register_table impl in catalog.rs just acknowledges (Ok(Some(table))). This is fine since the actual table creation happens via PaimonDdlHandler, but a short comment explaining the lifecycle (DDL handler creates → DataFusion calls register_table → we ack) would help future readers.

+1, good to merge.

- Add PaimonDdlHandler for CREATE TABLE, ALTER TABLE (ADD/DROP/RENAME COLUMN, RENAME TABLE)
- Add PaimonTableFactory for CREATE EXTERNAL TABLE via DataFusion TableProviderFactory
- Extend PaimonCatalogProvider/SchemaProvider with CREATE/DROP SCHEMA and DROP TABLE
- Add arrow_to_paimon_type and arrow_fields_to_paimon to paimon::arrow for Arrow-to-Paimon type conversion
- Support PRIMARY KEY (col, ...) constraint syntax in CREATE TABLE DDL
@JingsongLi JingsongLi merged commit 7b3c89f into apache:main Apr 12, 2026
8 checks passed
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.

3 participants