Core: Deprecate use of scientific notation in epoch time parsing (#36691)
The joda epoch parsing code currently supports passing epoch time as a number in scientific notation. However, no systems appear to exist which output timestamps in scientific notation. In java time, it is particularly complex to implement scientific notation timestamp parsing within a DateTimeFormatter. This commit adds a deprecation warning when the epoch time parsers in joda parse scientific notation, so that it can be removed when switching to java time. joda are passed a time in scientific notation.
This commit is contained in:
parent
e294056bbf
commit
0b22ca3a0f
|
@ -47,6 +47,7 @@ import java.io.IOException;
|
|||
import java.io.Writer;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Joda {
|
||||
|
||||
|
@ -321,6 +322,8 @@ public class Joda {
|
|||
|
||||
public static class EpochTimeParser implements DateTimeParser {
|
||||
|
||||
private static final Pattern scientificNotation = Pattern.compile("[Ee]");
|
||||
|
||||
private final boolean hasMilliSecondPrecision;
|
||||
|
||||
public EpochTimeParser(boolean hasMilliSecondPrecision) {
|
||||
|
@ -348,6 +351,11 @@ public class Joda {
|
|||
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());
|
||||
|
|
|
@ -77,13 +77,11 @@ public class JavaJodaTimeDuellingTests extends ESTestCase {
|
|||
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");
|
||||
|
|
|
@ -753,6 +753,15 @@ public class SimpleJodaTests extends ESTestCase {
|
|||
" 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue