Skip to content

feat(c): build a catalog-free Table from a resolved schema JSON - #595

Open
JunRuiLee wants to merge 1 commit into
apache:mainfrom
JunRuiLee:feat/table-descriptor
Open

feat(c): build a catalog-free Table from a resolved schema JSON#595
JunRuiLee wants to merge 1 commit into
apache:mainfrom
JunRuiLee:feat/table-descriptor

Conversation

@JunRuiLee

@JunRuiLee JunRuiLee commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Purpose

Add a catalog-free way to build a read-only-oriented Table from an already-resolved Paimon TableSchema, so a non-Java engine (e.g. Doris FE/BE via the C FFI) can rebuild a table for scan/read without a catalog lookup.

Today the only way to obtain a Table is Catalog::get_table, which re-resolves the table — risking schema/snapshot drift versus what the planner (the FE) already resolved — and ties the reader to a filesystem-catalog layout.

An earlier iteration proposed a dedicated TableDescriptor abstraction on the Java side to bundle path/schema/branch. The community felt it lacked sufficient motivation: it would re-define Paimon table metadata on the Java side and couple the paimon-rust interface to Doris integration details. That approach is dropped in favor of this generic, catalog-free entry point.

Design

The caller (Doris FE) passes everything a reader needs directly:

  • table_path — the table location
  • table_schema_json — the full TableSchema JSON, already resolved by the FE (parsed with the existing serde TableSchema shape; preserved as-is, not re-loaded, normalized, or overridden)
  • database / table_name — used to synthesize the table Identifier
  • branch — selects the branch-scoped managers (schema/snapshot/tag read paths); nullable, defaults to main
  • storage_options — used only to build FileIO; they are not merged into the supplied schema

The Rust side constructs the Table directly: no Catalog, no warehouse derivation, and no re-resolution of the FE-provided schema. branch only decides which branch's schema/snapshot/tag paths reads follow; reads can still use FE-generated splits (paimon_plan_from_split_bytes), and Rust-side time travel remains available through the existing read-builder options.

Aligning with Java FileStoreTableFactory.create(fileIO, path, schema) (which uses CatalogEnvironment.empty()), the constructed table is a normal table — not made artificially read-only — and the existing non-main-branch / time-travel write guards still apply.

Brief change log

  • crates/paimon/src/table/mod.rs: Table::from_resolved_schema(file_io, identifier, location, schema, branch) — preserves the supplied schema as-is, validates the identifier and branch name, validates the schema's structural invariants, wires a branch-scoped SchemaManager, sets rest_env = None and no time travel.
  • crates/paimon/src/spec/schema.rs: TableSchema::validate_resolved_structure() — a non-mutating structural check for externally supplied schema JSON: duplicate field names, duplicate field ids (incl. nested), primary-key/partition column existence, primary keys not being exactly the partition columns (which would panic the read path on a zero-column key), and reserved system field names/ids (e.g. a user _ROW_ID column would otherwise be silently replaced by the system row number). It intentionally does not run create-time policy checks (merge-engine/changelog/aggregation/rowkind/blob strategy), which normalize the schema or reject shapes that are valid to read.
  • bindings/c/src/table.rs: C FFI paimon_table_from_schema_json(table_path, table_schema_json, database, table_name, branch, storage_options, storage_options_len), mirroring the existing paimon_catalog_get_table handle/free contract, with an ABI signature guard. branch may be null (defaults to main); a non-null pointer is still fully UTF-8 and branch-name validated. Freed via paimon_table_free.
  • Read/vector/write builder safety docs note that a handle from paimon_table_from_schema_json is also a valid source.
  • Historical per-file schemas are still read from the immutable on-disk schema/schema-N by SchemaManager; the resolved schema pins the planned/current schema only.

Tests

  • paimon-c FFI tests: build a table from a resolved schema; null-branch defaults to main; invalid branch name (../dev) rejected; malformed JSON rejected; null-pointer / null storage_options with non-zero length rejected; invalid identifier rejected; missing primary-key column rejected.
  • paimon unit tests for validate_resolved_structure: accepts a valid schema; rejects missing primary-key column, missing partition column, duplicate field names, and duplicate field ids.

Not in this PR (known, pre-existing scan-planning limitations, independent of this entry point)

These are not introduced by this change and are unreachable through the read path Doris uses (paimon_plan_from_split_bytes reading FE-generated splits):

  • IncrementalScan builds a root (main-branch) SnapshotManager, so incremental scans of a non-main branch would read the main branch's snapshots (Rust-side scan planning only).
  • Time-travel selectors embedded directly in the schema JSON options are not honored by the plain read builder (only options passed to the read-builder call are).
  • A stale path option embedded in the schema JSON is preferred by FormatTableScan over the table location (Rust-side format scan planning only; normal-table reads use the table location and are unaffected).
  • A non-existent bucket-key is silently dropped and all data is written to bucket 0 — a write-path concern only; this entry point is for reading.
  • Full Java-parity SchemaValidation (option-combination policy checks) is not mirrored; only the structural invariants above are enforced.

API and Format

  • New public API: paimon::table::Table::from_resolved_schema, and C FFI paimon_table_from_schema_json (additive; existing symbols unchanged).
  • No new on-disk or wire format, and no new cross-language DTO. Consumes the existing serde TableSchema JSON.

Documentation

None yet (new, evolving C FFI surface for the Doris integration); docs can follow once the integration stabilizes.

@JunRuiLee
JunRuiLee force-pushed the feat/table-descriptor branch 2 times, most recently from 83f2db7 to 7636fda Compare July 28, 2026 08:31
@JunRuiLee JunRuiLee changed the title feat(table): build a catalog-free Table from a portable TableDescriptor feat(c): build a catalog-free Table from a resolved schema JSON Jul 28, 2026
@JunRuiLee
JunRuiLee marked this pull request as ready for review July 28, 2026 08:33
@JunRuiLee
JunRuiLee marked this pull request as draft July 28, 2026 08:40
@JunRuiLee
JunRuiLee force-pushed the feat/table-descriptor branch from 7636fda to ed3e54c Compare July 28, 2026 12:17
Add a catalog-free way to build a Table from an already-resolved Paimon
TableSchema, so a non-Java engine (e.g. Doris via the C FFI) can rebuild a
table for scan/read without a catalog lookup. Today the only way to obtain a
Table is Catalog::get_table, which re-resolves the table (risking schema/
snapshot drift versus what the planner already resolved) and ties the reader
to a filesystem-catalog layout.

The caller passes everything a reader needs directly: table path, the full
TableSchema JSON (preserved as-is, not re-loaded or normalized), database/
table name, branch, and filesystem options. The Rust side constructs the
Table with a plain FileIO and rest_env = None; branch only selects the
branch-scoped schema/snapshot/tag managers. Reads can still use FE-generated
splits via paimon_plan_from_split_bytes. Mirroring Java
FileStoreTableFactory.create(fileIO, path, schema), the table stays a normal
(writable) table; existing non-main-branch / time-travel write guards apply.

Validate the externally supplied schema's structural invariants without
normalizing it (TableSchema::validate_resolved_structure): reject duplicate
field names, duplicate field ids (including nested), primary-key/partition
columns that do not exist, primary keys that are exactly the partition columns
(the read path would panic on a zero-column key), and reserved system field
names/ids (e.g. a user _ROW_ID column would be silently replaced by the system
row number on read). Create-time policy checks (merge-engine/changelog/
aggregation/rowkind/blob strategy, bucket-key existence) are intentionally not
run, since they normalize the schema or reject shapes that are valid to read.

- crates/paimon/src/table/mod.rs: Table::from_resolved_schema.
- crates/paimon/src/spec/schema.rs: TableSchema::validate_resolved_structure.
- bindings/c/src/table.rs: paimon_table_from_schema_json (nullable branch
  defaults to main), mirroring the paimon_catalog_get_table handle/free
  contract with an ABI signature guard; freed via paimon_table_free.

Known pre-existing limitations, unreachable via the split-bytes read path
Doris uses, are left for follow-ups: incremental scan uses a root
SnapshotManager for non-main branches; time-travel selectors embedded in
schema JSON options are not honored by the plain read builder; a stale path
option is preferred by FormatTableScan over the table location; a non-existent
bucket-key is silently dropped on write (write path only); full Java-parity
SchemaValidation is not mirrored.
@JunRuiLee
JunRuiLee force-pushed the feat/table-descriptor branch from ed3e54c to c387895 Compare July 28, 2026 13:08
@JunRuiLee
JunRuiLee marked this pull request as ready for review July 28, 2026 13:19
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.

1 participant