1
0

[HUDI-324] TimestampKeyGenerator should support milliseconds (#993)

This commit is contained in:
Gurudatt Kulkarni
2019-11-05 17:52:14 +05:30
committed by vinoth chandar
parent 04834817c8
commit 71ac2c0d5e

View File

@@ -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);
}