Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Deprecate use of scientific notation in epoch time parsing #36691

Merged
merged 4 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions server/src/main/java/org/elasticsearch/common/joda/Joda.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.io.Writer;
import java.math.BigDecimal;
import java.util.Locale;
import java.util.regex.Pattern;

public class Joda {

Expand Down Expand Up @@ -321,6 +322,8 @@ public DateTimeField getField(Chronology chronology) {

public static class EpochTimeParser implements DateTimeParser {

private static final Pattern scientificNotation = Pattern.compile("[Ee]");

private final boolean hasMilliSecondPrecision;

public EpochTimeParser(boolean hasMilliSecondPrecision) {
Expand Down Expand Up @@ -348,6 +351,11 @@ public int parseInto(DateTimeParserBucket bucket, String text, int position) {
int factor = hasMilliSecondPrecision ? 1 : 1000;
try {
long millis = new BigDecimal(text).longValue() * factor;
// check for deprecation, but after it has parsed correctly so the "e" isn't from something else
if (scientificNotation.matcher(text).find()) {
deprecationLogger.deprecatedAndMaybeLog("epoch-scientific-notation", "Use of scientific notation" +
"in epoch time formats is deprecated and will not be supported in the next major version of Elasticsearch.");
}
DateTime dt = new DateTime(millis, DateTimeZone.UTC);
bucket.saveField(DateTimeFieldType.year(), dt.getYear());
bucket.saveField(DateTimeFieldType.monthOfYear(), dt.getMonthOfYear());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ public void testDuellingFormatsValidParsing() {
assertSameDate("1", "epoch_second");
assertSameDate("-1", "epoch_second");
assertSameDate("-1522332219", "epoch_second");
assertSameDate("1.0e3", "epoch_second");
assertSameDate("1522332219321", "epoch_millis");
assertSameDate("0", "epoch_millis");
assertSameDate("1", "epoch_millis");
assertSameDate("-1", "epoch_millis");
assertSameDate("-1522332219321", "epoch_millis");
assertSameDate("1.0e3", "epoch_millis");

assertSameDate("20181126", "basic_date");
assertSameDate("20181126T121212.123Z", "basic_date_time");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,15 @@ public void testDeprecatedFormatSpecifiers() {
" next major version of Elasticsearch. Prefix your date format with '8' to use the new specifier.");
}

public void testDeprecatedScientificNotation() {
assertValidDateFormatParsing("epoch_second", "1.234e5", "123400");
assertWarnings("Use of scientific notation" +
"in epoch time formats is deprecated and will not be supported in the next major version of Elasticsearch.");
assertValidDateFormatParsing("epoch_millis", "1.234e5", "123400");
assertWarnings("Use of scientific notation" +
"in epoch time formats is deprecated and will not be supported in the next major version of Elasticsearch.");
}

private void assertValidDateFormatParsing(String pattern, String dateToParse) {
assertValidDateFormatParsing(pattern, dateToParse, dateToParse);
}
Expand Down