nsivabalan commented on code in PR #13286: URL: https://github.com/apache/hudi/pull/13286#discussion_r2121941486
########## hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/io/TestMetadataWriterCommit.java: ########## @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hudi.io; + +import org.apache.hudi.client.WriteStatus; +import org.apache.hudi.common.config.HoodieMetadataConfig; +import org.apache.hudi.common.data.HoodieData; +import org.apache.hudi.common.model.HoodieCommitMetadata; +import org.apache.hudi.common.model.HoodieFailedWritesCleaningPolicy; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.model.HoodieWriteStat; +import org.apache.hudi.common.model.WriteOperationType; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.view.FileSystemViewStorageConfig; +import org.apache.hudi.common.testutils.HoodieTestDataGenerator; +import org.apache.hudi.common.testutils.InProcessTimeGenerator; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.data.HoodieJavaRDD; +import org.apache.hudi.metadata.HoodieBackedTableMetadataWriter; +import org.apache.hudi.metadata.SparkMetadataWriterFactory; +import org.apache.hudi.storage.StoragePath; +import org.apache.hudi.table.HoodieSparkTable; +import org.apache.hudi.table.HoodieTable; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +import static org.apache.hudi.common.testutils.HoodieTestDataGenerator.TRIP_EXAMPLE_SCHEMA; +import static org.apache.hudi.metadata.MetadataPartitionType.RECORD_INDEX; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Unit tests {@link HoodieCreateHandle}. + */ +public class TestMetadataWriterCommit extends BaseTestHandle { + + @Test + public void testCreateHandleRLIStats() throws IOException { + // init config and table + HoodieWriteConfig config = getConfigBuilder(basePath) + .withFileSystemViewConfig(FileSystemViewStorageConfig.newBuilder().withRemoteServerPort(timelineServicePort).build()) + .withMetadataConfig(HoodieMetadataConfig.newBuilder() + .enable(true) + .withEnableRecordIndex(true) + .withMetadataIndexColumnStats(false) + .withSecondaryIndexEnabled(false) + .build()) + .build(); + + HoodieTable table = HoodieSparkTable.create(config, context, metaClient); + + // one round per partition + String partitionPath = HoodieTestDataGenerator.DEFAULT_PARTITION_PATHS[0]; + + // init some args + String fileId = UUID.randomUUID().toString(); + String instantTime = InProcessTimeGenerator.createNewInstantTime(); + + // create a parquet file and obtain corresponding write status + config.setSchema(TRIP_EXAMPLE_SCHEMA); + HoodieTestDataGenerator dataGenerator = new HoodieTestDataGenerator(new String[] {partitionPath}); + Pair<WriteStatus, List<HoodieRecord>> statusListPair = createParquetFile(config, table, partitionPath, fileId, instantTime, dataGenerator); + WriteStatus writeStatus = statusListPair.getLeft(); + List<HoodieRecord> records = statusListPair.getRight(); + HoodieCommitMetadata commitMetadata = createCommitMetadata(writeStatus.getStat(), partitionPath); + + assertEquals(records.size(), writeStatus.getTotalRecords()); + assertEquals(0, writeStatus.getTotalErrorRecords()); + + // create mdt writer + HoodieBackedTableMetadataWriter mdtWriter = (HoodieBackedTableMetadataWriter) SparkMetadataWriterFactory.createWithStreamingWrites(storageConf, config, + HoodieFailedWritesCleaningPolicy.LAZY, context, Option.empty()); + HoodieTableMetaClient mdtMetaClient = HoodieTableMetaClient.builder().setBasePath(metaClient.getMetaPath() + "/metadata").setConf(storageConf).build(); + assertEquals(2, mdtMetaClient.getActiveTimeline().filterCompletedInstants().countInstants()); + + // Create commit in MDT + mdtWriter.startCommit(instantTime); + HoodieData<WriteStatus> mdtWriteStatus = mdtWriter.streamWriteToMetadataPartitions(HoodieJavaRDD.of(Collections.singletonList(writeStatus), context, 1), instantTime); + List<HoodieWriteStat> mdtWriteStats = mdtWriteStatus.collectAsList().stream().map(WriteStatus::getStat).collect(Collectors.toList()); + mdtWriter.completeStreamingCommit(instantTime, context, mdtWriteStats, commitMetadata); Review Comment: understand where FILES partition are invoked. -- 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]
