Skip to content

Commit 0037c8f

Browse files
committed
Improvements from review
1 parent 5ce0810 commit 0037c8f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

test/framework/src/main/java/org/elasticsearch/datageneration/datasource/DefaultObjectGenerationHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
import static org.elasticsearch.test.ESTestCase.randomRealisticUnicodeOfCodepointLengthBetween;
2121

2222
public class DefaultObjectGenerationHandler implements DataSourceHandler {
23+
24+
/**
25+
* Field names will not be generated which start with `_reserved_`. Handlers can safely
26+
* create field names starting with this prefix without the concern of randomly generated
27+
* fields having the same name.
28+
*/
29+
public static final String RESERVED_FIELD_NAME_PREFIX = "_reserved_";
30+
2331
@Override
2432
public DataSourceResponse.ChildFieldGenerator handle(DataSourceRequest.ChildFieldGenerator request) {
2533
return new DataSourceResponse.ChildFieldGenerator() {
@@ -57,6 +65,9 @@ public String generateFieldName() {
5765
if (fieldName.indexOf('.') != -1) {
5866
continue;
5967
}
68+
if (fieldName.startsWith(RESERVED_FIELD_NAME_PREFIX)) {
69+
continue;
70+
}
6071

6172
return fieldName;
6273
}

test/framework/src/main/java/org/elasticsearch/datageneration/datasource/MultifieldAddonHandler.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
public class MultifieldAddonHandler implements DataSourceHandler {
2020

21-
private static final String PLACEHOLDER_NAME = "_an_improbable_placeholder_name";
21+
private static final String PLACEHOLDER = DefaultObjectGenerationHandler.RESERVED_FIELD_NAME_PREFIX + "multifield";
2222
private static final float DEFAULT_CHANCE_OF_CHILD_FIELD = 0.5f;
2323
private final Map<FieldType, List<FieldType>> subfieldTypes;
2424
private final float chanceOfChildField;
@@ -47,7 +47,7 @@ public DataSourceResponse.LeafMappingParametersGenerator handle(DataSourceReques
4747

4848
// Need to delegate creation of the same type of field to other handlers. So skip request
4949
// if it's for the placeholder name used when creating the child and parent fields.
50-
if (request.fieldName().equals(PLACEHOLDER_NAME)) {
50+
if (request.fieldName().equals(PLACEHOLDER)) {
5151
return null;
5252
}
5353

@@ -76,9 +76,7 @@ public DataSourceResponse.LeafMappingParametersGenerator handle(DataSourceReques
7676

7777
private static Map<String, Object> getChildMappingForType(FieldType type, DataSourceRequest.LeafMappingParametersGenerator request) {
7878
Map<String, Object> mapping = getMappingForType(type, request);
79-
if (type == FieldType.KEYWORD) {
80-
mapping.remove("copy_to");
81-
}
79+
mapping.remove("copy_to");
8280
return mapping;
8381
}
8482

@@ -87,7 +85,7 @@ private static Map<String, Object> getMappingForType(FieldType type, DataSourceR
8785
.get(
8886
new DataSourceRequest.LeafMappingParametersGenerator(
8987
request.dataSource(),
90-
PLACEHOLDER_NAME,
88+
PLACEHOLDER,
9189
type.toString(),
9290
request.eligibleCopyToFields(),
9391
request.dynamicMapping()

0 commit comments

Comments
 (0)