Skip to content

[Feature] Add snapshot index and file key range inspection to PyPaimon CLI - #11701

Open
ViktorBystrov72 wants to merge 3 commits into
apache:masterfrom
ViktorBystrov72:feat/11697-inspect-snapshot-indexes
Open

ViktorBystrov72 wants to merge 3 commits into
apache:masterfrom
ViktorBystrov72:feat/11697-inspect-snapshot-indexes

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

Purpose

Refs #11697.

Add read-only paimon table indexes and paimon table file-key-ranges commands over the existing PyPaimon system tables. Both pin the requested or latest snapshot, report its ID, and support --limit, table output, and JSON output.

JSON preserves null values and integer metadata. The display limit applies after reading the system table. The file-indexes command requires a new reader and can be handled separately.

Tests

The two targeted CliTableTest cases passed on Python 3.13. They cover a retained snapshot, the latest snapshot ID in table output, missing snapshots, and limited output with nulls and large integers.

with patch.object(TableIndexesTable, '_build_arrow_table', return_value=rows):
result = json.loads(self._run_table_command_success(
'indexes', identifier, '--snapshot-id', '1', '--limit', '1', '-f', 'json'
))

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.

Nit: Because TableIndexesTable._build_arrow_table is patched with synthetic column names (row_range_start / row_range_end instead of TableIndexesTable's actual global_index_row_range_start / global_index_row_range_end) and ignores self, this test doesn't verify that TableIndexesTable actually reads from the view pinned to --snapshot-id 1, nor does it cover the empty-result branch (No indexes found for table ...).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I replaced the mocked Arrow table with a real Avro index manifest and two snapshots. The CLI reads and limits the historical snapshot while the latest snapshot returns an empty result. The fixture also checks the snapshot ID and preserves large row ranges and nulls. On this base the system-table columns are named row_range_start and row_range_end. The 10 focused tests passed. Updated test

import pandas as pd
display_id = _snapshot_display_value(snapshot_id)
values = [[display_id, *(_snapshot_display_value(value) for value in row.values())] for row in rows]
print(pd.DataFrame(values, columns=['snapshot_id'] + batch.column_names).to_string(index=False))

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.

Nit: Right above in cmd_table_list_files (lines 652–654), snapshot_id is included in each row dictionary (rows = [dict(snapshot_id=snapshot_id, **dict(zip(columns, values))) ...]) as well as at the top level of the JSON payload, whereas here snapshot_id is only prepended in --format table and omitted from each row in --format json. Not a blocker (having snapshot_id only once at the top level in JSON is arguably cleaner, matching list-manifests), just noting the slight difference across the system-table-backed CLI commands.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I kept snapshot_id at the top level in JSON because all rows come from the same pinned snapshot, matching the list-manifests layout. Table output includes it as the first column. The real-manifest fixture now checks both formats and the empty snapshot.

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