Skip to content

[python] Load system tables and branch schemas in JDBC get_table - #10896

Open
plusplusjiajia wants to merge 4 commits into
apache:masterfrom
plusplusjiajia:fix/python-jdbc-system-and-branch-tables
Open

plusplusjiajia wants to merge 4 commits into
apache:masterfrom
plusplusjiajia:fix/python-jdbc-system-and-branch-tables

Conversation

@plusplusjiajia

@plusplusjiajia plusplusjiajia commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Purpose

JdbcCatalog.get_table ignored the $ suffix of the identifier and the branch of the schema:

  • db.t$snapshots, db.t$options and db.t$nosuch all returned the data table;
  • db.t$branch_dev returned a table even when that branch did not exist, and read a branch with its own schema changes with main's schema.

As in Java AbstractCatalog.getTable and PyPaimon's filesystem catalog:

  • system tables are loaded through the shared system table loader, and unknown system table names raise TableNotExistException;
  • get_table_schema reads the schema of the identifier's branch, as FileSystemCatalog.get_table_schema does, so a branch table reads with its own schema, a branch that does not exist raises TableNotExistException, and db.t$branch_dev$options loads the system table of that branch;
  • default main spellings, such as Identifier('db', 't', branch='MAIN'), return a table on the main branch, while a branch whose name is MAIN (db.t$branch_MAIN), which is not the main branch, keeps its identity, also in the identifier of its system tables;
  • the returned table keeps the branch of the identifier, as Java CatalogUtils.loadTable does, so a branch whose name has a $, such as dev$blue, is not split into a branch and a system table.

Branch tables stay supported in PyPaimon's JDBC catalog, as before this change; Java's JdbcCatalog does not support them.

Tests

  • JdbcCatalogTest#test_get_system_table: $options, $OPTIONS and $branch_main$options load the options system table of the data table, by name and by Identifier.
  • JdbcCatalogTest#test_get_system_table_not_exist: unknown system tables and system tables of missing tables raise TableNotExistException.
  • JdbcCatalogTest#test_get_table_branch: a branch reads its own rows, keeps its own schema changes and options and loads its own $options; every main identifier, including Identifier('db', 't', branch='MAIN'), reads main; missing branches and tables raise TableNotExistException; a branch named MAIN, as left by earlier versions, and its $options stay on that branch when their identifiers are reused; a branch named dev$blue keeps its name.
  • catalog_table_guard_test.py: the shared guard test still loads $branch_dev for JDBC.
  • The new tests fail on master. The related catalog, branch and system table tests pass locally: 292 passed, 72 skipped. flake8 is clean.

@plusplusjiajia
plusplusjiajia marked this pull request as ready for review October 30, 2026 12:17
raise TableNotExistException(identifier)
table_path = self.get_table_path(identifier)
table_schema = self.get_table_schema(identifier)
table_identifier = identifier

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.

[P2] Canonicalize accepted default-main identifiers

For Identifier("db", "t", branch="MAIN"), encoded_branch_name() returns None, so the new guard accepts it, but this assignment preserves the identifier’s cached "MAIN"  branch. FileStoreTable.current_branch() then returns "MAIN", causing snapshot and read paths to target a nonexistent uppercase branch rather than main. I reproduced this after writing one row to main: the returned table had current_branch == "MAIN" and read []. Please normalize the base identifier for every accepted default-main input - not only system tables - and extend this test to perform an actual read.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Akash3121 Thanks, confirmed: the returned table kept the MAIN branch and read nothing. Fixed in 9cc196d: get_table now builds the table identifier without the system table or the default main branch spelling for every accepted input, and test_get_table_branch writes a row and reads it back through each main identifier, checking current_branch() is main.

@plusplusjiajia
plusplusjiajia marked this pull request as draft October 31, 2026 07:51
@plusplusjiajia plusplusjiajia changed the title [python] Load system tables and reject branches in JDBC get_table [python] Load system tables and branch schemas in JDBC get_table Oct 31, 2026
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-jdbc-system-and-branch-tables branch from 69962fd to f34b2f6 Compare November 2, 2026 01:49
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-jdbc-system-and-branch-tables branch from f34b2f6 to 36f771f Compare November 16, 2026 01:39
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-jdbc-system-and-branch-tables branch 2 times, most recently from 987f49c to 1384fd7 Compare November 24, 2026 10:17
@plusplusjiajia
plusplusjiajia marked this pull request as ready for review November 24, 2026 10:29
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-jdbc-system-and-branch-tables branch 3 times, most recently from dc33090 to 89406ab Compare November 30, 2026 06:33
plusplusjiajia and others added 4 commits November 30, 2026 01:40
JdbcCatalog.get_table ignored the $ suffix of the identifier: for example
db.t$snapshots, db.t$options and db.t$nosuch all returned the data table,
and db.t$branch_dev returned a table with main's schema even when that
branch did not exist.

As in Java, system tables are now loaded through the shared system table
loader, as in the filesystem catalog, and unknown names raise
TableNotExistException. As in Java JdbcCatalog, a branch other than main
raises NotImplementedError; as in alter_table, only a branch in the name
counts, so Identifier('db', 't', branch='MAIN') still reads db.t.
… get_table

Identifier('db', 't', branch='MAIN') is accepted as the main branch, but
the returned table kept the MAIN branch, so it read a branch that does
not exist and returned no rows. The returned table now uses the
identifier without the system table or such a default main branch
spelling for every accepted input.
Rejecting every branch other than main in JdbcCatalog.get_table removed
a working path: a branch table such as db.t$branch_dev reads and writes
its own snapshots and data files, and the shared catalog guard test
expected it to load.

Branch tables are kept, and the two problems they had are fixed as in
FileSystemCatalog: get_table_schema reads the schema of the
identifier's branch, so a branch with its own schema changes is read
with that schema and a branch that does not exist raises
TableNotExistException, and db.t$branch_dev$options loads the system
table of that branch. The returned table keeps the encoded branch, so a
branch whose name is MAIN, which is not the main branch, keeps its
identity, and keeps the branch of the identifier, as Java
CatalogUtils.loadTable does, so a branch whose name has a '$', such as
dev$blue, is not split into a branch and a system table.
A system table rebuilt its identifier with the branch argument of
Identifier, which drops any case of main, so the options table of a
branch named MAIN reloaded from its identifier read main. Such a branch
is now encoded in the name; other branches keep the branch argument, so
a branch whose name has a '$', such as dev$blue, is not split.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-jdbc-system-and-branch-tables branch from 89406ab to ba20087 Compare November 30, 2026 09:46
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.

2 participants