vinothchandar commented on a change in pull request #1834: URL: https://github.com/apache/hudi/pull/1834#discussion_r469400924
########## File path: hudi-client/src/test/java/org/apache/hudi/io/TestHoodieRowCreateHandle.java ########## @@ -0,0 +1,231 @@ +/* + * 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.HoodieInternalWriteStatus; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.model.HoodieWriteStat; +import org.apache.hudi.common.testutils.HoodieTestDataGenerator; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.exception.HoodieInsertException; +import org.apache.hudi.table.HoodieTable; +import org.apache.hudi.testutils.HoodieClientTestHarness; + +import org.apache.spark.sql.Dataset; +import org.apache.spark.sql.Row; +import org.apache.spark.sql.catalyst.InternalRow; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.UUID; + +import static org.apache.hudi.testutils.HoodieDatasetTestUtils.ENCODER; +import static org.apache.hudi.testutils.HoodieDatasetTestUtils.STRUCT_TYPE; +import static org.apache.hudi.testutils.HoodieDatasetTestUtils.getConfigBuilder; +import static org.apache.hudi.testutils.HoodieDatasetTestUtils.getInternalRowWithError; +import static org.apache.hudi.testutils.HoodieDatasetTestUtils.getRandomRows; +import static org.apache.hudi.testutils.HoodieDatasetTestUtils.toInternalRows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * Unit tests {@link HoodieRowCreateHandle}. + */ +public class TestHoodieRowCreateHandle extends HoodieClientTestHarness { + + private static final Random RANDOM = new Random(); + + @BeforeEach + public void setUp() throws Exception { + initSparkContexts("TestHoodieRowCreateHandle"); + initPath(); + initFileSystem(); + initTestDataGenerator(); + initMetaClient(); + } + + @AfterEach + public void tearDown() throws Exception { + cleanupResources(); + } + + @Test + public void testRowCreateHandle() throws IOException { + // init config and table + HoodieWriteConfig cfg = getConfigBuilder(basePath).build(); + HoodieTable table = HoodieTable.create(metaClient, cfg, hadoopConf); + List<String> fileNames = new ArrayList<>(); + List<String> fileAbsPaths = new ArrayList<>(); + + Dataset<Row> totalInputRows = null; + // one round per partition + for (int i = 0; i < 5; i++) { + String partitionPath = HoodieTestDataGenerator.DEFAULT_PARTITION_PATHS[i % 3]; + + // init some args + String fileId = UUID.randomUUID().toString(); + String instantTime = "000"; + + HoodieRowCreateHandle handle = new HoodieRowCreateHandle(table, cfg, partitionPath, fileId, instantTime, RANDOM.nextInt(100000), RANDOM.nextLong(), RANDOM.nextLong(), STRUCT_TYPE); + int size = 10 + RANDOM.nextInt(1000); + // Generate inputs + Dataset<Row> inputRows = getRandomRows(sqlContext, size, partitionPath, false); + if (totalInputRows == null) { + totalInputRows = inputRows; + } else { + totalInputRows = totalInputRows.union(inputRows); + } + + // issue writes + HoodieInternalWriteStatus writeStatus = writeAndGetWriteStatus(inputRows, handle); + + fileAbsPaths.add(basePath + "/" + writeStatus.getStat().getPath()); + fileNames.add(handle.getFileName()); + // verify output + assertOutput(writeStatus, size, fileId, partitionPath, instantTime, totalInputRows, fileNames, fileAbsPaths); + } + } + + /** + * Issue some corrupted or wrong schematized InternalRow after few valid InternalRows so that global error is thrown. write batch 1 of valid records write batch 2 of invalid records Global Error + * should be thrown. + */ + @Test + public void testGlobalFailure() throws IOException { Review comment: @nsivabalan is there a jira tracking this? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
