TheR1sing3un opened a new pull request, #7738:
URL: https://github.com/apache/paimon/pull/7738
## Purpose
Java's `org.apache.paimon.catalog.Identifier` encodes the branch (and any
system-table suffix) **into the `object` field** — `tbl$branch_dev$snapshots` —
so the wire shape is exactly two strings, `database` and `object`. Python's
`Identifier` was out of step on three real points:
1. **`SYSTEM_BRANCH_PREFIX = 'branch-'`** in Python vs **`branch_`** (with
underscore) in Java. Anything written by the Java REST server in the form
`tbl$branch_<name>` falls into Python's two-segment
branch-of-`is_system_table()`, where the prefix check `startswith('branch-')`
returns `False` → the method returns `True`. **Today a branched table is
misclassified as a system table by Python.**
2. **`branch` was a separate JSON field.** Java's
`@JsonIgnoreProperties(ignoreUnknown = true)` silently drops that field on the
wire — Python clients calling `Identifier(database=..., object=...,
branch=...)` thought they were targeting a branch but the server never saw it.
3. **`get_table_name()` returned the raw `object` name** including any
encoded suffix, and `get_branch_name()` / `get_system_table_name()` couldn't
decode `tbl$branch_dev$snapshots`-style names.
This PR ports the Java design 1:1.
## Identifier changes
* `Identifier(database, object)` is now the JSON-create constructor; the
`object` may already carry an encoded branch / system_table.
* `Identifier.create(database, table, branch=None, system_table=None)`
encodes the components into the object. `branch == "main"` (case-insensitive)
is the default and is **not** encoded, matching Java.
* `_split_object_name()` lazily decodes the object into `table` / `branch` /
`system_table`, with the same 1- / 2- / 3-segment rules as Java's
`splitObjectName()`.
* `SYSTEM_BRANCH_PREFIX` is now `branch_`.
* `get_full_name()` drops the database prefix when database is
`UNKNOWN_DATABASE` (matches Java).
* `__hash__` / `__eq__` use only `(database, object)`, so a JSON round-trip
produces an equal instance.
## Knock-on cleanup (single source of truth)
Now that the identifier carries the branch:
* `SnapshotCommit.commit()` (abstract + `CatalogSnapshotCommit` +
`RenamingSnapshotCommit`) drops its `branch` parameter; `FileStoreCommit` stops
passing `table.current_branch()`.
* `FileStoreTable.current_branch()` reads from the identifier (was
`self.options.branch()`).
* `FileStoreTable.copy()` re-encodes the branch into a new identifier when
`CoreOptions.BRANCH` is supplied, so `CatalogEnvironment` sees the branched
object name.
* `RESTCatalog.to_table_metadata()` drops the now-redundant block that
copied the branch back into options.
* `RESTTokenFileIO.refresh_token()` uses `Identifier.create(db, table,
branch=...)` to strip the system-table suffix while preserving the branch.
* The mock REST server's URL parser stops scanning for a `table.branch`
suffix and reads `identifier.get_branch_name()` directly, matching the Java URL
convention.
## Linked issue
N/A — surfaced when running pypaimon against a Java REST server that emits
`tbl$branch_<name>` object names.
## Tests
* `pypaimon/tests/identifier_test.py` — 25 cases covering simple / backtick
/ Java-compatible parsing, branch encoding, `main`-branch normalization,
`UNKNOWN_DATABASE`, one- / two- / three-segment object names with and without
branch prefix, `create()` with branch + system_table, equality through the JSON
shape, and the malformed `tbl$x$y`-without-branch-prefix case.
* `catalog_branch_manager_test`, `file_store_table_test`,
`rest_catalog_commit_snapshot_test`, `rest_token_file_io_test` — updated to
construct branched identifiers via `Identifier.create(...)` or the
`db.tbl$branch_<x>` string form.
Local: `pytest
pypaimon/tests/{identifier_test,branch,table/file_store_table_test,file_store_commit_test,rest/{client_test,rest_token_file_io_test,rest_catalog_commit_snapshot_test}.py}`
→ all green; `flake8 --config=dev/cfg.ini` clean.
## API and format
* **Wire compatibility**: this is a wire-correctness fix. The previous
`branch` JSON field was already silently dropped by Java; nothing that
successfully round-tripped through the Java REST server is affected. After the
fix, branch-aware Python clients now correctly produce
`object="tbl$branch_<name>"` that Java decodes the same way.
* **Public Python API**: `Identifier(database, object, branch=...)` no
longer accepts `branch` as a third arg. Use `Identifier.create(database, table,
branch=...)` instead. The two in-tree call sites that used the old form have
been updated.
* No file format change.
## Documentation
The new `create()` signature and the encoding rules are documented inline on
`Identifier` and `create()`.
## Generative AI disclosure
Drafted with assistance from an AI coding tool; the design is a direct 1:1
port of `org.apache.paimon.catalog.Identifier` (paimon-api), and every
behavioural difference between Java and Python that this PR closes is exercised
by a test in `identifier_test.py`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]