Skip to content

Commit 8674678

Browse files
authored
Revert "Deprecate resolution loss on date field (#78921)" (#80003)
This reverts commit d50c9e8. relates #78921 reason #37962 (comment)
1 parent f5e0270 commit 8674678

File tree

13 files changed

+35
-122
lines changed

13 files changed

+35
-122
lines changed

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void testDateNanosFormatUpgrade() throws IOException {
201201
Request index = new Request("POST", "/" + indexName + "/_doc/");
202202
XContentBuilder doc = XContentBuilder.builder(XContentType.JSON.xContent())
203203
.startObject()
204-
.field("date", "2015-01-01T12:10:30.123Z")
204+
.field("date", "2015-01-01T12:10:30.123456789Z")
205205
.field("date_nanos", "2015-01-01T12:10:30.123456789Z")
206206
.endObject();
207207
index.addParameter("refresh", "true");

qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/60_pipeline_timestamp_date_mapping.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
index: timetest
1010
body:
1111
mappings:
12-
"properties": { "my_time": {"type": "date_nanos", "format": "strict_date_optional_time_nanos"}}
12+
"properties": { "my_time": {"type": "date", "format": "strict_date_optional_time_nanos"}}
1313

1414
- do:
1515
ingest.put_pipeline:

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/49_range_timezone_bug.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ setup:
88
mappings:
99
properties:
1010
mydate:
11-
type: date_nanos
11+
type: date
1212
format: "uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSZZZZZ"
1313

1414
- do:

server/src/main/java/org/elasticsearch/index/IndexMode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ public void completeMappings(MappingParserContext context, Map<String, Object> m
117117
DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER,
118118
context.scriptCompiler(),
119119
DateFieldMapper.IGNORE_MALFORMED_SETTING.get(context.getSettings()),
120-
context.getIndexSettings().getIndexVersionCreated(),
121-
context.getIndexSettings().getIndex().getName()
120+
context.getIndexSettings().getIndexVersionCreated()
122121
)
123122
);
124123
}

server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public final class DateFieldMapper extends FieldMapper {
7474
"strict_date_optional_time_nanos||epoch_millis"
7575
);
7676
private static final DateMathParser EPOCH_MILLIS_PARSER = DateFormatter.forPattern("epoch_millis").toDateMathParser();
77-
private final String indexName;
7877

7978
public enum Resolution {
8079
MILLISECONDS(CONTENT_TYPE, NumericType.DATE) {
@@ -238,7 +237,6 @@ public static class Builder extends FieldMapper.Builder {
238237
private final Parameter<String> nullValue = Parameter.stringParam("null_value", false, m -> toType(m).nullValueAsString, null)
239238
.acceptsNull();
240239
private final Parameter<Boolean> ignoreMalformed;
241-
private String indexName;
242240

243241
private final Parameter<Script> script = Parameter.scriptParam(m -> toType(m).script);
244242
private final Parameter<String> onScriptError = Parameter.onScriptErrorParam(m -> toType(m).onScriptError, script);
@@ -253,15 +251,13 @@ public Builder(
253251
DateFormatter dateFormatter,
254252
ScriptCompiler scriptCompiler,
255253
boolean ignoreMalformedByDefault,
256-
Version indexCreatedVersion,
257-
String indexName
254+
Version indexCreatedVersion
258255
) {
259256
super(name);
260257
this.resolution = resolution;
261258
this.indexCreatedVersion = indexCreatedVersion;
262259
this.scriptCompiler = Objects.requireNonNull(scriptCompiler);
263260
this.ignoreMalformed = Parameter.boolParam("ignore_malformed", true, m -> toType(m).ignoreMalformed, ignoreMalformedByDefault);
264-
this.indexName = indexName;
265261

266262
this.script.precludesParameters(nullValue, ignoreMalformed);
267263
addScriptValidation(script, index, docValues);
@@ -301,13 +297,12 @@ protected List<Parameter<?>> getParameters() {
301297
return List.of(index, docValues, store, format, locale, nullValue, ignoreMalformed, script, onScriptError, meta);
302298
}
303299

304-
private Long parseNullValue(DateFieldType fieldType, String indexName) {
300+
private Long parseNullValue(DateFieldType fieldType) {
305301
if (nullValue.getValue() == null) {
306302
return null;
307303
}
308304
try {
309-
final String fieldName = fieldType.name();
310-
return fieldType.parseNullValueWithDeprecation(nullValue.getValue(), fieldName, indexName);
305+
return fieldType.parse(nullValue.getValue());
311306
} catch (Exception e) {
312307
if (indexCreatedVersion.onOrAfter(Version.V_8_0_0)) {
313308
throw new MapperParsingException("Error parsing [null_value] on field [" + name() + "]: " + e.getMessage(), e);
@@ -340,7 +335,7 @@ public DateFieldMapper build(MapperBuilderContext context) {
340335
meta.getValue()
341336
);
342337

343-
Long nullTimestamp = parseNullValue(ft, indexName);
338+
Long nullTimestamp = parseNullValue(ft);
344339
return new DateFieldMapper(name, ft, multiFieldsBuilder.build(this, context), copyTo.build(), nullTimestamp, resolution, this);
345340
}
346341
}
@@ -353,8 +348,7 @@ public DateFieldMapper build(MapperBuilderContext context) {
353348
c.getDateFormatter(),
354349
c.scriptCompiler(),
355350
ignoreMalformedByDefault,
356-
c.indexVersionCreated(),
357-
c.getIndexSettings() != null ? c.getIndexSettings().getIndex().getName() : null
351+
c.indexVersionCreated()
358352
);
359353
});
360354

@@ -366,8 +360,7 @@ public DateFieldMapper build(MapperBuilderContext context) {
366360
c.getDateFormatter(),
367361
c.scriptCompiler(),
368362
ignoreMalformedByDefault,
369-
c.indexVersionCreated(),
370-
c.getIndexSettings() != null ? c.getIndexSettings().getIndex().getName() : null
363+
c.indexVersionCreated()
371364
);
372365
});
373366

@@ -432,42 +425,7 @@ protected DateMathParser dateMathParser() {
432425

433426
// Visible for testing.
434427
public long parse(String value) {
435-
final Instant instant = getInstant(value);
436-
return resolution.convert(instant);
437-
}
438-
439-
public long parseWithDeprecation(String value, String fieldName, String indexName) {
440-
final Instant instant = getInstant(value);
441-
if (resolution == Resolution.MILLISECONDS && instant.getNano() % 1000000 != 0) {
442-
DEPRECATION_LOGGER.warn(
443-
DeprecationCategory.MAPPINGS,
444-
"date_field_with_nanos",
445-
"You are attempting to store a nanosecond resolution on a field [{}] of type date on index [{}]. "
446-
+ "The nanosecond part was lost. Use date_nanos field type.",
447-
fieldName,
448-
indexName
449-
);
450-
}
451-
return resolution.convert(instant);
452-
}
453-
454-
public long parseNullValueWithDeprecation(String value, String fieldName, String indexName) {
455-
final Instant instant = getInstant(value);
456-
if (resolution == Resolution.MILLISECONDS && instant.getNano() % 1000000 != 0) {
457-
DEPRECATION_LOGGER.warn(
458-
DeprecationCategory.MAPPINGS,
459-
"date_field_with_nanos",
460-
"You are attempting to set null_value with a nanosecond resolution on a field [{}] of type date on index [{}]. "
461-
+ "The nanosecond part was lost. Use date_nanos field type.",
462-
fieldName,
463-
indexName
464-
);
465-
}
466-
return resolution.convert(instant);
467-
}
468-
469-
private Instant getInstant(String value) {
470-
return DateFormatters.from(dateTimeFormatter().parse(value), dateTimeFormatter().locale()).toInstant();
428+
return resolution.convert(DateFormatters.from(dateTimeFormatter().parse(value), dateTimeFormatter().locale()).toInstant());
471429
}
472430

473431
/**
@@ -783,14 +741,11 @@ private DateFieldMapper(
783741
this.script = builder.script.get();
784742
this.scriptCompiler = builder.scriptCompiler;
785743
this.scriptValues = builder.scriptValues();
786-
this.indexName = builder.indexName;
787744
}
788745

789746
@Override
790747
public FieldMapper.Builder getMergeBuilder() {
791-
return new Builder(simpleName(), resolution, null, scriptCompiler, ignoreMalformedByDefault, indexCreatedVersion, indexName).init(
792-
this
793-
);
748+
return new Builder(simpleName(), resolution, null, scriptCompiler, ignoreMalformedByDefault, indexCreatedVersion).init(this);
794749
}
795750

796751
@Override
@@ -815,9 +770,7 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
815770
timestamp = nullValue;
816771
} else {
817772
try {
818-
final String fieldName = fieldType().name();
819-
final String indexName = context.indexSettings().getIndex().getName();
820-
timestamp = fieldType().parseWithDeprecation(dateAsString, fieldName, indexName);
773+
timestamp = fieldType().parse(dateAsString);
821774
} catch (IllegalArgumentException | ElasticsearchParseException | DateTimeException | ArithmeticException e) {
822775
if (ignoreMalformed) {
823776
context.addIgnoredField(mappedFieldType.name());

server/src/main/java/org/elasticsearch/index/mapper/DynamicFieldsBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ public void newDynamicDateField(DocumentParserContext context, String name, Date
362362
dateTimeFormatter,
363363
ScriptCompiler.NONE,
364364
ignoreMalformed,
365-
context.indexSettings().getIndexVersionCreated(),
366-
context.indexSettings().getIndex().getName()
365+
context.indexSettings().getIndexVersionCreated()
367366
),
368367
context
369368
);

server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverServiceTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,7 @@ public void testRolloverClusterStateForDataStream() throws Exception {
672672
null,
673673
ScriptCompiler.NONE,
674674
false,
675-
Version.CURRENT,
676-
"indexName"
675+
Version.CURRENT
677676
).build(MapperBuilderContext.ROOT);
678677
ClusterService clusterService = ClusterServiceUtils.createClusterService(testThreadPool);
679678
Environment env = mock(Environment.class);
@@ -688,8 +687,7 @@ public void testRolloverClusterStateForDataStream() throws Exception {
688687
DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER,
689688
ScriptCompiler.NONE,
690689
true,
691-
Version.CURRENT,
692-
"indexName"
690+
Version.CURRENT
693691
)
694692
);
695693
MetadataFieldMapper dtfm = getDataStreamTimestampFieldMapper();

server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package org.elasticsearch.index.mapper;
1010

11-
import org.apache.logging.log4j.Level;
1211
import org.apache.lucene.index.DocValuesType;
1312
import org.apache.lucene.index.IndexableField;
1413
import org.elasticsearch.Version;
@@ -140,22 +139,6 @@ public void testIgnoreMalformed() throws IOException {
140139
testIgnoreMalformedForValue("-522000000", "long overflow", "date_optional_time");
141140
}
142141

143-
public void testResolutionLossDeprecation() throws Exception {
144-
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "date")));
145-
146-
ParsedDocument doc = mapper.parse(source(b -> b.field("field", "2018-10-03T14:42:44.123456+0000")));
147-
148-
assertWarnings(
149-
true,
150-
new DeprecationWarning(
151-
Level.WARN,
152-
"You are attempting to store a nanosecond resolution "
153-
+ "on a field [field] of type date on index [index]. "
154-
+ "The nanosecond part was lost. Use date_nanos field type."
155-
)
156-
);
157-
}
158-
159142
private void testIgnoreMalformedForValue(String value, String expectedCause, String dateFormat) throws IOException {
160143

161144
DocumentMapper mapper = createDocumentMapper(fieldMapping((builder) -> dateFieldMapping(builder, dateFormat)));
@@ -419,11 +402,11 @@ public void testFetchMillisFromIso8601() throws IOException {
419402
}
420403

421404
public void testFetchMillisFromIso8601Nanos() throws IOException {
422-
assertFetch(dateNanosMapperService(), "field", randomIs8601Nanos(MAX_NANOS), null);
405+
assertFetch(dateMapperService(), "field", randomIs8601Nanos(MAX_ISO_DATE), null);
423406
}
424407

425408
public void testFetchMillisFromIso8601NanosFormatted() throws IOException {
426-
assertFetch(dateNanosMapperService(), "field", randomIs8601Nanos(MAX_NANOS), "strict_date_optional_time_nanos");
409+
assertFetch(dateMapperService(), "field", randomIs8601Nanos(MAX_ISO_DATE), "strict_date_optional_time_nanos");
427410
}
428411

429412
/**
@@ -434,8 +417,7 @@ public void testFetchMillisFromIso8601NanosFormatted() throws IOException {
434417
* way.
435418
*/
436419
public void testFetchMillisFromRoundedNanos() throws IOException {
437-
assertFetch(dateMapperService(), "field", randomDecimalMillis(MAX_ISO_DATE), null);
438-
assertFetch(dateNanosMapperService(), "field", randomDecimalNanos(MAX_NANOS), null);
420+
assertFetch(dateMapperService(), "field", randomDecimalNanos(MAX_ISO_DATE), null);
439421
}
440422

441423
/**
@@ -543,7 +525,7 @@ protected Object generateRandomInputValue(MappedFieldType ft) {
543525
switch (((DateFieldType) ft).resolution()) {
544526
case MILLISECONDS:
545527
if (randomBoolean()) {
546-
return randomDecimalMillis(MAX_ISO_DATE);
528+
return randomIs8601Nanos(MAX_ISO_DATE);
547529
}
548530
return randomLongBetween(0, Long.MAX_VALUE);
549531
case NANOSECONDS:
@@ -576,10 +558,6 @@ private String randomDecimalNanos(long maxMillis) {
576558
return Long.toString(randomLongBetween(0, maxMillis)) + "." + between(0, 999999);
577559
}
578560

579-
private String randomDecimalMillis(long maxMillis) {
580-
return Long.toString(randomLongBetween(0, maxMillis));
581-
}
582-
583561
public void testScriptAndPrecludedParameters() {
584562
{
585563
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {

x-pack/plugin/data-streams/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/datastreams/AutoCreateDataStreamIT.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.client.ResponseException;
1515
import org.elasticsearch.common.Strings;
1616
import org.elasticsearch.common.io.Streams;
17-
import org.elasticsearch.common.time.DateFormatter;
1817
import org.elasticsearch.test.rest.ESRestTestCase;
1918
import org.elasticsearch.xcontent.XContentBuilder;
2019
import org.elasticsearch.xcontent.json.JsonXContent;
@@ -102,9 +101,7 @@ private void createTemplateWithAllowAutoCreate(Boolean allowAutoCreate) throws I
102101

103102
private Response indexDocument() throws IOException {
104103
final Request indexDocumentRequest = new Request("POST", "recipe_kr/_doc");
105-
final Instant now = Instant.now();
106-
final String time = DateFormatter.forPattern("strict_date_optional_time").format(now);
107-
indexDocumentRequest.setJsonEntity("{ \"@timestamp\": \"" + time + "\", \"name\": \"Kimchi\" }");
104+
indexDocumentRequest.setJsonEntity("{ \"@timestamp\": \"" + Instant.now() + "\", \"name\": \"Kimchi\" }");
108105
return client().performRequest(indexDocumentRequest);
109106
}
110107
}

x-pack/plugin/ml/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/transforms/PainlessDomainSplitIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.cluster.metadata.IndexMetadata;
1313
import org.elasticsearch.common.Strings;
1414
import org.elasticsearch.common.settings.Settings;
15-
import org.elasticsearch.common.time.DateFormatter;
1615
import org.elasticsearch.test.rest.ESRestTestCase;
1716

1817
import java.time.ZoneOffset;
@@ -309,7 +308,7 @@ public void testHRDSplit() throws Exception {
309308

310309
for (int i = 1; i <= 100; i++) {
311310
ZonedDateTime time = baseTime.plusHours(i);
312-
String formattedTime = DateFormatter.forPattern("strict_date_optional_time").format(time);
311+
String formattedTime = time.format(DateTimeFormatter.ISO_DATE_TIME);
313312
if (i % 50 == 0) {
314313
// Anomaly has 100 docs, but we don't care about the value
315314
for (int j = 0; j < 100; j++) {

x-pack/plugin/transform/qa/multi-cluster-tests-with-security/src/test/resources/rest-api-spec/test/multi_cluster/80_transform.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ teardown:
210210
test_alias: {}
211211
mappings:
212212
properties:
213-
date:
214-
type: date_nanos
213+
time:
214+
type: date
215215
user:
216216
type: keyword
217217
stars:

x-pack/plugin/transform/qa/multi-cluster-tests-with-security/src/test/resources/rest-api-spec/test/remote_cluster/80_transform.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ teardown:
4848
test_alias: {}
4949
mappings:
5050
properties:
51-
date:
52-
type: date_nanos
51+
time:
52+
type: date
5353
user:
5454
type: keyword
5555
stars:
@@ -107,8 +107,8 @@ teardown:
107107
test_alias: {}
108108
mappings:
109109
properties:
110-
date:
111-
type: date_nanos
110+
time:
111+
type: date
112112
user:
113113
type: keyword
114114
stars:

0 commit comments

Comments
 (0)