Skip to content

Commit 63521b4

Browse files
authored
Rename dimension mapping parameter to time_series_dimension (#78012)
This PR renames dimension mapping parameter to time_series_dimension to make it consistent with time_series_metric parameter (#76766) Relates to #74450 and #74014
1 parent f1b1178 commit 63521b4

File tree

11 files changed

+104
-68
lines changed

11 files changed

+104
-68
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/tsdb/10_settings.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ enable:
1818
type: date
1919
metricset:
2020
type: keyword
21-
dimension: true
21+
time_series_dimension: true
2222
k8s:
2323
properties:
2424
pod:
2525
properties:
2626
uid:
2727
type: keyword
28-
dimension: true
28+
time_series_dimension: true
2929
name:
3030
type: keyword
3131
ip:

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,19 @@ public Builder(String name, ScriptCompiler scriptCompiler, boolean ignoreMalform
9090
= Parameter.boolParam("ignore_malformed", true, m -> toType(m).ignoreMalformed, ignoreMalformedByDefault);
9191
this.script.precludesParameters(nullValue, ignoreMalformed);
9292
addScriptValidation(script, indexed, hasDocValues);
93-
this.dimension = Parameter.boolParam("dimension", false, m -> toType(m).dimension, false)
94-
.addValidator(v -> {
95-
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
96-
throw new IllegalArgumentException(
97-
"Field [dimension] requires that [" + indexed.name + "] and [" + hasDocValues.name + "] are true"
98-
);
99-
}
100-
});
93+
this.dimension = TimeSeriesParams.dimensionParam(m -> toType(m).dimension).addValidator(v -> {
94+
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
95+
throw new IllegalArgumentException(
96+
"Field ["
97+
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
98+
+ "] requires that ["
99+
+ indexed.name
100+
+ "] and ["
101+
+ hasDocValues.name
102+
+ "] are true"
103+
);
104+
}
105+
});
101106
}
102107

103108
Builder nullValue(String nullValue) {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,16 @@ public Builder(String name, IndexAnalyzers indexAnalyzers, ScriptCompiler script
124124
this.script.precludesParameters(nullValue);
125125
addScriptValidation(script, indexed, hasDocValues);
126126

127-
this.dimension = Parameter.boolParam("dimension", false, m -> toType(m).dimension, false).addValidator(v -> {
127+
this.dimension = TimeSeriesParams.dimensionParam(m -> toType(m).dimension).addValidator(v -> {
128128
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
129129
throw new IllegalArgumentException(
130-
"Field [dimension] requires that [" + indexed.name + "] and [" + hasDocValues.name + "] are true"
130+
"Field ["
131+
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
132+
+ "] requires that ["
133+
+ indexed.name
134+
+ "] and ["
135+
+ hasDocValues.name
136+
+ "] are true"
131137
);
132138
}
133139
}).precludesParameters(normalizer, ignoreAbove);

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,24 @@ public Builder(String name, NumberType type, ScriptCompiler compiler, boolean ig
125125
this.nullValue = new Parameter<>("null_value", false, () -> null,
126126
(n, c, o) -> o == null ? null : type.parse(o, false), m -> toType(m).nullValue).acceptsNull();
127127

128-
this.dimension = Parameter.boolParam("dimension", false, m -> toType(m).dimension, false)
129-
.addValidator(v -> {
130-
if (v && EnumSet.of(NumberType.INTEGER, NumberType.LONG, NumberType.BYTE, NumberType.SHORT).contains(type) == false) {
131-
throw new IllegalArgumentException("Parameter [dimension] cannot be set to numeric type [" + type.name + "]");
132-
}
133-
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
134-
throw new IllegalArgumentException(
135-
"Field [dimension] requires that [" + indexed.name + "] and [" + hasDocValues.name + "] are true"
136-
);
137-
}
138-
});
128+
this.dimension = TimeSeriesParams.dimensionParam(m -> toType(m).dimension).addValidator(v -> {
129+
if (v && EnumSet.of(NumberType.INTEGER, NumberType.LONG, NumberType.BYTE, NumberType.SHORT).contains(type) == false) {
130+
throw new IllegalArgumentException(
131+
"Parameter [" + TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + "] cannot be set to numeric type [" + type.name + "]"
132+
);
133+
}
134+
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
135+
throw new IllegalArgumentException(
136+
"Field ["
137+
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
138+
+ "] requires that ["
139+
+ indexed.name
140+
+ "] and ["
141+
+ hasDocValues.name
142+
+ "] are true"
143+
);
144+
}
145+
});
139146

140147
this.metric = TimeSeriesParams.metricParam(m -> toType(m).metricType, MetricType.gauge, MetricType.counter)
141148
.addValidator(v -> {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
public final class TimeSeriesParams {
1919

2020
public static final String TIME_SERIES_METRIC_PARAM = "time_series_metric";
21+
public static final String TIME_SERIES_DIMENSION_PARAM = "time_series_dimension";
2122

22-
private TimeSeriesParams() {}
23+
private TimeSeriesParams() {
24+
}
2325

2426
public enum MetricType {
2527
gauge,
@@ -42,4 +44,8 @@ public static FieldMapper.Parameter<MetricType> metricParam(Function<FieldMapper
4244
).acceptsNull();
4345
}
4446

47+
public static FieldMapper.Parameter<Boolean> dimensionParam(Function<FieldMapper, Boolean> initializer) {
48+
return FieldMapper.Parameter.boolParam(TIME_SERIES_DIMENSION_PARAM, false, initializer, false);
49+
}
50+
4551
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public void testTooManyDimensionFields() {
340340
for (int i = 0; i <= max; i++) {
341341
b.startObject("field" + i)
342342
.field("type", randomFrom("ip", "keyword", "long", "integer", "byte", "short"))
343-
.field("dimension", true)
343+
.field("time_series_dimension", true)
344344
.endObject();
345345
}
346346
})));

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,33 +219,39 @@ public void testDimensionIndexedAndDocvalues() {
219219
{
220220
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
221221
minimalMapping(b);
222-
b.field("dimension", true).field("index", false).field("doc_values", false);
222+
b.field("time_series_dimension", true).field("index", false).field("doc_values", false);
223223
})));
224-
assertThat(e.getCause().getMessage(),
225-
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
224+
assertThat(
225+
e.getCause().getMessage(),
226+
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
227+
);
226228
}
227229
{
228230
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
229231
minimalMapping(b);
230-
b.field("dimension", true).field("index", true).field("doc_values", false);
232+
b.field("time_series_dimension", true).field("index", true).field("doc_values", false);
231233
})));
232-
assertThat(e.getCause().getMessage(),
233-
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
234+
assertThat(
235+
e.getCause().getMessage(),
236+
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
237+
);
234238
}
235239
{
236240
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
237241
minimalMapping(b);
238-
b.field("dimension", true).field("index", false).field("doc_values", true);
242+
b.field("time_series_dimension", true).field("index", false).field("doc_values", true);
239243
})));
240-
assertThat(e.getCause().getMessage(),
241-
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
244+
assertThat(
245+
e.getCause().getMessage(),
246+
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
247+
);
242248
}
243249
}
244250

245251
public void testDimensionMultiValuedField() throws IOException {
246252
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> {
247253
minimalMapping(b);
248-
b.field("dimension", true);
254+
b.field("time_series_dimension", true);
249255
}));
250256

251257
Exception e = expectThrows(MapperParsingException.class,

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -314,52 +314,52 @@ public void testDimension() throws IOException {
314314
public void testDimensionAndIgnoreAbove() {
315315
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
316316
minimalMapping(b);
317-
b.field("dimension", true).field("ignore_above", 2048);
317+
b.field("time_series_dimension", true).field("ignore_above", 2048);
318318
})));
319319
assertThat(e.getCause().getMessage(),
320-
containsString("Field [ignore_above] cannot be set in conjunction with field [dimension]"));
320+
containsString("Field [ignore_above] cannot be set in conjunction with field [time_series_dimension]"));
321321
}
322322

323323
public void testDimensionAndNormalizer() {
324324
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
325325
minimalMapping(b);
326-
b.field("dimension", true).field("normalizer", "my_normalizer");
326+
b.field("time_series_dimension", true).field("normalizer", "my_normalizer");
327327
})));
328328
assertThat(e.getCause().getMessage(),
329-
containsString("Field [normalizer] cannot be set in conjunction with field [dimension]"));
329+
containsString("Field [normalizer] cannot be set in conjunction with field [time_series_dimension]"));
330330
}
331331

332332
public void testDimensionIndexedAndDocvalues() {
333333
{
334334
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
335335
minimalMapping(b);
336-
b.field("dimension", true).field("index", false).field("doc_values", false);
336+
b.field("time_series_dimension", true).field("index", false).field("doc_values", false);
337337
})));
338338
assertThat(e.getCause().getMessage(),
339-
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
339+
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true"));
340340
}
341341
{
342342
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
343343
minimalMapping(b);
344-
b.field("dimension", true).field("index", true).field("doc_values", false);
344+
b.field("time_series_dimension", true).field("index", true).field("doc_values", false);
345345
})));
346346
assertThat(e.getCause().getMessage(),
347-
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
347+
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true"));
348348
}
349349
{
350350
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
351351
minimalMapping(b);
352-
b.field("dimension", true).field("index", false).field("doc_values", true);
352+
b.field("time_series_dimension", true).field("index", false).field("doc_values", true);
353353
})));
354354
assertThat(e.getCause().getMessage(),
355-
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
355+
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true"));
356356
}
357357
}
358358

359359
public void testDimensionMultiValuedField() throws IOException {
360360
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> {
361361
minimalMapping(b);
362-
b.field("dimension", true);
362+
b.field("time_series_dimension", true);
363363
}));
364364

365365
Exception e = expectThrows(MapperParsingException.class,
@@ -371,7 +371,7 @@ public void testDimensionMultiValuedField() throws IOException {
371371
public void testDimensionExtraLongKeyword() throws IOException {
372372
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> {
373373
minimalMapping(b);
374-
b.field("dimension", true);
374+
b.field("time_series_dimension", true);
375375
}));
376376

377377
Exception e = expectThrows(MapperParsingException.class,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ public void testDimension() throws IOException {
255255
// dimension = true is not allowed
256256
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
257257
minimalMapping(b);
258-
b.field("dimension", true);
258+
b.field("time_series_dimension", true);
259259
})));
260-
assertThat(e.getCause().getMessage(), containsString("Parameter [dimension] cannot be set"));
260+
assertThat(e.getCause().getMessage(), containsString("Parameter [time_series_dimension] cannot be set"));
261261
}
262262

263263
public void testMetricType() throws IOException {

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,39 @@ public void testDimensionIndexedAndDocvalues() {
3939
{
4040
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
4141
minimalMapping(b);
42-
b.field("dimension", true).field("index", false).field("doc_values", false);
42+
b.field("time_series_dimension", true).field("index", false).field("doc_values", false);
4343
})));
44-
assertThat(e.getCause().getMessage(),
45-
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
44+
assertThat(
45+
e.getCause().getMessage(),
46+
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
47+
);
4648
}
4749
{
4850
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
4951
minimalMapping(b);
50-
b.field("dimension", true).field("index", true).field("doc_values", false);
52+
b.field("time_series_dimension", true).field("index", true).field("doc_values", false);
5153
})));
52-
assertThat(e.getCause().getMessage(),
53-
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
54+
assertThat(
55+
e.getCause().getMessage(),
56+
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
57+
);
5458
}
5559
{
5660
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
5761
minimalMapping(b);
58-
b.field("dimension", true).field("index", false).field("doc_values", true);
62+
b.field("time_series_dimension", true).field("index", false).field("doc_values", true);
5963
})));
60-
assertThat(e.getCause().getMessage(),
61-
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
64+
assertThat(
65+
e.getCause().getMessage(),
66+
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
67+
);
6268
}
6369
}
6470

6571
public void testDimensionMultiValuedField() throws IOException {
6672
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> {
6773
minimalMapping(b);
68-
b.field("dimension", true);
74+
b.field("time_series_dimension", true);
6975
}));
7076

7177
Exception e = expectThrows(MapperParsingException.class,

test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ protected static void assertNoDocValuesField(LuceneDocument doc, String field) {
175175
protected <T> void assertDimension(boolean isDimension, Function<T, Boolean> checker) throws IOException {
176176
MapperService mapperService = createMapperService(fieldMapping(b -> {
177177
minimalMapping(b);
178-
b.field("dimension", isDimension);
178+
b.field("time_series_dimension", isDimension);
179179
}));
180180

181181
@SuppressWarnings("unchecked") // Syntactic sugar in tests
@@ -557,25 +557,25 @@ protected String randomFetchTestFormat() {
557557
*/
558558
protected void registerDimensionChecks(ParameterChecker checker) throws IOException {
559559
// dimension cannot be updated
560-
checker.registerConflictCheck("dimension", b -> b.field("dimension", true));
561-
checker.registerConflictCheck("dimension", b -> b.field("dimension", false));
562-
checker.registerConflictCheck("dimension",
560+
checker.registerConflictCheck("time_series_dimension", b -> b.field("time_series_dimension", true));
561+
checker.registerConflictCheck("time_series_dimension", b -> b.field("time_series_dimension", false));
562+
checker.registerConflictCheck("time_series_dimension",
563563
fieldMapping(b -> {
564564
minimalMapping(b);
565-
b.field("dimension", false);
565+
b.field("time_series_dimension", false);
566566
}),
567567
fieldMapping(b -> {
568568
minimalMapping(b);
569-
b.field("dimension", true);
569+
b.field("time_series_dimension", true);
570570
}));
571-
checker.registerConflictCheck("dimension",
571+
checker.registerConflictCheck("time_series_dimension",
572572
fieldMapping(b -> {
573573
minimalMapping(b);
574-
b.field("dimension", true);
574+
b.field("time_series_dimension", true);
575575
}),
576576
fieldMapping(b -> {
577577
minimalMapping(b);
578-
b.field("dimension", false);
578+
b.field("time_series_dimension", false);
579579
}));
580580
}
581581

0 commit comments

Comments
 (0)