You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by vi...@apache.org on 2019/11/05 12:22:26 UTC

[incubator-hudi] branch master updated: [HUDI-324] TimestampKeyGenerator should support milliseconds (#993)

This is an automated email from the ASF dual-hosted git repository.

vinoth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new 71ac2c0  [HUDI-324] TimestampKeyGenerator should support milliseconds (#993)
71ac2c0 is described below

commit 71ac2c0d5e8bffdbb11f7789a7805575736049c1
Author: Gurudatt Kulkarni <Gu...@users.noreply.github.com>
AuthorDate: Tue Nov 5 17:52:14 2019 +0530

    [HUDI-324] TimestampKeyGenerator should support milliseconds (#993)
---
 .../org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java b/hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java
index bb6802f..5d0bae2 100644
--- a/hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java
+++ b/hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java
@@ -39,7 +39,7 @@ import org.apache.hudi.utilities.exception.HoodieDeltaStreamerException;
 public class TimestampBasedKeyGenerator extends SimpleKeyGenerator {
 
   enum TimestampType implements Serializable {
-    UNIX_TIMESTAMP, DATE_STRING, MIXED
+    UNIX_TIMESTAMP, DATE_STRING, MIXED, EPOCHMILLISECONDS
   }
 
   private final TimestampType timestampType;
@@ -97,9 +97,10 @@ public class TimestampBasedKeyGenerator extends SimpleKeyGenerator {
         throw new HoodieNotSupportedException(
             "Unexpected type for partition field: " + partitionVal.getClass().getName());
       }
+      Date timestamp = this.timestampType == TimestampType.EPOCHMILLISECONDS ? new Date(unixTime) : new Date(unixTime * 1000);
 
       return new HoodieKey(DataSourceUtils.getNestedFieldValAsString(record, recordKeyField),
-          partitionPathFormat.format(new Date(unixTime * 1000)));
+          partitionPathFormat.format(timestamp));
     } catch (ParseException pe) {
       throw new HoodieDeltaStreamerException("Unable to parse input partition field :" + partitionVal, pe);
     }