21
21
import static org .apache .iceberg .spark .actions .NDVSketchUtil .APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY ;
22
22
import static org .apache .iceberg .types .Types .NestedField .optional ;
23
23
import static org .apache .iceberg .types .Types .NestedField .required ;
24
- import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
25
- import static org .junit .jupiter .api .Assertions .assertNotEquals ;
26
- import static org .junit .jupiter .api .Assertions .assertNotNull ;
27
- import static org .junit .jupiter .api .Assertions .assertThrows ;
28
- import static org .junit .jupiter .api .Assertions .assertTrue ;
24
+ import static org .assertj .core .api .Assertions .assertThat ;
25
+ import static org .assertj .core .api .Assertions .assertThatNoException ;
26
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
29
27
30
28
import java .io .IOException ;
31
29
import java .util .List ;
58
56
import org .apache .spark .sql .catalyst .parser .ParseException ;
59
57
import org .apache .spark .sql .types .StructType ;
60
58
import org .junit .jupiter .api .AfterEach ;
61
- import org .junit .jupiter .api .Assertions ;
62
59
import org .junit .jupiter .api .TestTemplate ;
63
60
64
61
public class TestComputeTableStatsAction extends CatalogTestBase {
@@ -89,8 +86,8 @@ public void testLoadingTableDirectly() {
89
86
SparkActions actions = SparkActions .get ();
90
87
ComputeTableStats .Result results = actions .computeTableStats (table ).execute ();
91
88
StatisticsFile statisticsFile = results .statisticsFile ();
92
- Assertions . assertNotEquals (statisticsFile .fileSizeInBytes (), 0 );
93
- Assertions . assertEquals (statisticsFile .blobMetadata (). size (), 2 );
89
+ assertThat (statisticsFile .fileSizeInBytes ()). isGreaterThan ( 0 );
90
+ assertThat (statisticsFile .blobMetadata ()). hasSize ( 2 );
94
91
}
95
92
96
93
@ TestTemplate
@@ -115,19 +112,18 @@ public void testComputeTableStatsAction() throws NoSuchTableException, ParseExce
115
112
SparkActions actions = SparkActions .get ();
116
113
ComputeTableStats .Result results =
117
114
actions .computeTableStats (table ).columns ("id" , "data" ).execute ();
118
- assertNotNull (results );
115
+ assertThat (results ). isNotNull ( );
119
116
120
117
List <StatisticsFile > statisticsFiles = table .statisticsFiles ();
121
- Assertions . assertEquals (statisticsFiles . size (), 1 );
118
+ assertThat (statisticsFiles ). hasSize ( 1 );
122
119
123
120
StatisticsFile statisticsFile = statisticsFiles .get (0 );
124
- assertNotEquals (statisticsFile .fileSizeInBytes (), 0 );
125
- Assertions . assertEquals (statisticsFile .blobMetadata (). size (), 2 );
121
+ assertThat (statisticsFile .fileSizeInBytes ()). isGreaterThan ( 0 );
122
+ assertThat (statisticsFile .blobMetadata ()). hasSize ( 2 );
126
123
127
124
BlobMetadata blobMetadata = statisticsFile .blobMetadata ().get (0 );
128
- Assertions .assertEquals (
129
- blobMetadata .properties ().get (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY ),
130
- String .valueOf (4 ));
125
+ assertThat (blobMetadata .properties ())
126
+ .containsEntry (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY , "4" );
131
127
}
132
128
133
129
@ TestTemplate
@@ -149,28 +145,16 @@ public void testComputeTableStatsActionWithoutExplicitColumns()
149
145
Table table = Spark3Util .loadIcebergTable (spark , tableName );
150
146
SparkActions actions = SparkActions .get ();
151
147
ComputeTableStats .Result results = actions .computeTableStats (table ).execute ();
152
- assertNotNull (results );
148
+ assertThat (results ). isNotNull ( );
153
149
154
- Assertions . assertEquals ( 1 , table .statisticsFiles (). size () );
150
+ assertThat ( table .statisticsFiles ()). hasSize ( 1 );
155
151
StatisticsFile statisticsFile = table .statisticsFiles ().get (0 );
156
- Assertions .assertEquals (2 , statisticsFile .blobMetadata ().size ());
157
- assertNotEquals (0 , statisticsFile .fileSizeInBytes ());
158
- Assertions .assertEquals (
159
- 4 ,
160
- Long .parseLong (
161
- statisticsFile
162
- .blobMetadata ()
163
- .get (0 )
164
- .properties ()
165
- .get (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY )));
166
- Assertions .assertEquals (
167
- 4 ,
168
- Long .parseLong (
169
- statisticsFile
170
- .blobMetadata ()
171
- .get (1 )
172
- .properties ()
173
- .get (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY )));
152
+ assertThat (statisticsFile .fileSizeInBytes ()).isGreaterThan (0 );
153
+ assertThat (statisticsFile .blobMetadata ()).hasSize (2 );
154
+ assertThat (statisticsFile .blobMetadata ().get (0 ).properties ())
155
+ .containsEntry (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY , "4" );
156
+ assertThat (statisticsFile .blobMetadata ().get (1 ).properties ())
157
+ .containsEntry (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY , "4" );
174
158
}
175
159
176
160
@ TestTemplate
@@ -180,12 +164,9 @@ public void testComputeTableStatsForInvalidColumns() throws NoSuchTableException
180
164
sql ("INSERT into %s values(1, 'abcd')" , tableName );
181
165
Table table = Spark3Util .loadIcebergTable (spark , tableName );
182
166
SparkActions actions = SparkActions .get ();
183
- IllegalArgumentException exception =
184
- assertThrows (
185
- IllegalArgumentException .class ,
186
- () -> actions .computeTableStats (table ).columns ("id1" ).execute ());
187
- String message = exception .getMessage ();
188
- assertTrue (message .contains ("Can't find column id1 in table" ));
167
+ assertThatThrownBy (() -> actions .computeTableStats (table ).columns ("id1" ).execute ())
168
+ .isInstanceOf (IllegalArgumentException .class )
169
+ .hasMessageStartingWith ("Can't find column id1 in table" );
189
170
}
190
171
191
172
@ TestTemplate
@@ -194,7 +175,7 @@ public void testComputeTableStatsWithNoSnapshots() throws NoSuchTableException,
194
175
Table table = Spark3Util .loadIcebergTable (spark , tableName );
195
176
SparkActions actions = SparkActions .get ();
196
177
ComputeTableStats .Result result = actions .computeTableStats (table ).columns ("id" ).execute ();
197
- Assertions . assertNull (result .statisticsFile ());
178
+ assertThat (result .statisticsFile ()). isNull ( );
198
179
}
199
180
200
181
@ TestTemplate
@@ -215,19 +196,17 @@ public void testComputeTableStatsWithNullValues() throws NoSuchTableException, P
215
196
Table table = Spark3Util .loadIcebergTable (spark , tableName );
216
197
SparkActions actions = SparkActions .get ();
217
198
ComputeTableStats .Result results = actions .computeTableStats (table ).columns ("data" ).execute ();
218
- assertNotNull (results );
199
+ assertThat (results ). isNotNull ( );
219
200
220
201
List <StatisticsFile > statisticsFiles = table .statisticsFiles ();
221
- Assertions . assertEquals (statisticsFiles . size (), 1 );
202
+ assertThat (statisticsFiles ). hasSize ( 1 );
222
203
223
204
StatisticsFile statisticsFile = statisticsFiles .get (0 );
224
- assertNotEquals (statisticsFile .fileSizeInBytes (), 0 );
225
- Assertions . assertEquals (statisticsFile .blobMetadata (). size (), 1 );
205
+ assertThat (statisticsFile .fileSizeInBytes ()). isGreaterThan ( 0 );
206
+ assertThat (statisticsFile .blobMetadata ()). hasSize ( 1 );
226
207
227
- BlobMetadata blobMetadata = statisticsFile .blobMetadata ().get (0 );
228
- Assertions .assertEquals (
229
- blobMetadata .properties ().get (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY ),
230
- String .valueOf (4 ));
208
+ assertThat (statisticsFile .blobMetadata ().get (0 ).properties ())
209
+ .containsEntry (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY , "4" );
231
210
}
232
211
233
212
@ TestTemplate
@@ -241,7 +220,8 @@ public void testComputeTableStatsWithSnapshotHavingDifferentSchemas()
241
220
// Snapshot id not specified
242
221
Table table = Spark3Util .loadIcebergTable (spark , tableName );
243
222
244
- assertDoesNotThrow (() -> actions .computeTableStats (table ).columns ("data" ).execute ());
223
+ assertThatNoException ()
224
+ .isThrownBy (() -> actions .computeTableStats (table ).columns ("data" ).execute ());
245
225
246
226
sql ("ALTER TABLE %s DROP COLUMN %s" , tableName , "data" );
247
227
// Append data to create snapshot
@@ -250,15 +230,14 @@ public void testComputeTableStatsWithSnapshotHavingDifferentSchemas()
250
230
long snapshotId2 = Spark3Util .loadIcebergTable (spark , tableName ).currentSnapshot ().snapshotId ();
251
231
252
232
// Snapshot id specified
253
- assertDoesNotThrow (
254
- () -> actions .computeTableStats (table ).snapshot (snapshotId1 ).columns ("data" ).execute ());
255
-
256
- IllegalArgumentException exception =
257
- assertThrows (
258
- IllegalArgumentException .class ,
259
- () -> actions .computeTableStats (table ).snapshot (snapshotId2 ).columns ("data" ).execute ());
260
- String message = exception .getMessage ();
261
- assertTrue (message .contains ("Can't find column data in table" ));
233
+ assertThatNoException ()
234
+ .isThrownBy (
235
+ () -> actions .computeTableStats (table ).snapshot (snapshotId1 ).columns ("data" ).execute ());
236
+
237
+ assertThatThrownBy (
238
+ () -> actions .computeTableStats (table ).snapshot (snapshotId2 ).columns ("data" ).execute ())
239
+ .isInstanceOf (IllegalArgumentException .class )
240
+ .hasMessageStartingWith ("Can't find column data in table" );
262
241
}
263
242
264
243
@ TestTemplate
@@ -271,19 +250,17 @@ public void testComputeTableStatsWhenSnapshotIdNotSpecified()
271
250
SparkActions actions = SparkActions .get ();
272
251
ComputeTableStats .Result results = actions .computeTableStats (table ).columns ("data" ).execute ();
273
252
274
- assertNotNull (results );
253
+ assertThat (results ). isNotNull ( );
275
254
276
255
List <StatisticsFile > statisticsFiles = table .statisticsFiles ();
277
- Assertions . assertEquals (statisticsFiles . size (), 1 );
256
+ assertThat (statisticsFiles ). hasSize ( 1 );
278
257
279
258
StatisticsFile statisticsFile = statisticsFiles .get (0 );
280
- assertNotEquals (statisticsFile .fileSizeInBytes (), 0 );
281
- Assertions . assertEquals (statisticsFile .blobMetadata (). size (), 1 );
259
+ assertThat (statisticsFile .fileSizeInBytes ()). isGreaterThan ( 0 );
260
+ assertThat (statisticsFile .blobMetadata ()). hasSize ( 1 );
282
261
283
- BlobMetadata blobMetadata = statisticsFile .blobMetadata ().get (0 );
284
- Assertions .assertEquals (
285
- blobMetadata .properties ().get (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY ),
286
- String .valueOf (1 ));
262
+ assertThat (statisticsFile .blobMetadata ().get (0 ).properties ())
263
+ .containsEntry (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY , "1" );
287
264
}
288
265
289
266
@ TestTemplate
@@ -305,10 +282,10 @@ public void testComputeTableStatsWithNestedSchema()
305
282
306
283
tbl .refresh ();
307
284
List <StatisticsFile > statisticsFiles = tbl .statisticsFiles ();
308
- Assertions . assertEquals (statisticsFiles . size (), 1 );
285
+ assertThat (statisticsFiles ). hasSize ( 1 );
309
286
StatisticsFile statisticsFile = statisticsFiles .get (0 );
310
- assertNotEquals (statisticsFile .fileSizeInBytes (), 0 );
311
- Assertions . assertEquals (statisticsFile .blobMetadata (). size (), 1 );
287
+ assertThat (statisticsFile .fileSizeInBytes ()). isGreaterThan ( 0 );
288
+ assertThat (statisticsFile .blobMetadata ()). hasSize ( 1 );
312
289
}
313
290
314
291
@ TestTemplate
@@ -322,10 +299,9 @@ public void testComputeTableStatsWithNoComputableColumns() throws IOException {
322
299
323
300
table .refresh ();
324
301
SparkActions actions = SparkActions .get ();
325
- IllegalArgumentException exception =
326
- assertThrows (
327
- IllegalArgumentException .class , () -> actions .computeTableStats (table ).execute ());
328
- Assertions .assertEquals (exception .getMessage (), "No columns found to compute stats" );
302
+ assertThatThrownBy (() -> actions .computeTableStats (table ).execute ())
303
+ .isInstanceOf (IllegalArgumentException .class )
304
+ .hasMessage ("No columns found to compute stats" );
329
305
}
330
306
331
307
@ TestTemplate
@@ -386,18 +362,17 @@ public void testComputeTableStats(String columnName, String type)
386
362
table .refresh ();
387
363
ComputeTableStats .Result results =
388
364
actions .computeTableStats (table ).columns (columnName ).execute ();
389
- assertNotNull (results );
365
+ assertThat (results ). isNotNull ( );
390
366
391
367
List <StatisticsFile > statisticsFiles = table .statisticsFiles ();
392
- Assertions . assertEquals (statisticsFiles . size (), 1 );
368
+ assertThat (statisticsFiles ). hasSize ( 1 );
393
369
394
370
StatisticsFile statisticsFile = statisticsFiles .get (0 );
395
- assertNotEquals (statisticsFile .fileSizeInBytes (), 0 );
396
- Assertions . assertEquals (statisticsFile .blobMetadata (). size (), 1 );
371
+ assertThat (statisticsFile .fileSizeInBytes ()). isGreaterThan ( 0 );
372
+ assertThat (statisticsFile .blobMetadata ()). hasSize ( 1 );
397
373
398
- BlobMetadata blobMetadata = statisticsFile .blobMetadata ().get (0 );
399
- Assertions .assertNotNull (
400
- blobMetadata .properties ().get (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY ));
374
+ assertThat (statisticsFile .blobMetadata ().get (0 ).properties ())
375
+ .containsKey (APACHE_DATASKETCHES_THETA_V1_NDV_PROPERTY );
401
376
}
402
377
403
378
private GenericRecord createNestedRecord () {
0 commit comments