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/12/16 11:48:03 UTC

[GitHub] [hudi] wangxianghu commented on a change in pull request #2340: [MINOR] Make QuickstartUtil generate random timestamp instead of 0

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



##########
File path: hudi-spark-datasource/hudi-spark/src/main/java/org/apache/hudi/QuickstartUtils.java
##########
@@ -121,11 +121,23 @@ public static GenericRecord generateGenericRecord(String rowKey, String riderNam
      */
     public static OverwriteWithLatestAvroPayload generateRandomValue(HoodieKey key, String riderDriverSuffix)
         throws IOException {
+      // The timestamp generated is limited to range from 7 days before to now, to avoid generating too many
+      // partitionPaths when user use timestamp as partitionPath filed.
       GenericRecord rec =
-          generateGenericRecord(key.getRecordKey(), "rider-" + riderDriverSuffix, "driver-" + riderDriverSuffix, 0);
+          generateGenericRecord(key.getRecordKey(), "rider-" + riderDriverSuffix,"driver-"
+              + riderDriverSuffix, generateRangeRandomTimestamp(7));
       return new OverwriteWithLatestAvroPayload(Option.of(rec));
     }
 
+    /**
+     * Generate timestamp range from {@param daysTillNow} before to now.
+     */
+    private static long generateRangeRandomTimestamp(int daysTillNow) {
+      long now = System.currentTimeMillis();
+      long daysBefore = now - daysTillNow * 24 * 60 * 60 * 1000L;
+      return daysBefore + (long)(Math.random() * (now - daysBefore));

Review comment:
       > It's not good for reading. `now - daysBefore ` = `now - (now - daysTillNow * 24 * 60 * 60 * 1000L)`?
   
   how about this
   ```
       private static long generateRangeRandomTimestamp(int daysTillNow) {
         long interval = daysTillNow * 24 * 60 * 60 * 1000L;
         return System.currentTimeMillis() - (long)(Math.random() * interval);
       }
   ```




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