You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:25:13 UTC

[GitHub] [hudi] xushiyan opened a new pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

xushiyan opened a new pull request #1884:
URL: https://github.com/apache/hudi/pull/1884


   There are testutils functions scattered around in different modules (client, spark, common) for common transformations like HoodieRecords to HoodieKeys. This is to organize them in `Transformations.java` for ease of discovery and use.
   
   ## Changes
   
   - Consolidate transform functions for tests in Transformations.java
   - Consolidate assertion functions for tests in Assertions.java
   - Make use of SchemaTestUtil for loading schema from resource
   
   ## Committer checklist
   
    - [ ] Has a corresponding JIRA in PR title & commit
    
    - [ ] Commit message is descriptive of the change
    
    - [ ] CI is green
   
    - [ ] Necessary doc changes done or have another open PR
          
    - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] xushiyan commented on a change in pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
xushiyan commented on a change in pull request #1884:
URL: https://github.com/apache/hudi/pull/1884#discussion_r463355509



##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/SchemaTestUtil.java
##########
@@ -66,24 +68,24 @@ public static Schema getSimpleSchema() throws IOException {
       throws IOException, URISyntaxException {
     GenericDatumReader<IndexedRecord> reader = new GenericDatumReader<>(writerSchema, readerSchema);
     // Required to register the necessary JAR:// file system
-    URI resource = SchemaTestUtil.class.getClass().getResource("/sample.data").toURI();
+    URI resource = SchemaTestUtil.class.getResource(RESOURCE_SAMPLE_DATA).toURI();
     Path dataPath;
     if (resource.toString().contains("!")) {
       dataPath = uriToPath(resource);
     } else {
-      dataPath = Paths.get(SchemaTestUtil.class.getClass().getResource("/sample.data").toURI());
+      dataPath = Paths.get(SchemaTestUtil.class.getResource(RESOURCE_SAMPLE_DATA).toURI());
     }
 
     try (Stream<String> stream = Files.lines(dataPath)) {
       return stream.skip(from).limit(limit).map(s -> {
         try {
           return reader.read(null, DecoderFactory.get().jsonDecoder(writerSchema, s));
         } catch (IOException e) {
-          throw new HoodieIOException("Could not read data from simple_data.json", e);
+          throw new HoodieIOException("Could not read data from " + RESOURCE_SAMPLE_DATA, e);

Review comment:
       yea "simple_data.json" does not exist.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] xushiyan commented on a change in pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
xushiyan commented on a change in pull request #1884:
URL: https://github.com/apache/hudi/pull/1884#discussion_r462674786



##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/Transformations.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.common.testutils;
+
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Common transformations in test cases.
+ */
+public final class Transformations {
+
+  public static <T> List<T> flatten(Iterator<List<T>> iteratorOfLists) {
+    List<T> flattened = new ArrayList<>();
+    iteratorOfLists.forEachRemaining(flattened::addAll);
+    return flattened;
+  }
+
+  public static <T> Iterator<T> flattenAsIterator(Iterator<List<T>> iteratorOfLists) {
+    return flatten(iteratorOfLists).iterator();
+  }
+
+  public static Set<String> recordsToRecordKeySet(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getRecordKey).collect(Collectors.toSet());
+  }
+
+  public static List<HoodieKey> recordsToHoodieKeys(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getKey).collect(Collectors.toList());
+  }
+
+  public static List<String> hoodieKeysToStrings(List<HoodieKey> keys) {

Review comment:
       make sense.. as this is only used by `HoodieJavaApp#run` and specific to its own logic, let's put it there for its own usage? 

##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/Transformations.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.common.testutils;
+
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Common transformations in test cases.
+ */
+public final class Transformations {
+
+  public static <T> List<T> flatten(Iterator<List<T>> iteratorOfLists) {
+    List<T> flattened = new ArrayList<>();
+    iteratorOfLists.forEachRemaining(flattened::addAll);
+    return flattened;
+  }
+
+  public static <T> Iterator<T> flattenAsIterator(Iterator<List<T>> iteratorOfLists) {
+    return flatten(iteratorOfLists).iterator();
+  }
+
+  public static Set<String> recordsToRecordKeySet(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getRecordKey).collect(Collectors.toSet());
+  }
+
+  public static List<HoodieKey> recordsToHoodieKeys(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getKey).collect(Collectors.toList());
+  }
+
+  public static List<String> hoodieKeysToStrings(List<HoodieKey> keys) {
+    return keys.stream()
+        .map(hr -> "{\"_row_key\":\"" + hr.getRecordKey() + "\",\"partition\":\"" + hr.getPartitionPath() + "\"}")
+        .collect(Collectors.toList());
+  }
+
+  public static List<String> recordsToStrings(List<HoodieRecord> records) {
+    return records.stream().map(Transformations::recordToString).filter(Option::isPresent).map(Option::get)
+        .collect(Collectors.toList());
+  }
+
+  public static Option<String> recordToString(HoodieRecord record) {

Review comment:
       this method and `Transformations#recordsToStrings` work for HoodieRecord of `RawTripTestPayload`, how about moving them to RawTripTestPayload.java?

##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/SchemaTestUtil.java
##########
@@ -66,12 +66,12 @@ public static Schema getSimpleSchema() throws IOException {
       throws IOException, URISyntaxException {
     GenericDatumReader<IndexedRecord> reader = new GenericDatumReader<>(writerSchema, readerSchema);
     // Required to register the necessary JAR:// file system
-    URI resource = SchemaTestUtil.class.getClass().getResource("/sample.data").toURI();
+    URI resource = SchemaTestUtil.class.getResource("/sample.data").toURI();

Review comment:
       yup fixing it




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] yanghua merged pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
yanghua merged pull request #1884:
URL: https://github.com/apache/hudi/pull/1884


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] xushiyan commented on a change in pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
xushiyan commented on a change in pull request #1884:
URL: https://github.com/apache/hudi/pull/1884#discussion_r462017090



##########
File path: hudi-spark/src/test/java/org/apache/hudi/testutils/DataSourceTestUtils.java
##########
@@ -1,71 +0,0 @@
-/*
- * 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.testutils;
-
-import org.apache.hudi.common.model.HoodieKey;
-import org.apache.hudi.common.model.HoodieRecord;
-import org.apache.hudi.common.model.HoodieRecordPayload;
-import org.apache.hudi.common.testutils.RawTripTestPayload;
-import org.apache.hudi.common.util.Option;
-import org.apache.hudi.table.UserDefinedBulkInsertPartitioner;
-
-import org.apache.spark.api.java.JavaRDD;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * Test utils for data source tests.
- */
-public class DataSourceTestUtils {

Review comment:
       all methods moved to `Transformations.java`

##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/Transformations.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.common.testutils;
+
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Common transformations in test cases.
+ */
+public final class Transformations {
+
+  public static <T> List<T> flatten(Iterator<List<T>> iteratorOfLists) {
+    List<T> flattened = new ArrayList<>();
+    iteratorOfLists.forEachRemaining(flattened::addAll);
+    return flattened;
+  }
+
+  public static <T> Iterator<T> flattenAsIterator(Iterator<List<T>> iteratorOfLists) {
+    return flatten(iteratorOfLists).iterator();
+  }
+
+  public static Set<String> recordsToRecordKeySet(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getRecordKey).collect(Collectors.toSet());
+  }
+
+  public static List<HoodieKey> recordsToHoodieKeys(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getKey).collect(Collectors.toList());
+  }
+
+  public static List<String> hoodieKeysToStrings(List<HoodieKey> keys) {
+    return keys.stream()
+        .map(hr -> "{\"_row_key\":\"" + hr.getRecordKey() + "\",\"partition\":\"" + hr.getPartitionPath() + "\"}")
+        .collect(Collectors.toList());
+  }
+
+  public static List<String> recordsToStrings(List<HoodieRecord> records) {
+    return records.stream().map(Transformations::recordToString).filter(Option::isPresent).map(Option::get)
+        .collect(Collectors.toList());
+  }
+
+  public static Option<String> recordToString(HoodieRecord record) {
+    try {
+      String str = ((RawTripTestPayload) record.getData()).getJsonData();
+      str = "{" + str.substring(str.indexOf("\"timestamp\":"));
+      // Remove the last } bracket
+      str = str.substring(0, str.length() - 1);
+      return Option.of(str + ", \"partition\": \"" + record.getPartitionPath() + "\"}");
+    } catch (IOException e) {
+      return Option.empty();
+    }
+  }
+
+  /**
+   * Pseudorandom: select even indices first, then select odd ones.
+   */
+  public static <T> List<T> randomSelect(List<T> items, int n) {

Review comment:
       IMO not needing real randomness for caller's scenario

##########
File path: hudi-common/src/test/java/org/apache/hudi/common/table/timeline/TestHoodieActiveTimeline.java
##########
@@ -94,17 +94,19 @@ public void testLoadingInstantsFromFiles() throws IOException {
     timeline = timeline.reload();
 
     assertEquals(5, timeline.countInstants(), "Total instants should be 5");
-    HoodieTestUtils.assertStreamEquals("Check the instants stream",
+    assertStreamEquals(

Review comment:
       moving message arg to the last, align with junit API style




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] yanghua commented on a change in pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1884:
URL: https://github.com/apache/hudi/pull/1884#discussion_r462669484



##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/Transformations.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.common.testutils;
+
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Common transformations in test cases.
+ */
+public final class Transformations {
+
+  public static <T> List<T> flatten(Iterator<List<T>> iteratorOfLists) {
+    List<T> flattened = new ArrayList<>();
+    iteratorOfLists.forEachRemaining(flattened::addAll);
+    return flattened;
+  }
+
+  public static <T> Iterator<T> flattenAsIterator(Iterator<List<T>> iteratorOfLists) {
+    return flatten(iteratorOfLists).iterator();
+  }
+
+  public static Set<String> recordsToRecordKeySet(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getRecordKey).collect(Collectors.toSet());
+  }
+
+  public static List<HoodieKey> recordsToHoodieKeys(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getKey).collect(Collectors.toList());
+  }
+
+  public static List<String> hoodieKeysToStrings(List<HoodieKey> keys) {
+    return keys.stream()
+        .map(hr -> "{\"_row_key\":\"" + hr.getRecordKey() + "\",\"partition\":\"" + hr.getPartitionPath() + "\"}")
+        .collect(Collectors.toList());
+  }
+
+  public static List<String> recordsToStrings(List<HoodieRecord> records) {
+    return records.stream().map(Transformations::recordToString).filter(Option::isPresent).map(Option::get)
+        .collect(Collectors.toList());
+  }
+
+  public static Option<String> recordToString(HoodieRecord record) {

Review comment:
       ditto

##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/Transformations.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.common.testutils;
+
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Common transformations in test cases.
+ */
+public final class Transformations {
+
+  public static <T> List<T> flatten(Iterator<List<T>> iteratorOfLists) {
+    List<T> flattened = new ArrayList<>();
+    iteratorOfLists.forEachRemaining(flattened::addAll);
+    return flattened;
+  }
+
+  public static <T> Iterator<T> flattenAsIterator(Iterator<List<T>> iteratorOfLists) {
+    return flatten(iteratorOfLists).iterator();
+  }
+
+  public static Set<String> recordsToRecordKeySet(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getRecordKey).collect(Collectors.toSet());
+  }
+
+  public static List<HoodieKey> recordsToHoodieKeys(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getKey).collect(Collectors.toList());
+  }
+
+  public static List<String> hoodieKeysToStrings(List<HoodieKey> keys) {

Review comment:
       Considering `_row_key` is not a generic definition. IMO, we should put this method into a util class. The `xxxs` class should be more generic. WDYT?

##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/SchemaTestUtil.java
##########
@@ -66,12 +66,12 @@ public static Schema getSimpleSchema() throws IOException {
       throws IOException, URISyntaxException {
     GenericDatumReader<IndexedRecord> reader = new GenericDatumReader<>(writerSchema, readerSchema);
     // Required to register the necessary JAR:// file system
-    URI resource = SchemaTestUtil.class.getClass().getResource("/sample.data").toURI();
+    URI resource = SchemaTestUtil.class.getResource("/sample.data").toURI();

Review comment:
       It would be better to extract those file names into constant fields in this file. WDYT?

##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/Transformations.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.common.testutils;
+
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Common transformations in test cases.
+ */
+public final class Transformations {
+
+  public static <T> List<T> flatten(Iterator<List<T>> iteratorOfLists) {
+    List<T> flattened = new ArrayList<>();
+    iteratorOfLists.forEachRemaining(flattened::addAll);
+    return flattened;
+  }
+
+  public static <T> Iterator<T> flattenAsIterator(Iterator<List<T>> iteratorOfLists) {
+    return flatten(iteratorOfLists).iterator();
+  }
+
+  public static Set<String> recordsToRecordKeySet(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getRecordKey).collect(Collectors.toSet());
+  }
+
+  public static List<HoodieKey> recordsToHoodieKeys(List<HoodieRecord> records) {
+    return records.stream().map(HoodieRecord::getKey).collect(Collectors.toList());
+  }
+
+  public static List<String> hoodieKeysToStrings(List<HoodieKey> keys) {
+    return keys.stream()
+        .map(hr -> "{\"_row_key\":\"" + hr.getRecordKey() + "\",\"partition\":\"" + hr.getPartitionPath() + "\"}")
+        .collect(Collectors.toList());
+  }
+
+  public static List<String> recordsToStrings(List<HoodieRecord> records) {
+    return records.stream().map(Transformations::recordToString).filter(Option::isPresent).map(Option::get)
+        .collect(Collectors.toList());
+  }
+
+  public static Option<String> recordToString(HoodieRecord record) {

Review comment:
       Sounds good.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] yanghua commented on a change in pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1884:
URL: https://github.com/apache/hudi/pull/1884#discussion_r463351355



##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/SchemaTestUtil.java
##########
@@ -66,24 +68,24 @@ public static Schema getSimpleSchema() throws IOException {
       throws IOException, URISyntaxException {
     GenericDatumReader<IndexedRecord> reader = new GenericDatumReader<>(writerSchema, readerSchema);
     // Required to register the necessary JAR:// file system
-    URI resource = SchemaTestUtil.class.getClass().getResource("/sample.data").toURI();
+    URI resource = SchemaTestUtil.class.getResource(RESOURCE_SAMPLE_DATA).toURI();
     Path dataPath;
     if (resource.toString().contains("!")) {
       dataPath = uriToPath(resource);
     } else {
-      dataPath = Paths.get(SchemaTestUtil.class.getClass().getResource("/sample.data").toURI());
+      dataPath = Paths.get(SchemaTestUtil.class.getResource(RESOURCE_SAMPLE_DATA).toURI());
     }
 
     try (Stream<String> stream = Files.lines(dataPath)) {
       return stream.skip(from).limit(limit).map(s -> {
         try {
           return reader.read(null, DecoderFactory.get().jsonDecoder(writerSchema, s));
         } catch (IOException e) {
-          throw new HoodieIOException("Could not read data from simple_data.json", e);
+          throw new HoodieIOException("Could not read data from " + RESOURCE_SAMPLE_DATA, e);

Review comment:
       Is the old `simple_data.json` not correct, right?

##########
File path: hudi-client/src/test/java/org/apache/hudi/index/bloom/TestHoodieBloomIndex.java
##########
@@ -73,9 +72,7 @@
 
 public class TestHoodieBloomIndex extends HoodieClientTestHarness {
 
-  private String schemaStr;
-  private Schema schema;
-
+  private static final Schema SCHEMA = getSchemaFromResource(TestHoodieGlobalBloomIndex.class, "/exampleSchema.txt", true);

Review comment:
       May it be `TestHoodieBloomIndex.class`?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] xushiyan commented on a change in pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
xushiyan commented on a change in pull request #1884:
URL: https://github.com/apache/hudi/pull/1884#discussion_r463355428



##########
File path: hudi-client/src/test/java/org/apache/hudi/index/bloom/TestHoodieBloomIndex.java
##########
@@ -73,9 +72,7 @@
 
 public class TestHoodieBloomIndex extends HoodieClientTestHarness {
 
-  private String schemaStr;
-  private Schema schema;
-
+  private static final Schema SCHEMA = getSchemaFromResource(TestHoodieGlobalBloomIndex.class, "/exampleSchema.txt", true);

Review comment:
       fixed.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] xushiyan commented on pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
xushiyan commented on pull request #1884:
URL: https://github.com/apache/hudi/pull/1884#issuecomment-667458092


   @yanghua rebased and resolved conflicts. thanks


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] xushiyan commented on pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
xushiyan commented on pull request #1884:
URL: https://github.com/apache/hudi/pull/1884#issuecomment-665350793


   @yanghua @vinothchandar This is another set of incremental changes for testutils re-organization.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] xushiyan commented on pull request #1884: [HUDI-995] Use Transformations, Assertions and SchemaTestUtil

Posted by GitBox <gi...@apache.org>.
xushiyan commented on pull request #1884:
URL: https://github.com/apache/hudi/pull/1884#issuecomment-666028265


   @yanghua address the comments in the last 2 commits. thanks.


----------------------------------------------------------------
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:
users@infra.apache.org