From 47a6cca01343e4a671e588afbfbbb6901cd46a50 Mon Sep 17 00:00:00 2001 From: QiuMM Date: Fri, 28 Sep 2018 00:38:44 +0800 Subject: [PATCH] Add TimestampSpec format for microsecond (#6395) --- docs/content/ingestion/ingestion-spec.md | 2 +- .../druid/java/util/common/parsers/TimestampParser.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/content/ingestion/ingestion-spec.md b/docs/content/ingestion/ingestion-spec.md index 7978f6ff561..590ea30cd99 100644 --- a/docs/content/ingestion/ingestion-spec.md +++ b/docs/content/ingestion/ingestion-spec.md @@ -187,7 +187,7 @@ handle all formatting decisions on their own, without using the ParseSpec. | Field | Type | Description | Required | |-------|------|-------------|----------| | column | String | The column of the timestamp. | yes | -| format | String | iso, millis, posix, auto or any [Joda time](http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html) format. | no (default == 'auto' | +| format | String | iso, posix, millis, micro, nano, auto or any [Joda time](http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html) format. | no (default == 'auto' | ### DimensionsSpec diff --git a/java-util/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java b/java-util/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java index 38f12060942..ecd06f822f9 100644 --- a/java-util/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java +++ b/java-util/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java @@ -71,8 +71,9 @@ public class TimestampParser return DateTimes.of(ParserUtils.stripQuotes(input)); }; } else if ("posix".equalsIgnoreCase(format) - || "millis".equalsIgnoreCase(format) - || "nano".equalsIgnoreCase(format)) { + || "millis".equalsIgnoreCase(format) + || "micro".equalsIgnoreCase(format) + || "nano".equalsIgnoreCase(format)) { final Function numericFun = createNumericTimestampParser(format); return input -> { Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp"); @@ -104,6 +105,8 @@ public class TimestampParser { if ("posix".equalsIgnoreCase(format)) { return input -> DateTimes.utc(TimeUnit.SECONDS.toMillis(input.longValue())); + } else if ("micro".equalsIgnoreCase(format)) { + return input -> DateTimes.utc(TimeUnit.MICROSECONDS.toMillis(input.longValue())); } else if ("nano".equalsIgnoreCase(format)) { return input -> DateTimes.utc(TimeUnit.NANOSECONDS.toMillis(input.longValue())); } else if ("ruby".equalsIgnoreCase(format)) {