mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-22 21:05:23 +00:00
Camel case date formats are deprecated and snake case should be used instead. backports #59555
This commit is contained in:
parent
e37bfe8a5f
commit
19fe3e511f
@ -386,12 +386,12 @@ public class NestedIT extends ESIntegTestCase {
|
||||
.startObject("dates")
|
||||
.field("type", "object")
|
||||
.startObject("properties")
|
||||
.startObject("day").field("type", "date").field("format", "dateOptionalTime").endObject()
|
||||
.startObject("day").field("type", "date").field("format", "date_optional_time").endObject()
|
||||
.startObject("month")
|
||||
.field("type", "object")
|
||||
.startObject("properties")
|
||||
.startObject("end").field("type", "date").field("format", "dateOptionalTime").endObject()
|
||||
.startObject("start").field("type", "date").field("format", "dateOptionalTime").endObject()
|
||||
.startObject("end").field("type", "date").field("format", "date_optional_time").endObject()
|
||||
.startObject("start").field("type", "date").field("format", "date_optional_time").endObject()
|
||||
.startObject("label").field("type", "keyword").endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
|
@ -608,7 +608,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
.field("long_field", 4L)
|
||||
.field("float_field", 5.0f)
|
||||
.field("double_field", 6.0d)
|
||||
.field("date_field", DateFormatter.forPattern("dateOptionalTime").format(date))
|
||||
.field("date_field", DateFormatter.forPattern("date_optional_time").format(date))
|
||||
.field("boolean_field", true)
|
||||
.field("binary_field", Base64.getEncoder().encodeToString("testing text".getBytes("UTF-8")))
|
||||
.endObject()).get();
|
||||
@ -640,7 +640,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
assertThat(searchHit.getFields().get("long_field").getValue(), equalTo((Object) 4L));
|
||||
assertThat(searchHit.getFields().get("float_field").getValue(), equalTo((Object) 5.0f));
|
||||
assertThat(searchHit.getFields().get("double_field").getValue(), equalTo((Object) 6.0d));
|
||||
String dateTime = DateFormatter.forPattern("dateOptionalTime").format(date);
|
||||
String dateTime = DateFormatter.forPattern("date_optional_time").format(date);
|
||||
assertThat(searchHit.getFields().get("date_field").getValue(), equalTo((Object) dateTime));
|
||||
assertThat(searchHit.getFields().get("boolean_field").getValue(), equalTo((Object) Boolean.TRUE));
|
||||
assertThat(searchHit.getFields().get("binary_field").getValue(), equalTo(new BytesArray("testing text" .getBytes("UTF8"))));
|
||||
@ -818,7 +818,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
.field("long_field", 4L)
|
||||
.field("float_field", 5.0f)
|
||||
.field("double_field", 6.0d)
|
||||
.field("date_field", DateFormatter.forPattern("dateOptionalTime").format(date))
|
||||
.field("date_field", DateFormatter.forPattern("date_optional_time").format(date))
|
||||
.field("boolean_field", true)
|
||||
.field("binary_field", new byte[] {42, 100})
|
||||
.field("ip_field", "::1")
|
||||
@ -855,7 +855,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("float_field").getValue(), equalTo((Object) 5.0));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("double_field").getValue(), equalTo((Object) 6.0d));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("date_field").getValue(),
|
||||
equalTo(DateFormatter.forPattern("dateOptionalTime").format(date)));
|
||||
equalTo(DateFormatter.forPattern("date_optional_time").format(date)));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("boolean_field").getValue(), equalTo((Object) true));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("text_field").getValue(), equalTo("foo"));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("keyword_field").getValue(), equalTo("foo"));
|
||||
@ -880,7 +880,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("float_field").getValue(), equalTo((Object) 5.0));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("double_field").getValue(), equalTo((Object) 6.0d));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("date_field").getValue(),
|
||||
equalTo(DateFormatter.forPattern("dateOptionalTime").format(date)));
|
||||
equalTo(DateFormatter.forPattern("date_optional_time").format(date)));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("boolean_field").getValue(), equalTo((Object) true));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("text_field").getValue(), equalTo("foo"));
|
||||
assertThat(searchResponse.getHits().getAt(0).getFields().get("keyword_field").getValue(), equalTo("foo"));
|
||||
|
@ -51,7 +51,7 @@ import java.util.Set;
|
||||
*/
|
||||
public final class UnassignedInfo implements ToXContentFragment, Writeable {
|
||||
|
||||
public static final DateFormatter DATE_TIME_FORMATTER = DateFormatter.forPattern("dateOptionalTime").withZone(ZoneOffset.UTC);
|
||||
public static final DateFormatter DATE_TIME_FORMATTER = DateFormatter.forPattern("date_optional_time").withZone(ZoneOffset.UTC);
|
||||
|
||||
public static final Setting<TimeValue> INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING =
|
||||
Setting.positiveTimeSetting("index.unassigned.node_left.delayed_timeout", TimeValue.timeValueMinutes(1), Property.Dynamic,
|
||||
|
@ -25,6 +25,8 @@ import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
import org.elasticsearch.common.time.DateFormatter;
|
||||
import org.elasticsearch.common.time.FormatNames;
|
||||
import org.elasticsearch.common.util.LazyInitializable;
|
||||
import org.elasticsearch.common.time.FormatNames;
|
||||
import org.joda.time.Chronology;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeField;
|
||||
@ -51,10 +53,14 @@ import java.math.BigDecimal;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Deprecated
|
||||
public class Joda {
|
||||
|
||||
private static DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(Joda.class));
|
||||
|
||||
// Joda.forPattern could be used even before the logging is initialized.
|
||||
// If LogManager.getLogger is called before logging config is loaded
|
||||
// it results in errors sent to status logger and startup to fail.
|
||||
// Hence a lazy initialization.
|
||||
private static final LazyInitializable<DeprecationLogger, RuntimeException> deprecationLogger
|
||||
= new LazyInitializable(() -> new DeprecationLogger(LogManager.getLogger(FormatNames.class)));
|
||||
/**
|
||||
* Parses a joda based pattern, including some named ones (similar to the built in Joda ISO ones).
|
||||
*/
|
||||
@ -66,6 +72,14 @@ public class Joda {
|
||||
throw new IllegalArgumentException("No date pattern provided");
|
||||
}
|
||||
|
||||
FormatNames formatName = FormatNames.forName(input);
|
||||
if (formatName != null && formatName.isCamelCase(input)) {
|
||||
String msg = "Camel case format name {} is deprecated and will be removed in a future version. " +
|
||||
"Use snake case name {} instead.";
|
||||
getDeprecationLogger()
|
||||
.deprecatedAndMaybeLog("camelCaseDateFormat", msg, formatName.getCamelCaseName(), formatName.getSnakeCaseName());
|
||||
}
|
||||
|
||||
DateTimeFormatter formatter;
|
||||
if (FormatNames.BASIC_DATE.matches(input)) {
|
||||
formatter = ISODateTimeFormat.basicDate();
|
||||
@ -272,7 +286,7 @@ public class Joda {
|
||||
private static void maybeLogJodaDeprecation(String format) {
|
||||
if (JodaDeprecationPatterns.isDeprecatedPattern(format)) {
|
||||
String suggestion = JodaDeprecationPatterns.formatSuggestion(format);
|
||||
deprecationLogger.deprecatedAndMaybeLog("joda-pattern-deprecation",
|
||||
getDeprecationLogger().deprecatedAndMaybeLog("joda-pattern-deprecation",
|
||||
suggestion + " " + JodaDeprecationPatterns.USE_NEW_FORMAT_SPECIFIERS);
|
||||
}
|
||||
}
|
||||
@ -382,11 +396,11 @@ public class Joda {
|
||||
long millis = new BigDecimal(text).longValue() * factor;
|
||||
// check for deprecations, but after it has parsed correctly so invalid values aren't counted as deprecated
|
||||
if (millis < 0) {
|
||||
deprecationLogger.deprecatedAndMaybeLog("epoch-negative", "Use of negative values" +
|
||||
getDeprecationLogger().deprecatedAndMaybeLog("epoch-negative", "Use of negative values" +
|
||||
" in epoch time formats is deprecated and will not be supported in the next major version of Elasticsearch.");
|
||||
}
|
||||
if (scientificNotation.matcher(text).find()) {
|
||||
deprecationLogger.deprecatedAndMaybeLog("epoch-scientific-notation", "Use of scientific notation" +
|
||||
getDeprecationLogger().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);
|
||||
@ -405,6 +419,10 @@ public class Joda {
|
||||
}
|
||||
}
|
||||
|
||||
private static DeprecationLogger getDeprecationLogger() {
|
||||
return deprecationLogger.getOrCompute();
|
||||
}
|
||||
|
||||
public static class EpochTimePrinter implements DateTimePrinter {
|
||||
|
||||
private boolean hasMilliSecondPrecision;
|
||||
|
@ -19,8 +19,11 @@
|
||||
|
||||
package org.elasticsearch.common.time;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
import org.elasticsearch.common.util.LazyInitializable;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Instant;
|
||||
@ -55,6 +58,12 @@ import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
|
||||
public class DateFormatters {
|
||||
// when run with JDK8, WeekFields for Locale.ROOT would return WeekFields.of(DayOfWeek.SUNDAY,1)
|
||||
public static final WeekFields WEEK_FIELDS_ROOT = WeekFields.of(DayOfWeek.MONDAY,4);
|
||||
// DateFormatters is being used even before the logging is initialized.
|
||||
// If LogManager.getLogger is called before logging config is loaded
|
||||
// it results in errors sent to status logger and startup to fail.
|
||||
// Hence a lazy initialization.
|
||||
private static final LazyInitializable<DeprecationLogger, RuntimeException> deprecationLogger
|
||||
= new LazyInitializable(() -> new DeprecationLogger(LogManager.getLogger(FormatNames.class)));
|
||||
|
||||
private static final DateTimeFormatter TIME_ZONE_FORMATTER_NO_COLON = new DateTimeFormatterBuilder()
|
||||
.appendOffset("+HHmm", "Z")
|
||||
@ -1635,166 +1644,174 @@ public class DateFormatters {
|
||||
throw new IllegalArgumentException("No date pattern provided");
|
||||
}
|
||||
|
||||
if ("iso8601".equals(input)) {
|
||||
FormatNames formatName = FormatNames.forName(input);
|
||||
if (formatName != null && formatName.isCamelCase(input)) {
|
||||
String msg = "Camel case format name {} is deprecated and will be removed in a future version. " +
|
||||
"Use snake case name {} instead.";
|
||||
deprecationLogger.getOrCompute()
|
||||
.deprecatedAndMaybeLog("camelCaseDateFormat", msg, formatName.getCamelCaseName(), formatName.getSnakeCaseName());
|
||||
}
|
||||
|
||||
if (FormatNames.ISO8601.matches(input)) {
|
||||
return ISO_8601;
|
||||
} else if ("basicDate".equals(input) || "basic_date".equals(input)) {
|
||||
} else if (FormatNames.BASIC_DATE.matches(input)) {
|
||||
return BASIC_DATE;
|
||||
} else if ("basicDateTime".equals(input) || "basic_date_time".equals(input)) {
|
||||
} else if (FormatNames.BASIC_DATE_TIME.matches(input)) {
|
||||
return BASIC_DATE_TIME;
|
||||
} else if ("basicDateTimeNoMillis".equals(input) || "basic_date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.BASIC_DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return BASIC_DATE_TIME_NO_MILLIS;
|
||||
} else if ("basicOrdinalDate".equals(input) || "basic_ordinal_date".equals(input)) {
|
||||
} else if (FormatNames.BASIC_ORDINAL_DATE.matches(input)) {
|
||||
return BASIC_ORDINAL_DATE;
|
||||
} else if ("basicOrdinalDateTime".equals(input) || "basic_ordinal_date_time".equals(input)) {
|
||||
} else if (FormatNames.BASIC_ORDINAL_DATE_TIME.matches(input)) {
|
||||
return BASIC_ORDINAL_DATE_TIME;
|
||||
} else if ("basicOrdinalDateTimeNoMillis".equals(input) || "basic_ordinal_date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.BASIC_ORDINAL_DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return BASIC_ORDINAL_DATE_TIME_NO_MILLIS;
|
||||
} else if ("basicTime".equals(input) || "basic_time".equals(input)) {
|
||||
} else if (FormatNames.BASIC_TIME.matches(input)) {
|
||||
return BASIC_TIME;
|
||||
} else if ("basicTimeNoMillis".equals(input) || "basic_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.BASIC_TIME_NO_MILLIS.matches(input)) {
|
||||
return BASIC_TIME_NO_MILLIS;
|
||||
} else if ("basicTTime".equals(input) || "basic_t_time".equals(input)) {
|
||||
} else if (FormatNames.BASIC_T_TIME.matches(input)) {
|
||||
return BASIC_T_TIME;
|
||||
} else if ("basicTTimeNoMillis".equals(input) || "basic_t_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.BASIC_T_TIME_NO_MILLIS.matches(input)) {
|
||||
return BASIC_T_TIME_NO_MILLIS;
|
||||
} else if ("basicWeekDate".equals(input) || "basic_week_date".equals(input)) {
|
||||
} else if (FormatNames.BASIC_WEEK_DATE.matches(input)) {
|
||||
return BASIC_WEEK_DATE;
|
||||
} else if ("basicWeekDateTime".equals(input) || "basic_week_date_time".equals(input)) {
|
||||
} else if (FormatNames.BASIC_WEEK_DATE_TIME.matches(input)) {
|
||||
return BASIC_WEEK_DATE_TIME;
|
||||
} else if ("basicWeekDateTimeNoMillis".equals(input) || "basic_week_date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.BASIC_WEEK_DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return BASIC_WEEK_DATE_TIME_NO_MILLIS;
|
||||
} else if ("date".equals(input)) {
|
||||
} else if (FormatNames.DATE.matches(input)) {
|
||||
return DATE;
|
||||
} else if ("dateHour".equals(input) || "date_hour".equals(input)) {
|
||||
} else if (FormatNames.DATE_HOUR.matches(input)) {
|
||||
return DATE_HOUR;
|
||||
} else if ("dateHourMinute".equals(input) || "date_hour_minute".equals(input)) {
|
||||
} else if (FormatNames.DATE_HOUR_MINUTE.matches(input)) {
|
||||
return DATE_HOUR_MINUTE;
|
||||
} else if ("dateHourMinuteSecond".equals(input) || "date_hour_minute_second".equals(input)) {
|
||||
} else if (FormatNames.DATE_HOUR_MINUTE_SECOND.matches(input)) {
|
||||
return DATE_HOUR_MINUTE_SECOND;
|
||||
} else if ("dateHourMinuteSecondFraction".equals(input) || "date_hour_minute_second_fraction".equals(input)) {
|
||||
} else if (FormatNames.DATE_HOUR_MINUTE_SECOND_FRACTION.matches(input)) {
|
||||
return DATE_HOUR_MINUTE_SECOND_FRACTION;
|
||||
} else if ("dateHourMinuteSecondMillis".equals(input) || "date_hour_minute_second_millis".equals(input)) {
|
||||
} else if (FormatNames.DATE_HOUR_MINUTE_SECOND_MILLIS.matches(input)) {
|
||||
return DATE_HOUR_MINUTE_SECOND_MILLIS;
|
||||
} else if ("dateOptionalTime".equals(input) || "date_optional_time".equals(input)) {
|
||||
} else if (FormatNames.DATE_OPTIONAL_TIME.matches(input)) {
|
||||
return DATE_OPTIONAL_TIME;
|
||||
} else if ("dateTime".equals(input) || "date_time".equals(input)) {
|
||||
} else if (FormatNames.DATE_TIME.matches(input)) {
|
||||
return DATE_TIME;
|
||||
} else if ("dateTimeNoMillis".equals(input) || "date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return DATE_TIME_NO_MILLIS;
|
||||
} else if ("hour".equals(input)) {
|
||||
} else if (FormatNames.HOUR.matches(input)) {
|
||||
return HOUR;
|
||||
} else if ("hourMinute".equals(input) || "hour_minute".equals(input)) {
|
||||
} else if (FormatNames.HOUR_MINUTE.matches(input)) {
|
||||
return HOUR_MINUTE;
|
||||
} else if ("hourMinuteSecond".equals(input) || "hour_minute_second".equals(input)) {
|
||||
} else if (FormatNames.HOUR_MINUTE_SECOND.matches(input)) {
|
||||
return HOUR_MINUTE_SECOND;
|
||||
} else if ("hourMinuteSecondFraction".equals(input) || "hour_minute_second_fraction".equals(input)) {
|
||||
} else if (FormatNames.HOUR_MINUTE_SECOND_FRACTION.matches(input)) {
|
||||
return HOUR_MINUTE_SECOND_FRACTION;
|
||||
} else if ("hourMinuteSecondMillis".equals(input) || "hour_minute_second_millis".equals(input)) {
|
||||
} else if (FormatNames.HOUR_MINUTE_SECOND_MILLIS.matches(input)) {
|
||||
return HOUR_MINUTE_SECOND_MILLIS;
|
||||
} else if ("ordinalDate".equals(input) || "ordinal_date".equals(input)) {
|
||||
} else if (FormatNames.ORDINAL_DATE.matches(input)) {
|
||||
return ORDINAL_DATE;
|
||||
} else if ("ordinalDateTime".equals(input) || "ordinal_date_time".equals(input)) {
|
||||
} else if (FormatNames.ORDINAL_DATE_TIME.matches(input)) {
|
||||
return ORDINAL_DATE_TIME;
|
||||
} else if ("ordinalDateTimeNoMillis".equals(input) || "ordinal_date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.ORDINAL_DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return ORDINAL_DATE_TIME_NO_MILLIS;
|
||||
} else if ("time".equals(input)) {
|
||||
} else if (FormatNames.TIME.matches(input)) {
|
||||
return TIME;
|
||||
} else if ("timeNoMillis".equals(input) || "time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.TIME_NO_MILLIS.matches(input)) {
|
||||
return TIME_NO_MILLIS;
|
||||
} else if ("tTime".equals(input) || "t_time".equals(input)) {
|
||||
} else if (FormatNames.T_TIME.matches(input)) {
|
||||
return T_TIME;
|
||||
} else if ("tTimeNoMillis".equals(input) || "t_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.T_TIME_NO_MILLIS.matches(input)) {
|
||||
return T_TIME_NO_MILLIS;
|
||||
} else if ("weekDate".equals(input) || "week_date".equals(input)) {
|
||||
} else if (FormatNames.WEEK_DATE.matches(input)) {
|
||||
return WEEK_DATE;
|
||||
} else if ("weekDateTime".equals(input) || "week_date_time".equals(input)) {
|
||||
} else if (FormatNames.WEEK_DATE_TIME.matches(input)) {
|
||||
return WEEK_DATE_TIME;
|
||||
} else if ("weekDateTimeNoMillis".equals(input) || "week_date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.WEEK_DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return WEEK_DATE_TIME_NO_MILLIS;
|
||||
} else if ("weekyear".equals(input) || "week_year".equals(input)) {
|
||||
} else if (FormatNames.WEEK_YEAR.matches(input)) {
|
||||
return WEEK_YEAR;
|
||||
} else if ("weekyearWeek".equals(input) || "weekyear_week".equals(input)) {
|
||||
} else if (FormatNames.WEEK_YEAR_WEEK.matches(input)) {
|
||||
return WEEKYEAR_WEEK;
|
||||
} else if ("weekyearWeekDay".equals(input) || "weekyear_week_day".equals(input)) {
|
||||
} else if (FormatNames.WEEKYEAR_WEEK_DAY.matches(input)) {
|
||||
return WEEKYEAR_WEEK_DAY;
|
||||
} else if ("year".equals(input)) {
|
||||
} else if (FormatNames.YEAR.matches(input)) {
|
||||
return YEAR;
|
||||
} else if ("yearMonth".equals(input) || "year_month".equals(input)) {
|
||||
} else if (FormatNames.YEAR_MONTH.matches(input)) {
|
||||
return YEAR_MONTH;
|
||||
} else if ("yearMonthDay".equals(input) || "year_month_day".equals(input)) {
|
||||
} else if (FormatNames.YEAR_MONTH_DAY.matches(input)) {
|
||||
return YEAR_MONTH_DAY;
|
||||
} else if ("epoch_second".equals(input)) {
|
||||
} else if (FormatNames.EPOCH_SECOND.matches(input)) {
|
||||
return EpochTime.SECONDS_FORMATTER;
|
||||
} else if ("epoch_millis".equals(input)) {
|
||||
} else if (FormatNames.EPOCH_MILLIS.matches(input)) {
|
||||
return EpochTime.MILLIS_FORMATTER;
|
||||
// strict date formats here, must be at least 4 digits for year and two for months and two for day
|
||||
} else if ("strictBasicWeekDate".equals(input) || "strict_basic_week_date".equals(input)) {
|
||||
} else if (FormatNames.STRICT_BASIC_WEEK_DATE.matches(input)) {
|
||||
return STRICT_BASIC_WEEK_DATE;
|
||||
} else if ("strictBasicWeekDateTime".equals(input) || "strict_basic_week_date_time".equals(input)) {
|
||||
} else if (FormatNames.STRICT_BASIC_WEEK_DATE_TIME.matches(input)) {
|
||||
return STRICT_BASIC_WEEK_DATE_TIME;
|
||||
} else if ("strictBasicWeekDateTimeNoMillis".equals(input) || "strict_basic_week_date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.STRICT_BASIC_WEEK_DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return STRICT_BASIC_WEEK_DATE_TIME_NO_MILLIS;
|
||||
} else if ("strictDate".equals(input) || "strict_date".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE.matches(input)) {
|
||||
return STRICT_DATE;
|
||||
} else if ("strictDateHour".equals(input) || "strict_date_hour".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE_HOUR.matches(input)) {
|
||||
return STRICT_DATE_HOUR;
|
||||
} else if ("strictDateHourMinute".equals(input) || "strict_date_hour_minute".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE_HOUR_MINUTE.matches(input)) {
|
||||
return STRICT_DATE_HOUR_MINUTE;
|
||||
} else if ("strictDateHourMinuteSecond".equals(input) || "strict_date_hour_minute_second".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE_HOUR_MINUTE_SECOND.matches(input)) {
|
||||
return STRICT_DATE_HOUR_MINUTE_SECOND;
|
||||
} else if ("strictDateHourMinuteSecondFraction".equals(input) || "strict_date_hour_minute_second_fraction".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE_HOUR_MINUTE_SECOND_FRACTION.matches(input)) {
|
||||
return STRICT_DATE_HOUR_MINUTE_SECOND_FRACTION;
|
||||
} else if ("strictDateHourMinuteSecondMillis".equals(input) || "strict_date_hour_minute_second_millis".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE_HOUR_MINUTE_SECOND_MILLIS.matches(input)) {
|
||||
return STRICT_DATE_HOUR_MINUTE_SECOND_MILLIS;
|
||||
} else if ("strictDateOptionalTime".equals(input) || "strict_date_optional_time".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE_OPTIONAL_TIME.matches(input)) {
|
||||
return STRICT_DATE_OPTIONAL_TIME;
|
||||
} else if ("strictDateOptionalTimeNanos".equals(input) || "strict_date_optional_time_nanos".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE_OPTIONAL_TIME_NANOS.matches(input)) {
|
||||
return STRICT_DATE_OPTIONAL_TIME_NANOS;
|
||||
} else if ("strictDateTime".equals(input) || "strict_date_time".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE_TIME.matches(input)) {
|
||||
return STRICT_DATE_TIME;
|
||||
} else if ("strictDateTimeNoMillis".equals(input) || "strict_date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.STRICT_DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return STRICT_DATE_TIME_NO_MILLIS;
|
||||
} else if ("strictHour".equals(input) || "strict_hour".equals(input)) {
|
||||
} else if (FormatNames.STRICT_HOUR.matches(input)) {
|
||||
return STRICT_HOUR;
|
||||
} else if ("strictHourMinute".equals(input) || "strict_hour_minute".equals(input)) {
|
||||
} else if (FormatNames.STRICT_HOUR_MINUTE.matches(input)) {
|
||||
return STRICT_HOUR_MINUTE;
|
||||
} else if ("strictHourMinuteSecond".equals(input) || "strict_hour_minute_second".equals(input)) {
|
||||
} else if (FormatNames.STRICT_HOUR_MINUTE_SECOND.matches(input)) {
|
||||
return STRICT_HOUR_MINUTE_SECOND;
|
||||
} else if ("strictHourMinuteSecondFraction".equals(input) || "strict_hour_minute_second_fraction".equals(input)) {
|
||||
} else if (FormatNames.STRICT_HOUR_MINUTE_SECOND_FRACTION.matches(input)) {
|
||||
return STRICT_HOUR_MINUTE_SECOND_FRACTION;
|
||||
} else if ("strictHourMinuteSecondMillis".equals(input) || "strict_hour_minute_second_millis".equals(input)) {
|
||||
} else if (FormatNames.STRICT_HOUR_MINUTE_SECOND_MILLIS.matches(input)) {
|
||||
return STRICT_HOUR_MINUTE_SECOND_MILLIS;
|
||||
} else if ("strictOrdinalDate".equals(input) || "strict_ordinal_date".equals(input)) {
|
||||
} else if (FormatNames.STRICT_ORDINAL_DATE.matches(input)) {
|
||||
return STRICT_ORDINAL_DATE;
|
||||
} else if ("strictOrdinalDateTime".equals(input) || "strict_ordinal_date_time".equals(input)) {
|
||||
} else if (FormatNames.STRICT_ORDINAL_DATE_TIME.matches(input)) {
|
||||
return STRICT_ORDINAL_DATE_TIME;
|
||||
} else if ("strictOrdinalDateTimeNoMillis".equals(input) || "strict_ordinal_date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.STRICT_ORDINAL_DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return STRICT_ORDINAL_DATE_TIME_NO_MILLIS;
|
||||
} else if ("strictTime".equals(input) || "strict_time".equals(input)) {
|
||||
} else if (FormatNames.STRICT_TIME.matches(input)) {
|
||||
return STRICT_TIME;
|
||||
} else if ("strictTimeNoMillis".equals(input) || "strict_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.STRICT_TIME_NO_MILLIS.matches(input)) {
|
||||
return STRICT_TIME_NO_MILLIS;
|
||||
} else if ("strictTTime".equals(input) || "strict_t_time".equals(input)) {
|
||||
} else if (FormatNames.STRICT_T_TIME.matches(input)) {
|
||||
return STRICT_T_TIME;
|
||||
} else if ("strictTTimeNoMillis".equals(input) || "strict_t_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.STRICT_T_TIME_NO_MILLIS.matches(input)) {
|
||||
return STRICT_T_TIME_NO_MILLIS;
|
||||
} else if ("strictWeekDate".equals(input) || "strict_week_date".equals(input)) {
|
||||
} else if (FormatNames.STRICT_WEEK_DATE.matches(input)) {
|
||||
return STRICT_WEEK_DATE;
|
||||
} else if ("strictWeekDateTime".equals(input) || "strict_week_date_time".equals(input)) {
|
||||
} else if (FormatNames.STRICT_WEEK_DATE_TIME.matches(input)) {
|
||||
return STRICT_WEEK_DATE_TIME;
|
||||
} else if ("strictWeekDateTimeNoMillis".equals(input) || "strict_week_date_time_no_millis".equals(input)) {
|
||||
} else if (FormatNames.STRICT_WEEK_DATE_TIME_NO_MILLIS.matches(input)) {
|
||||
return STRICT_WEEK_DATE_TIME_NO_MILLIS;
|
||||
} else if ("strictWeekyear".equals(input) || "strict_weekyear".equals(input)) {
|
||||
} else if (FormatNames.STRICT_WEEKYEAR.matches(input)) {
|
||||
return STRICT_WEEKYEAR;
|
||||
} else if ("strictWeekyearWeek".equals(input) || "strict_weekyear_week".equals(input)) {
|
||||
} else if (FormatNames.STRICT_WEEKYEAR_WEEK.matches(input)) {
|
||||
return STRICT_WEEKYEAR_WEEK;
|
||||
} else if ("strictWeekyearWeekDay".equals(input) || "strict_weekyear_week_day".equals(input)) {
|
||||
} else if (FormatNames.STRICT_WEEKYEAR_WEEK_DAY.matches(input)) {
|
||||
return STRICT_WEEKYEAR_WEEK_DAY;
|
||||
} else if ("strictYear".equals(input) || "strict_year".equals(input)) {
|
||||
} else if (FormatNames.STRICT_YEAR.matches(input)) {
|
||||
return STRICT_YEAR;
|
||||
} else if ("strictYearMonth".equals(input) || "strict_year_month".equals(input)) {
|
||||
} else if (FormatNames.STRICT_YEAR_MONTH.matches(input)) {
|
||||
return STRICT_YEAR_MONTH;
|
||||
} else if ("strictYearMonthDay".equals(input) || "strict_year_month_day".equals(input)) {
|
||||
} else if (FormatNames.STRICT_YEAR_MONTH_DAY.matches(input)) {
|
||||
return STRICT_YEAR_MONTH_DAY;
|
||||
} else {
|
||||
try {
|
||||
|
@ -25,7 +25,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public enum FormatNames {
|
||||
ISO8601("iso8601", "iso8601"),
|
||||
ISO8601(null, "iso8601"),
|
||||
BASIC_DATE("basicDate", "basic_date"),
|
||||
BASIC_DATE_TIME("basicDateTime", "basic_date_time"),
|
||||
BASIC_DATE_TIME_NO_MILLIS("basicDateTimeNoMillis", "basic_date_time_no_millis"),
|
||||
@ -39,7 +39,7 @@ public enum FormatNames {
|
||||
BASIC_WEEK_DATE("basicWeekDate", "basic_week_date"),
|
||||
BASIC_WEEK_DATE_TIME("basicWeekDateTime", "basic_week_date_time"),
|
||||
BASIC_WEEK_DATE_TIME_NO_MILLIS("basicWeekDateTimeNoMillis", "basic_week_date_time_no_millis"),
|
||||
DATE("date", "date"),
|
||||
DATE(null, "date"),
|
||||
DATE_HOUR("dateHour", "date_hour"),
|
||||
DATE_HOUR_MINUTE("dateHourMinute", "date_hour_minute"),
|
||||
DATE_HOUR_MINUTE_SECOND("dateHourMinuteSecond", "date_hour_minute_second"),
|
||||
@ -48,7 +48,7 @@ public enum FormatNames {
|
||||
DATE_OPTIONAL_TIME("dateOptionalTime", "date_optional_time"),
|
||||
DATE_TIME("dateTime", "date_time"),
|
||||
DATE_TIME_NO_MILLIS("dateTimeNoMillis", "date_time_no_millis"),
|
||||
HOUR("hour", "hour"),
|
||||
HOUR(null, "hour"),
|
||||
HOUR_MINUTE("hourMinute", "hour_minute"),
|
||||
HOUR_MINUTE_SECOND("hourMinuteSecond", "hour_minute_second"),
|
||||
HOUR_MINUTE_SECOND_FRACTION("hourMinuteSecondFraction", "hour_minute_second_fraction"),
|
||||
@ -56,7 +56,7 @@ public enum FormatNames {
|
||||
ORDINAL_DATE("ordinalDate", "ordinal_date"),
|
||||
ORDINAL_DATE_TIME("ordinalDateTime", "ordinal_date_time"),
|
||||
ORDINAL_DATE_TIME_NO_MILLIS("ordinalDateTimeNoMillis", "ordinal_date_time_no_millis"),
|
||||
TIME("time", "time"),
|
||||
TIME(null, "time"),
|
||||
TIME_NO_MILLIS("timeNoMillis", "time_no_millis"),
|
||||
T_TIME("tTime", "t_time"),
|
||||
T_TIME_NO_MILLIS("tTimeNoMillis", "t_time_no_millis"),
|
||||
@ -66,11 +66,11 @@ public enum FormatNames {
|
||||
WEEK_YEAR("weekyear", "week_year"),
|
||||
WEEK_YEAR_WEEK("weekyearWeek", "weekyear_week"),
|
||||
WEEKYEAR_WEEK_DAY("weekyearWeekDay", "weekyear_week_day"),
|
||||
YEAR("year", "year"),
|
||||
YEAR(null, "year"),
|
||||
YEAR_MONTH("yearMonth", "year_month"),
|
||||
YEAR_MONTH_DAY("yearMonthDay", "year_month_day"),
|
||||
EPOCH_SECOND("epoch_second", "epoch_second"),
|
||||
EPOCH_MILLIS("epoch_millis", "epoch_millis"),
|
||||
EPOCH_SECOND(null, "epoch_second"),
|
||||
EPOCH_MILLIS(null, "epoch_millis"),
|
||||
// strict date formats here, must be at least 4 digits for year and two for months and two for day"
|
||||
STRICT_BASIC_WEEK_DATE("strictBasicWeekDate", "strict_basic_week_date"),
|
||||
STRICT_BASIC_WEEK_DATE_TIME("strictBasicWeekDateTime", "strict_basic_week_date_time"),
|
||||
@ -122,7 +122,28 @@ public enum FormatNames {
|
||||
return ALL_NAMES.contains(format);
|
||||
}
|
||||
|
||||
public static FormatNames forName(String format) {
|
||||
for (FormatNames name : values()) {
|
||||
if (name.matches(format)) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean matches(String format) {
|
||||
return format.equals(camelCaseName) || format.equals(snakeCaseName);
|
||||
}
|
||||
|
||||
public boolean isCamelCase(String format) {
|
||||
return format.equals(camelCaseName);
|
||||
}
|
||||
|
||||
public String getSnakeCaseName() {
|
||||
return snakeCaseName;
|
||||
}
|
||||
|
||||
public String getCamelCaseName() {
|
||||
return camelCaseName;
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class HotThreads {
|
||||
|
||||
private static final Object mutex = new Object();
|
||||
|
||||
private static final DateFormatter DATE_TIME_FORMATTER = DateFormatter.forPattern("dateOptionalTime");
|
||||
private static final DateFormatter DATE_TIME_FORMATTER = DateFormatter.forPattern("date_optional_time");
|
||||
|
||||
private int busiestThreads = 3;
|
||||
private TimeValue interval = new TimeValue(500, TimeUnit.MILLISECONDS);
|
||||
|
@ -58,7 +58,7 @@ public final class SnapshotInfo implements Comparable<SnapshotInfo>, ToXContent,
|
||||
public static final String CONTEXT_MODE_PARAM = "context_mode";
|
||||
public static final String CONTEXT_MODE_SNAPSHOT = "SNAPSHOT";
|
||||
public static final Version METADATA_FIELD_INTRODUCED = Version.V_7_3_0;
|
||||
private static final DateFormatter DATE_TIME_FORMATTER = DateFormatter.forPattern("strictDateOptionalTime");
|
||||
private static final DateFormatter DATE_TIME_FORMATTER = DateFormatter.forPattern("strict_date_optional_time");
|
||||
private static final String SNAPSHOT = "snapshot";
|
||||
private static final String UUID = "uuid";
|
||||
private static final String INDICES = "indices";
|
||||
|
@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class JodaDateMathParserTests extends ESTestCase {
|
||||
|
||||
DateFormatter formatter = Joda.forPattern("dateOptionalTime||epoch_millis");
|
||||
DateFormatter formatter = Joda.forPattern("date_optional_time||epoch_millis");
|
||||
DateMathParser parser = formatter.toDateMathParser();
|
||||
|
||||
void assertDateMathEquals(String toTest, String expected) {
|
||||
|
@ -40,7 +40,8 @@ public class JodaTests extends ESTestCase {
|
||||
DateFormatter formatter2 = Joda.forPattern("basicTTime");
|
||||
assertEquals(formatter2.pattern(), "basicTTime");
|
||||
assertEquals(formatter2.zone(), ZoneOffset.UTC);
|
||||
|
||||
assertWarnings("Camel case format name basicTTime is deprecated and will be removed in a future version. " +
|
||||
"Use snake case name basic_t_time instead.");
|
||||
DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, DateTimeZone.UTC);
|
||||
assertEquals("T102030.040Z", formatter1.formatJoda(dt));
|
||||
assertEquals("T102030.040Z", formatter1.formatJoda(dt));
|
||||
|
@ -20,6 +20,7 @@
|
||||
package org.elasticsearch.common.time;
|
||||
|
||||
import org.elasticsearch.bootstrap.JavaVersion;
|
||||
import org.elasticsearch.common.joda.Joda;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.time.Clock;
|
||||
@ -381,4 +382,50 @@ public class DateFormattersTests extends ESTestCase {
|
||||
assertThat(instant.getNano(), is(123_456_789));
|
||||
}
|
||||
}
|
||||
|
||||
public void testCamelCaseDeprecation() {
|
||||
String[] deprecatedNames = new String[]{
|
||||
"basicDate", "basicDateTime", "basicDateTimeNoMillis", "basicOrdinalDate", "basicOrdinalDateTime",
|
||||
"basicOrdinalDateTimeNoMillis", "basicTime", "basicTimeNoMillis", "basicTTime", "basicTTimeNoMillis",
|
||||
"basicWeekDate", "basicWeekDateTime", "basicWeekDateTimeNoMillis", "dateHour", "dateHourMinute",
|
||||
"dateHourMinuteSecond", "dateHourMinuteSecondFraction", "dateHourMinuteSecondMillis", "dateOptionalTime",
|
||||
"dateTime", "dateTimeNoMillis", "hourMinute", "hourMinuteSecond", "hourMinuteSecondFraction", "hourMinuteSecondMillis",
|
||||
"ordinalDate", "ordinalDateTime", "ordinalDateTimeNoMillis", "timeNoMillis",
|
||||
"tTime", "tTimeNoMillis", "weekDate", "weekDateTime", "weekDateTimeNoMillis", "weekyear", "weekyearWeek", "weekyearWeekDay",
|
||||
"yearMonth", "yearMonthDay", "strictBasicWeekDate", "strictBasicWeekDateTime",
|
||||
"strictBasicWeekDateTimeNoMillis", "strictDate", "strictDateHour", "strictDateHourMinute", "strictDateHourMinuteSecond",
|
||||
"strictDateHourMinuteSecondFraction", "strictDateHourMinuteSecondMillis", "strictDateOptionalTime",
|
||||
"strictDateOptionalTimeNanos", "strictDateTime", "strictDateTimeNoMillis", "strictHour", "strictHourMinute",
|
||||
"strictHourMinuteSecond", "strictHourMinuteSecondFraction", "strictHourMinuteSecondMillis", "strictOrdinalDate",
|
||||
"strictOrdinalDateTime", "strictOrdinalDateTimeNoMillis", "strictTime", "strictTimeNoMillis", "strictTTime",
|
||||
"strictTTimeNoMillis", "strictWeekDate", "strictWeekDateTime", "strictWeekDateTimeNoMillis", "strictWeekyear",
|
||||
"strictWeekyearWeek",
|
||||
"strictWeekyearWeekDay", "strictYear", "strictYearMonth", "strictYearMonthDay"
|
||||
};
|
||||
for (String name : deprecatedNames) {
|
||||
String snakeCaseName = FormatNames.forName(name).getSnakeCaseName();
|
||||
|
||||
DateFormatter dateFormatter = DateFormatter.forPattern(name);
|
||||
assertThat(dateFormatter.pattern(), equalTo(name));
|
||||
assertWarnings("Camel case format name " + name + " is deprecated and will be removed in a future version. " +
|
||||
"Use snake case name " + snakeCaseName + " instead.");
|
||||
|
||||
dateFormatter = DateFormatter.forPattern(snakeCaseName);
|
||||
assertThat(dateFormatter.pattern(), equalTo(snakeCaseName));
|
||||
}
|
||||
|
||||
for (String name : deprecatedNames) {
|
||||
if (name.equals("strictDateOptionalTimeNanos") == false) {
|
||||
DateFormatter dateFormatter = Joda.forPattern(name);
|
||||
assertThat(dateFormatter.pattern(), equalTo(name));
|
||||
|
||||
String snakeCaseName = FormatNames.forName(name).getSnakeCaseName();
|
||||
assertWarnings("Camel case format name " + name + " is deprecated and will be removed in a future version. " +
|
||||
"Use snake case name " + snakeCaseName + " instead.");
|
||||
|
||||
dateFormatter = Joda.forPattern(snakeCaseName);
|
||||
assertThat(dateFormatter.pattern(), equalTo(snakeCaseName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class JavaDateMathParserTests extends ESTestCase {
|
||||
|
||||
private final DateFormatter formatter = DateFormatter.forPattern("dateOptionalTime||epoch_millis");
|
||||
private final DateFormatter formatter = DateFormatter.forPattern("date_optional_time||epoch_millis");
|
||||
private final DateMathParser parser = formatter.toDateMathParser();
|
||||
|
||||
public void testOverridingLocaleOrZoneAndCompositeRoundUpParser() {
|
||||
@ -273,7 +273,7 @@ public class JavaDateMathParserTests extends ESTestCase {
|
||||
assertDateMathEquals("1418248078000||/m", "2014-12-10T21:47:00.000");
|
||||
|
||||
// also check other time units
|
||||
DateMathParser parser = DateFormatter.forPattern("epoch_second||dateOptionalTime").toDateMathParser();
|
||||
DateMathParser parser = DateFormatter.forPattern("epoch_second||date_optional_time").toDateMathParser();
|
||||
long datetime = parser.parse("1418248078", () -> 0).toEpochMilli();
|
||||
assertDateEquals(datetime, "1418248078", "2014-12-10T21:47:58.000");
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class LongBoundsTests extends ESTestCase {
|
||||
new IndexSettings(IndexMetadata.builder("foo").settings(indexSettings).build(), indexSettings),
|
||||
BigArrays.NON_RECYCLING_INSTANCE, null, null, null, null, null, xContentRegistry(), writableRegistry(),
|
||||
null, null, () -> now, null, null, () -> true, null);
|
||||
DateFormatter formatter = DateFormatter.forPattern("dateOptionalTime");
|
||||
DateFormatter formatter = DateFormatter.forPattern("date_optional_time");
|
||||
DocValueFormat format = new DocValueFormat.DateTime(formatter, ZoneOffset.UTC, DateFieldMapper.Resolution.MILLISECONDS);
|
||||
|
||||
LongBounds expected = randomParsedExtendedBounds();
|
||||
|
Loading…
x
Reference in New Issue
Block a user