JingsongLi commented on code in PR #11154:
URL: https://github.com/apache/paimon/pull/11154#discussion_r4588553755
##########
paimon-python/pypaimon/cli/cli_table.py:
##########
@@ -595,12 +595,145 @@ def cmd_table_manifest(args):
sys.exit(1)
+def cmd_table_list_files(args):
+ """
+ Execute the 'table list-files' command.
+
+ Lists the live data files referenced by the latest or a specified snapshot.
+
+ Args:
+ args: Parsed command line arguments.
+ """
+ from pypaimon.table.file_store_table import FileStoreTable
+ from pypaimon.table.system.files_table import FilesTable
+
+ table = _open_schema_table(args)
+ try:
+ if not isinstance(table, FileStoreTable):
+ raise ValueError('File listing is not supported for this table
type; expected a FileStoreTable.')
+ manager = table.snapshot_manager()
+ snapshot = (manager.get_latest_snapshot() if args.snapshot_id is None
+ else manager.get_snapshot_by_id(args.snapshot_id))
+ if snapshot is None and args.snapshot_id is not None:
+ raise ValueError(f"Snapshot {args.snapshot_id} not found for table
'{args.table}'.")
+
+ # Pin the resolved snapshot, including an empty table, before reading
its live files.
+ files =
FilesTable(table._copy_with_snapshot(snapshot))._build_arrow_table()
+ if args.bucket is not None:
+ import pyarrow.compute as pc
+ files = files.filter(pc.equal(files.column('bucket'), args.bucket))
+ if args.limit is not None:
+ files = files.slice(0, args.limit)
+ files = files.rename_columns(['delete_row_count' if name ==
'deleteRowCount' else name
+ for name in files.column_names])
+ snapshot_id = snapshot.id if snapshot is not None else None
+ # Table.to_pylist is unavailable in the supported PyArrow 6 release.
+ columns = files.to_pydict()
+ rows = [dict(snapshot_id=snapshot_id, **dict(zip(columns, values)))
for values in zip(*columns.values())]
+ if args.format == 'json':
+ result = _manifest_json_value({'table': args.table, 'snapshot_id':
snapshot_id, 'files': rows})
+ print(json.dumps(result, ensure_ascii=False, indent=2,
allow_nan=False))
+ elif not rows:
+ print(f"No files found for table '{args.table}' (snapshot
{_snapshot_display_value(snapshot_id)}).")
+ else:
+ import pandas as pd
+ for row in rows:
+ if row['creation_time'] is not None:
+ row['creation_time'] = row['creation_time'].isoformat()
+ # Convert before Pandas can coerce nullable integers to floats.
+ values = [[_snapshot_display_value(value) for value in
row.values()] for row in rows]
+ print(pd.DataFrame(values, columns=['snapshot_id'] +
files.column_names).to_string(index=False))
+ except Exception as e:
+ print(f"Error: Failed to list files for table '{args.table}': {e}",
file=sys.stderr)
+ sys.exit(1)
+
+
+def cmd_table_file(args):
+ """
+ Execute the 'table file' command.
+
+ Displays a Parquet file's schema and footer metadata without reading data
records.
+
+ Args:
+ args: Parsed command line arguments.
+ """
+ from os.path import basename
+
+ import pyarrow.fs as pafs
+ import pyarrow.parquet as pq
+
+ from pypaimon.table.system.files_table import _data_file_format
+ from pypaimon.utils.path import to_file_io_path
+
+ table = _open_schema_table(args)
+ try:
+ io_path = to_file_io_path(args.file)
+ fallback_path = args.file
+ # Paimon emits literal file:/ paths; standard file:/// URIs are
URL-encoded.
+ if args.file.startswith('file:///'):
Review Comment:
[P2] Disambiguate localhost URIs before opening the file
Only `file:///` receives URI-decoding precedence here. For a standard
`file://localhost/.../literal%20file.parquet` URI, `to_file_io_path` instead
tries the physical `literal%20file.parquet` first. If that file also exists
beside the intended `literal file.parquet`, the stat succeeds and no fallback
occurs, so the command silently reports the other file's schema/footer while
echoing the original URI.
I reproduced this with two real Parquet files containing one and two rows
respectively. The decoded physical path and
`file:///.../literal%20file.parquet` both report two rows, but the equivalent
localhost URI reports one. With the same files and URI, the previous
`bdd9b2a142` command reports the correct two rows; the regression is introduced
by this revision.
Please make metadata-literal paths and standard URIs unambiguous, or reject
inputs whose two interpretations identify different existing files. Simply
reversing localhost precedence can break metadata paths that retain that
authority, so preserve the metadata round-trip tests and add this coexistence
case.
--
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]