2929import org .apache .iceberg .TableScan ;
3030import org .apache .iceberg .catalog .Namespace ;
3131import org .apache .iceberg .catalog .TableIdentifier ;
32+ import org .apache .iceberg .exceptions .ServiceFailureException ;
3233import org .apache .iceberg .io .CloseableIterable ;
3334import org .apache .iceberg .rest .RESTCatalog ;
3435import org .apache .iceberg .types .Conversions ;
@@ -74,42 +75,17 @@ public static void run(RESTCatalog catalog, String target, boolean json, Option.
7475 if (targetTable != null && !targetTable .equals (tableId .name ())) {
7576 continue ;
7677 }
77- org .apache .iceberg .Table table = catalog .loadTable (tableId );
78- Snapshot snapshot = table .currentSnapshot ();
79- Table .Snapshot snapshotInfo = null ;
80- if (snapshot != null ) {
81- snapshotInfo =
82- new Table .Snapshot (
83- snapshot .sequenceNumber (),
84- snapshot .snapshotId (),
85- snapshot .parentId (),
86- snapshot .timestampMillis (),
87- Instant .ofEpochMilli (snapshot .timestampMillis ()).toString (),
88- Instant .ofEpochMilli (snapshot .timestampMillis ())
89- .atZone (ZoneId .systemDefault ())
90- .format (DateTimeFormatter .ISO_OFFSET_DATE_TIME ),
91- snapshot .operation (),
92- snapshot .summary (),
93- snapshot .manifestListLocation ());
94- }
9578
96- List <Table .Metrics > metrics = null ;
97- if (optionsSet .contains (Option .INCLUDE_METRICS )) {
98- metrics = gatherTableMetrics (table );
79+ Describe .Table .Data tableData = null ;
80+ Table .Metadata tableMetadata ;
81+ try {
82+ tableData = gatherTableData (catalog , tableId , optionsSet );
83+ tableMetadata = new Table .Metadata (tableId .toString ());
84+ } catch (ServiceFailureException e ) {
85+ tableMetadata = new Table .Metadata (tableId .toString (), e .getMessage ());
9986 }
10087
101- boolean includeSchema = optionsSet .contains (Option .INCLUDE_SCHEMA );
102- Table .Data tableData =
103- new Table .Data (
104- includeSchema ? table .schema ().toString () : null ,
105- includeSchema ? table .spec ().toString () : null ,
106- includeSchema ? table .sortOrder ().toString () : null ,
107- optionsSet .contains (Option .INCLUDE_PROPERTIES ) ? table .properties () : null ,
108- table .location (),
109- snapshotInfo ,
110- metrics );
111-
112- tablesMetadata .add (new Table ("Table" , new Table .Metadata (tableId .toString ()), tableData ));
88+ tablesMetadata .add (new Table ("Table" , tableMetadata , tableData ));
11389 }
11490 }
11591
@@ -125,6 +101,45 @@ public static void run(RESTCatalog catalog, String target, boolean json, Option.
125101 }
126102 }
127103
104+ private static Table .Data gatherTableData (
105+ RESTCatalog catalog , TableIdentifier tableId , Set <Describe .Option > optionsSet )
106+ throws IOException {
107+
108+ org .apache .iceberg .Table table = catalog .loadTable (tableId );
109+ Snapshot snapshot = table .currentSnapshot ();
110+ Table .Snapshot snapshotInfo = null ;
111+ if (snapshot != null ) {
112+ snapshotInfo =
113+ new Table .Snapshot (
114+ snapshot .sequenceNumber (),
115+ snapshot .snapshotId (),
116+ snapshot .parentId (),
117+ snapshot .timestampMillis (),
118+ Instant .ofEpochMilli (snapshot .timestampMillis ()).toString (),
119+ Instant .ofEpochMilli (snapshot .timestampMillis ())
120+ .atZone (ZoneId .systemDefault ())
121+ .format (DateTimeFormatter .ISO_OFFSET_DATE_TIME ),
122+ snapshot .operation (),
123+ snapshot .summary (),
124+ snapshot .manifestListLocation ());
125+ }
126+
127+ List <Table .Metrics > metrics = null ;
128+ if (optionsSet .contains (Option .INCLUDE_METRICS )) {
129+ metrics = gatherTableMetrics (table );
130+ }
131+
132+ boolean includeSchema = optionsSet .contains (Option .INCLUDE_SCHEMA );
133+ return new Table .Data (
134+ includeSchema ? table .schema ().toString () : null ,
135+ includeSchema ? table .spec ().toString () : null ,
136+ includeSchema ? table .sortOrder ().toString () : null ,
137+ optionsSet .contains (Option .INCLUDE_PROPERTIES ) ? table .properties () : null ,
138+ table .location (),
139+ snapshotInfo ,
140+ metrics );
141+ }
142+
128143 private static List <Table .Metrics > gatherTableMetrics (org .apache .iceberg .Table table )
129144 throws IOException {
130145 List <Table .Metrics > metricsList = new ArrayList <>();
@@ -218,7 +233,13 @@ record Table(String kind, Table.Metadata metadata, Table.Data data) {
218233 }
219234 }
220235
221- record Metadata (String id ) {}
236+ record Metadata (String id , String status ) {
237+ static final String STATUS_OK = "OK" ;
238+
239+ Metadata (String id ) {
240+ this (id , STATUS_OK );
241+ }
242+ }
222243
223244 record Data (
224245 String schemaRaw ,
0 commit comments