1919
2020package org .apache .hudi .client ;
2121
22- import org .apache .hudi .avro .model .HoodieClusteringPlan ;
23- import org .apache .hudi .avro .model .HoodieClusteringStrategy ;
2422import org .apache .hudi .client .embedded .EmbeddedTimelineService ;
2523import org .apache .hudi .common .config .HoodieMetadataConfig ;
26- import org .apache .hudi .common .data .HoodieData ;
2724import org .apache .hudi .common .data .HoodieData .HoodieDataCacheKey ;
2825import org .apache .hudi .common .model .HoodieRecord ;
2926import org .apache .hudi .common .model .HoodieTableType ;
30- import org .apache .hudi .common .model .WriteOperationType ;
3127import org .apache .hudi .common .table .HoodieTableConfig ;
3228import org .apache .hudi .common .table .HoodieTableMetaClient ;
33- import org .apache .hudi .common .table .timeline .HoodieInstant ;
3429import org .apache .hudi .common .table .timeline .InstantComparison ;
3530import org .apache .hudi .common .table .view .FileSystemViewStorageConfig ;
3631import org .apache .hudi .common .testutils .HoodieTestDataGenerator ;
37- import org .apache .hudi .common .util .ClusteringUtils ;
3832import org .apache .hudi .common .util .Option ;
39- import org .apache .hudi .common .util .collection .Pair ;
4033import org .apache .hudi .config .HoodieWriteConfig ;
4134import org .apache .hudi .data .HoodieJavaRDD ;
4235import org .apache .hudi .metadata .HoodieTableMetadata ;
43- import org .apache .hudi .table .HoodieTable ;
44- import org .apache .hudi .table .action .HoodieWriteMetadata ;
4536import org .apache .hudi .testutils .SparkClientFunctionalTestHarness ;
4637
4738import org .apache .avro .generic .GenericRecord ;
5142import org .junit .jupiter .params .provider .Arguments ;
5243import org .junit .jupiter .params .provider .CsvSource ;
5344import org .junit .jupiter .params .provider .MethodSource ;
54- import org .mockito .MockedStatic ;
5545
5646import java .io .IOException ;
5747import java .net .URI ;
58- import java .util .Arrays ;
5948import java .util .Collections ;
60- import java .util .HashMap ;
6149import java .util .List ;
62- import java .util .Map ;
6350import java .util .Properties ;
6451import java .util .stream .Collectors ;
6552import java .util .stream .Stream ;
6653
6754import static org .apache .hudi .common .testutils .HoodieTestDataGenerator .getCommitTimeAtUTC ;
68- import static org .apache .hudi .config .HoodieClusteringConfig .PLAN_STRATEGY_SORT_COLUMNS ;
6955import static org .apache .hudi .testutils .Assertions .assertNoWriteErrors ;
7056import static org .junit .jupiter .api .Assertions .assertEquals ;
7157import static org .junit .jupiter .api .Assertions .assertFalse ;
7258import static org .junit .jupiter .api .Assertions .assertTrue ;
73- import static org .mockito .ArgumentMatchers .any ;
74- import static org .mockito .Mockito .mock ;
75- import static org .mockito .Mockito .mockStatic ;
76- import static org .mockito .Mockito .when ;
7759
7860class TestSparkRDDWriteClient extends SparkClientFunctionalTestHarness {
7961
@@ -223,67 +205,6 @@ public void testCompletionTimeGreaterThanRequestedTime() throws IOException {
223205 testAndAssertCompletionIsEarlierThanRequested (basePath , props );
224206 }
225207
226- private static Stream <Arguments > streamingMetadataWritesTestArgs () {
227- return Arrays .stream (new Object [][] {
228- {"COMPACT" , "NONE" , false , false , false },
229- {"COMPACT" , "NONE" , true , false , false },
230- {"COMPACT" , "GLOBAL_SORT" , true , false , false },
231- {"COMPACT" , "GLOBAL_SORT" , false , false , false },
232- {"LOG_COMPACT" , "NONE" , true , false , false },
233- {"LOG_COMPACT" , "NONE" , false , false , false },
234- {"LOG_COMPACT" , "GLOBAL_SORT" , true , false , false },
235- {"LOG_COMPACT" , "GLOBAL_SORT" , false , false , false },
236- {"CLUSTER" , "NONE" , true , false , true },
237- {"CLUSTER" , "NONE" , false , false , true },
238- {"CLUSTER" , "GLOBAL_SORT" , true , false , false },
239- {"CLUSTER" , "GLOBAL_SORT" , false , false , false },
240- {"CLUSTER" , "NONE" , true , true , false },
241- {"CLUSTER" , "NONE" , false , true , true },
242- {"CLUSTER" , "GLOBAL_SORT" , true , true , false },
243- {"CLUSTER" , "GLOBAL_SORT" , false , true , false },
244- }).map (Arguments ::of );
245- }
246-
247- @ ParameterizedTest
248- @ MethodSource ("streamingMetadataWritesTestArgs" )
249- public void testStreamingMetadataWrites (WriteOperationType writeOperationType ,
250- String bulkInsertSortMode , boolean setSortColsinClusteringPlan ,
251- boolean setNonEmptyValueForSortcols ,
252- boolean expectedEnforceRepartitionWithCoalesce ) throws IOException {
253- HoodieTableMetaClient metaClient =
254- getHoodieMetaClient (storageConf (), URI .create (basePath ()).getPath (), new Properties ());
255- HoodieWriteConfig writeConfig = getConfigBuilder (true )
256- .withMetadataConfig (HoodieMetadataConfig .newBuilder ().enable (true ).withStreamingWriteEnabled (true ).build ())
257- .withBulkInsertSortMode (bulkInsertSortMode )
258- .withPath (metaClient .getBasePath ())
259- .build ();
260- MockStreamingMetadataWriteHandler mockMetadataWriteHandler = new MockStreamingMetadataWriteHandler ();
261-
262- try (MockedStatic <ClusteringUtils > mocked = mockStatic (ClusteringUtils .class );) {
263- HoodieClusteringPlan clusteringPlan = mock (HoodieClusteringPlan .class );
264- HoodieClusteringStrategy clusteringStrategy = mock (HoodieClusteringStrategy .class );
265- when (clusteringPlan .getStrategy ()).thenReturn (clusteringStrategy );
266- Map <String , String > strategyParams = new HashMap <>();
267- if (setSortColsinClusteringPlan ) {
268- strategyParams .put (PLAN_STRATEGY_SORT_COLUMNS .key (), setNonEmptyValueForSortcols ? "abc" : "" );
269- }
270- when (clusteringStrategy .getStrategyParams ()).thenReturn (strategyParams );
271-
272- HoodieInstant hoodieInstant = mock (HoodieInstant .class );
273- mocked .when (() -> ClusteringUtils .getClusteringPlan (any (), any ())).thenReturn (Option .of (Pair .of (hoodieInstant , clusteringPlan )));
274- mocked .when (() -> ClusteringUtils .getRequestedClusteringInstant (any (), any (), any ())).thenReturn (Option .of (hoodieInstant ));
275-
276- SparkRDDTableServiceClient tableServiceClient = new SparkRDDTableServiceClient (context (), writeConfig , Option .empty (), mockMetadataWriteHandler );
277- HoodieWriteMetadata <HoodieData <WriteStatus >> writeMetadata = mock (HoodieWriteMetadata .class );
278- HoodieData <WriteStatus > hoodieData = mock (HoodieData .class );
279- when (writeMetadata .getWriteStatuses ()).thenReturn (hoodieData );
280- HoodieTable table = mock (HoodieTable .class );
281- when (table .getMetaClient ()).thenReturn (metaClient );
282- tableServiceClient .partialUpdateTableMetadata (table , writeMetadata , "00001" , writeOperationType );
283- assertEquals (expectedEnforceRepartitionWithCoalesce , mockMetadataWriteHandler .enforceCoalesceWithRepartition );
284- }
285- }
286-
287208 private void testAndAssertCompletionIsEarlierThanRequested (String basePath , Properties properties ) throws IOException {
288209 HoodieTableMetaClient metaClient = getHoodieMetaClient (storageConf (), basePath , properties );
289210
@@ -303,19 +224,4 @@ private void testAndAssertCompletionIsEarlierThanRequested(String basePath, Prop
303224 assertTrue (InstantComparison .compareTimestamps (hoodieInstant .requestedTime (), InstantComparison .LESSER_THAN , hoodieInstant .getCompletionTime ()));
304225 });
305226 }
306-
307- class MockStreamingMetadataWriteHandler extends StreamingMetadataWriteHandler {
308-
309- boolean enforceCoalesceWithRepartition ;
310- int coalesceDivisorForDataTableWrites ;
311-
312- @ Override
313- public HoodieData <WriteStatus > streamWriteToMetadataTable (HoodieTable table , HoodieData <WriteStatus > dataTableWriteStatuses , String instantTime ,
314- boolean enforceCoalesceWithRepartition , int coalesceDivisorForDataTableWrites ) {
315- this .enforceCoalesceWithRepartition = enforceCoalesceWithRepartition ;
316- this .coalesceDivisorForDataTableWrites = coalesceDivisorForDataTableWrites ;
317- return dataTableWriteStatuses ;
318- }
319- }
320-
321227}
0 commit comments