99 */
1010package com .altinity .ice .cli .internal .cmd ;
1111
12+ import com .altinity .ice .cli .internal .util .TreePrinter ;
1213import java .io .IOException ;
1314import java .util .ArrayList ;
1415import java .util .List ;
@@ -30,53 +31,49 @@ public static void run(RESTCatalog catalog, TableIdentifier tableId) throws IOEx
3031 Table table = catalog .loadTable (tableId );
3132 Snapshot snapshot = table .currentSnapshot ();
3233
34+ String tableName = tableId .toString ();
35+ String rootLabel = "Snapshots: " + tableName ;
36+
3337 if (snapshot == null ) {
34- System .out .println ("Snapshots: " + tableId );
38+ System .out .println (rootLabel );
3539 System .out .println ("(no snapshots)" );
3640 return ;
3741 }
3842
39- String tableName = tableId .toString ();
4043 int schemaId = snapshot .schemaId () != null ? snapshot .schemaId () : 0 ;
4144 String manifestListLocation = snapshot .manifestListLocation ();
4245 String locationStr = manifestListLocation != null ? manifestListLocation : "(embedded)" ;
43-
44- System .out .println ("Snapshots: " + tableName );
45- System .out .println (
46- "└── Snapshot " + snapshot .snapshotId () + ", schema " + schemaId + ": " + locationStr );
46+ String snapshotLabel =
47+ "Snapshot " + snapshot .snapshotId () + ", schema " + schemaId + ": " + locationStr ;
4748
4849 FileIO tableIO = table .io ();
4950 List <ManifestFile > manifests ;
5051 try {
5152 manifests = snapshot .allManifests (tableIO );
5253 } catch (Exception e ) {
54+ TreePrinter .print (
55+ new TreePrinter .Node (rootLabel , List .of (new TreePrinter .Node (snapshotLabel ))));
5356 System .out .println (" (failed to read manifests: " + e .getMessage () + ")" );
5457 return ;
5558 }
5659
57- for (int m = 0 ; m < manifests .size (); m ++) {
58- ManifestFile manifest = manifests .get (m );
59- boolean isLastManifest = (m == manifests .size () - 1 );
60- String manifestPrefix = isLastManifest ? "└── " : "├── " ;
61- String childConnector = isLastManifest ? " " : "│ " ;
62-
63- List <String > dataFileLocations = new ArrayList <>();
60+ List <TreePrinter .Node > manifestNodes = new ArrayList <>(manifests .size ());
61+ for (ManifestFile manifest : manifests ) {
62+ List <TreePrinter .Node > dataFileNodes = new ArrayList <>();
6463 try (CloseableIterable <DataFile > files = ManifestFiles .read (manifest , tableIO )) {
6564 for (DataFile file : files ) {
66- dataFileLocations .add (file .location ());
65+ dataFileNodes .add (new TreePrinter . Node ( "Datafile: " + file .location () ));
6766 }
6867 } catch (Exception e ) {
69- dataFileLocations .add ("(failed to read: " + e .getMessage () + ")" );
70- }
71-
72- System .out .println (" " + manifestPrefix + "Manifest: " + manifest .path ());
73-
74- String dataFileIndent = " " + childConnector ;
75- for (int f = 0 ; f < dataFileLocations .size (); f ++) {
76- boolean isLastFile = (f == dataFileLocations .size () - 1 );
77- String filePrefix = isLastFile ? "└── " : "├── " ;
78- System .out .println (dataFileIndent + filePrefix + "Datafile: " + dataFileLocations .get (f ));
68+ dataFileNodes .add (
69+ new TreePrinter .Node ("Datafile: (failed to read: " + e .getMessage () + ")" ));
7970 }
71+ manifestNodes .add (new TreePrinter .Node ("Manifest: " + manifest .path (), dataFileNodes ));
8072 }
73+
74+ TreePrinter .Node root =
75+ new TreePrinter .Node (
76+ rootLabel , List .of (new TreePrinter .Node (snapshotLabel , manifestNodes )));
77+ TreePrinter .print (root );
8178 }
8279}
0 commit comments