wangxianghu commented on a change in pull request #2505:
URL: https://github.com/apache/hudi/pull/2505#discussion_r566572544



##########
File path: 
hudi-spark-datasource/hudi-spark/src/main/java/org/apache/hudi/QuickstartUtils.java
##########
@@ -176,14 +175,17 @@ public HoodieRecord generateUpdateRecord(HoodieKey key, 
String randomString) thr
      * @return list of hoodie record updates
      */
     public List<HoodieRecord> generateUpdates(Integer n) throws IOException {
-      String randomString = generateRandomString();
-      List<HoodieRecord> updates = new ArrayList<>();
-      for (int i = 0; i < n; i++) {
-        HoodieKey key = existingKeys.get(rand.nextInt(numExistingKeys));
-        HoodieRecord record = generateUpdateRecord(key, randomString);
-        updates.add(record);
+      if (numExistingKeys == 0) {
+        throw new IllegalArgumentException("Data must have been written before 
performing the update operation");

Review comment:
       can we throws `HoodieException` here

##########
File path: 
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/TestQuickstartUtils.java
##########
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@ExtendWith(MockitoExtension.class)
+public class TestQuickstartUtils {
+
+  @Test
+  public void testGenerateUpdates() throws Exception {
+    QuickstartUtils.DataGenerator dataGenerator = new 
QuickstartUtils.DataGenerator();
+    assertEquals(dataGenerator.generateInserts(10).size(), 10);
+    assertEquals(dataGenerator.generateUpdates(10).size(), 10);

Review comment:
       is is possible to add a test against the case where exception is thrown ?




----------------------------------------------------------------
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]


Reply via email to