fengruotj commented on code in PR #11154:
URL: https://github.com/apache/paimon/pull/11154#discussion_r4583130538


##########
paimon-python/pypaimon/cli/cli_table.py:
##########
@@ -595,12 +595,133 @@ 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
+
+    table = _open_schema_table(args)
+    try:
+        status = table.file_io.get_file_status(args.file)
+        if status.type != pafs.FileType.File:

Review Comment:
   @Akash3121 Thanks for reviewing! Agreed. I've added a local change to 
preserve the emitted metadata path at both FileIO calls, with regression tests 
for the public list-files/manifest-to-file round trip on escaped partitions and 
for ordinary encoded file URIs. 



-- 
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]

Reply via email to