[Rollup] Add scaled_float to allowed metric mapper types (elastic/x-pack-elasticsearch#4423)
We grab all the NumberFieldMappers to determine the whitelist of allowed number types, but `scaled_float` is in a module so it isn't picked up automatically. This commit adds `scaled_float` to the whitelist manually. Original commit: elastic/x-pack-elasticsearch@fb35440315
This commit is contained in:
parent
3bc6fd76a3
commit
2d6d3c3d74
|
@ -67,9 +67,14 @@ public class MetricConfig implements Writeable, ToXContentFragment {
|
|||
private static final ParseField AVG = new ParseField("avg");
|
||||
private static final ParseField VALUE_COUNT = new ParseField("value_count");
|
||||
|
||||
private static final List<String> MAPPER_TYPES = Stream.of(NumberFieldMapper.NumberType.values())
|
||||
.map(NumberFieldMapper.NumberType::typeName)
|
||||
.collect(Collectors.toList());
|
||||
private static final List<String> MAPPER_TYPES;
|
||||
static {
|
||||
List<String> types = Stream.of(NumberFieldMapper.NumberType.values())
|
||||
.map(NumberFieldMapper.NumberType::typeName)
|
||||
.collect(Collectors.toList());
|
||||
types.add("scaled_float"); // have to add manually since scaled_float is in a module
|
||||
MAPPER_TYPES = types;
|
||||
}
|
||||
|
||||
public static final ConstructingObjectParser<MetricConfig, Void> PARSER = new ConstructingObjectParser<>(
|
||||
NAME, a -> new MetricConfig((String)a[0], (List<String>) a[1]));
|
||||
|
|
|
@ -119,6 +119,77 @@ public class MetricsConfigSerializingTests extends AbstractSerializingTestCase<M
|
|||
.build();
|
||||
config.validateMappings(responseMap, e);
|
||||
assertThat(e.validationErrors().size(), equalTo(0));
|
||||
|
||||
|
||||
fieldCaps = mock(FieldCapabilities.class);
|
||||
when(fieldCaps.isAggregatable()).thenReturn(true);
|
||||
responseMap.put("my_field", Collections.singletonMap("double", fieldCaps));
|
||||
config = new MetricConfig.Builder()
|
||||
.setField("my_field")
|
||||
.setMetrics(Collections.singletonList("max"))
|
||||
.build();
|
||||
config.validateMappings(responseMap, e);
|
||||
assertThat(e.validationErrors().size(), equalTo(0));
|
||||
|
||||
fieldCaps = mock(FieldCapabilities.class);
|
||||
when(fieldCaps.isAggregatable()).thenReturn(true);
|
||||
responseMap.put("my_field", Collections.singletonMap("float", fieldCaps));
|
||||
config = new MetricConfig.Builder()
|
||||
.setField("my_field")
|
||||
.setMetrics(Collections.singletonList("max"))
|
||||
.build();
|
||||
config.validateMappings(responseMap, e);
|
||||
assertThat(e.validationErrors().size(), equalTo(0));
|
||||
|
||||
fieldCaps = mock(FieldCapabilities.class);
|
||||
when(fieldCaps.isAggregatable()).thenReturn(true);
|
||||
responseMap.put("my_field", Collections.singletonMap("short", fieldCaps));
|
||||
config = new MetricConfig.Builder()
|
||||
.setField("my_field")
|
||||
.setMetrics(Collections.singletonList("max"))
|
||||
.build();
|
||||
config.validateMappings(responseMap, e);
|
||||
assertThat(e.validationErrors().size(), equalTo(0));
|
||||
|
||||
fieldCaps = mock(FieldCapabilities.class);
|
||||
when(fieldCaps.isAggregatable()).thenReturn(true);
|
||||
responseMap.put("my_field", Collections.singletonMap("byte", fieldCaps));
|
||||
config = new MetricConfig.Builder()
|
||||
.setField("my_field")
|
||||
.setMetrics(Collections.singletonList("max"))
|
||||
.build();
|
||||
config.validateMappings(responseMap, e);
|
||||
assertThat(e.validationErrors().size(), equalTo(0));
|
||||
|
||||
fieldCaps = mock(FieldCapabilities.class);
|
||||
when(fieldCaps.isAggregatable()).thenReturn(true);
|
||||
responseMap.put("my_field", Collections.singletonMap("half_float", fieldCaps));
|
||||
config = new MetricConfig.Builder()
|
||||
.setField("my_field")
|
||||
.setMetrics(Collections.singletonList("max"))
|
||||
.build();
|
||||
config.validateMappings(responseMap, e);
|
||||
assertThat(e.validationErrors().size(), equalTo(0));
|
||||
|
||||
fieldCaps = mock(FieldCapabilities.class);
|
||||
when(fieldCaps.isAggregatable()).thenReturn(true);
|
||||
responseMap.put("my_field", Collections.singletonMap("scaled_float", fieldCaps));
|
||||
config = new MetricConfig.Builder()
|
||||
.setField("my_field")
|
||||
.setMetrics(Collections.singletonList("max"))
|
||||
.build();
|
||||
config.validateMappings(responseMap, e);
|
||||
assertThat(e.validationErrors().size(), equalTo(0));
|
||||
|
||||
fieldCaps = mock(FieldCapabilities.class);
|
||||
when(fieldCaps.isAggregatable()).thenReturn(true);
|
||||
responseMap.put("my_field", Collections.singletonMap("integer", fieldCaps));
|
||||
config = new MetricConfig.Builder()
|
||||
.setField("my_field")
|
||||
.setMetrics(Collections.singletonList("max"))
|
||||
.build();
|
||||
config.validateMappings(responseMap, e);
|
||||
assertThat(e.validationErrors().size(), equalTo(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue