Skip to content

feat: add global system tables framework under sys database#366

Open
suxiaogang223 wants to merge 16 commits into
alibaba:mainfrom
suxiaogang223:codex/global-system-tables
Open

feat: add global system tables framework under sys database#366
suxiaogang223 wants to merge 16 commits into
alibaba:mainfrom
suxiaogang223:codex/global-system-tables

Conversation

@suxiaogang223

@suxiaogang223 suxiaogang223 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Add global system table support under the sys database, enabling catalog-level metadata queries.

Closes part of #141.

Changes

Infrastructure

  • Add GetOptions() to Catalog interface for catalog-level config access
  • FileSystemCatalog stores and exposes catalog options
  • New GlobalSystemTableLoader with independent registry for sys tables
  • Extend SystemTablePath with is_global flag and TryParsePath to detect sys/ paths
  • FileSystemCatalog handles sys database in ListTables/DatabaseExists/TableExists/LoadTableSchema

Global System Tables

Table Status Columns
sys.catalog_options ✅ Complete key, value
sys.all_table_options ✅ Complete database_name, table_name, key, value
sys.tables ✅ Complete database_name, table_name, table_type, partitioned, primary_key, record_count, file_size_in_bytes, file_count, last_file_creation_time
sys.partitions ✅ Complete database_name, table_name, partition_name, record_count, file_size_in_bytes, file_count, last_update_time

Integration Tests (4 new tests in SystemTableReadInteTest)

  • TestReadGlobalCatalogOptions — verifies schema + content
  • TestReadGlobalAllTableOptions — verifies table options across databases
  • TestReadGlobalTables — verifies schema, table metadata
  • TestReadGlobalPartitions — verifies empty result for unpartitioned tables

Files Changed

 include/paimon/catalog/catalog.h                   |   5 +
 src/paimon/CMakeLists.txt                          |   1 +
 src/paimon/core/catalog/catalog.cpp                |   2 +-
 src/paimon/core/catalog/file_system_catalog.cpp    |  39 +-
 src/paimon/core/catalog/file_system_catalog.h      |   6 +-
 .../core/table/system/global_system_tables.cpp     | 370 ++++++++++++++
 .../core/table/system/global_system_tables.h       | 117 +++++
 src/paimon/core/table/system/system_table.cpp      |  28 +-
 src/paimon/core/table/system/system_table.h        |   2 +
 .../core/catalog/file_system_catalog_test.cpp      |  14 +-
 test/inte/read_inte_test.cpp                       | 237 +++++++++
 11 files changed, 810 insertions(+), 10 deletions(-)

Verification

Fedora x86_64, GCC 16:

  • Build: ✅
  • paimon-core-test: 36/40 pass (4 failures pre-existing)
  • paimon-read-inte-test (global tables): 4/4 ✅
  • paimon-read-inte-test (system tables): same as before

🤖 Generated with Claude Code

@suxiaogang223
suxiaogang223 force-pushed the codex/global-system-tables branch from e4597fa to 92de892 Compare July 2, 2026 08:45
@suxiaogang223
suxiaogang223 marked this pull request as ready for review July 2, 2026 12:29
@suxiaogang223
suxiaogang223 force-pushed the codex/global-system-tables branch from 55828f8 to c5d3439 Compare July 2, 2026 13:00

@zjw1111 zjw1111 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for building out the global sys system tables — the loader/registry split and reuse of InMemorySystemTable make the design clean and easy to follow.

I left a few inline comments. The most important one is a potential crash on the normal engine read path for sys.tables / sys.partitions / sys.all_table_options (see the comment in system_table.cpp). A couple of smaller notes are below:

  • global_system_tables.cpp (CatalogOptionsSystemTable::BuildRows, around line 264): this table stores fields via a non-owning std::string_view into context_.catalog_options, while the other tables copy through BinaryString (StringValue). It's safe today because the map is a stable member, but for consistency and to avoid a future dangling-view footgun, would it be possible to use StringValue(...) here too?
  • file_system_catalog.cpp (line 282): the const_cast<FileSystemCatalog*>(this) looks unnecessary since only const Catalog methods are used later — declaring GlobalSystemTableContext::catalog as const Catalog* would let you drop it. Minor, feel free to skip.

Thanks again!

Comment thread src/paimon/core/table/system/system_table.cpp
Comment thread src/paimon/core/table/system/global_system_tables.h Outdated
Comment thread src/paimon/core/table/system/system_table.cpp Outdated

@zjw1111 zjw1111 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional inline note on the sys.tables primary_key column — a schema/data-contract nit. Thanks!

Comment thread src/paimon/core/table/system/global_system_tables.cpp Outdated
Comment thread src/paimon/core/catalog/file_system_catalog.h
Comment thread src/paimon/core/catalog/file_system_catalog_test.cpp
Comment thread src/paimon/core/catalog/file_system_catalog_test.cpp
Comment thread src/paimon/core/table/system/global_system_tables.cpp
Comment thread src/paimon/core/table/system/global_system_tables.cpp
@suxiaogang223
suxiaogang223 force-pushed the codex/global-system-tables branch from 76f878a to d79ca7b Compare July 13, 2026 11:41
suxiaogang223 and others added 13 commits July 17, 2026 10:27
- Add GetOptions() to Catalog interface for catalog-level config access
- FileSystemCatalog stores and exposes catalog_options
- New GlobalSystemTableLoader with independent registry for sys tables
- Implement sys.catalog_options, sys.all_table_options, sys.tables
- Stub for sys.partitions (manifest aggregation to follow)
- Extend SystemTablePath with is_global flag
- TryParsePath detects sys/ paths for TableScan/TableRead routing
- FileSystemCatalog handles sys database in ListTables, DatabaseExists,
  TableExists, LoadTableSchema

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace the TODO stubs in TablesSystemTable::BuildRows() with actual
manifest entry aggregation. The new AggregateFileStats() helper reads
the latest snapshot data files and computes record_count, file_size,
file_count, and last_file_creation_time.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace the stub with actual partition-level file statistics using the
AggregateFileStats helper. For each partitioned table, read manifest
entries and emit one row per partition with record_count, file_size,
file_count, and last_update_time.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add 4 tests to SystemTableReadInteTest:
- TestReadGlobalCatalogOptions: verifies sys.catalog_options schema and content
- TestReadGlobalAllTableOptions: verifies sys.all_table_options with table options
- TestReadGlobalTables: verifies sys.tables schema, table_type, partitioned, pk
- TestReadGlobalPartitions: verifies sys.partitions returns empty for unpartitioned

Tests use a ReadGlobalSystemTable helper that creates the
GlobalSystemTableContext with a proper Catalog pointer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@suxiaogang223
suxiaogang223 force-pushed the codex/global-system-tables branch from bc70c46 to fc812bb Compare July 17, 2026 02:28
Comment thread src/paimon/core/table/system/global_system_tables.cpp

@lxy-9602 lxy-9602 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

@lxy-9602
lxy-9602 requested a review from zjw1111 July 20, 2026 06:51

@zjw1111 zjw1111 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks again for the updates. Two small consistency notes on the new sys.tables implementation versus Java Paimon.


const auto& opts = data_schema->Options();
auto table_type = opts.find("type");
const std::string table_type_str = table_type == opts.end() ? "TABLE" : table_type->second;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for aligning the sys.tables schema with Java — the 14-column layout looks great.

One small consistency issue on the default table_type: here it falls back to "TABLE" (uppercase), but Java's AllTablesTable uses options.getOrDefault(TYPE.key(), TYPE.defaultValue().toString()), and TableType.TABLE.toString() returns the lowercase "table" (see TableType: TABLE("table", ...)). So for a normal table without an explicit type option, the C++ reader emits "TABLE" while Java emits "table", which clients relying on the Java contract would see as a mismatch.

Would it be possible to default to the lowercase "table"? Note that TestReadGlobalTables currently asserts "TABLE", so that assertion would need updating as well.

}

auto& stats = result.by_partition[partition_key];
stats.record_count += file->row_count;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for populating the file statistics here.

I wonder if this diverges from Java's contract for a filesystem catalog. In Java, CatalogUtils.toTableAndSnapshots only loads a TableSnapshot when catalog.supportsVersionManagement() is true; FileSystemCatalog (via AbstractCatalog) returns false, so snapshot stays null and AllTablesTable emits null for record_count / file_size_in_bytes / file_count / last_file_creation_time. This PR instead reads the latest snapshot and manifests to compute them, so for a table with committed data the C++ reader returns non-null values where Java returns null.

In addition, the semantics of record_count itself differ: here it is the sum of row_count over merged ADD entries (i.e. live rows), whereas Java's snapshot.recordCount() is the accumulated totalRecordCount, so even when populated the two are not equivalent.

TestReadGlobalTables doesn't surface this because the tables have no committed data (empty snapshot → all-null branch). Could you clarify whether this is an intentional enhancement? If so, it would help to document the difference from the Java FS-catalog contract in a comment and add a "table with data" case to lock in the expected values.

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