Skip to content

Commit 2fd99a5

Browse files
committed
wip
1 parent da14832 commit 2fd99a5

File tree

5 files changed

+174
-116
lines changed

5 files changed

+174
-116
lines changed

server/src/test/java/org/elasticsearch/index/mapper/blockloader/TextFieldWithParentBlockLoaderTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@ public DataSourceResponse.LeafMappingParametersGenerator handle(DataSourceReques
3131
// We need to force multi field generation
3232
return new DataSourceResponse.LeafMappingParametersGenerator(() -> {
3333
var defaultSupplier = DefaultMappingParametersHandler.keywordMapping(
34-
request,
35-
DefaultMappingParametersHandler.commonMappingParameters()
34+
request
3635
);
3736
var mapping = defaultSupplier.get();
3837
// we don't need this here
3938
mapping.remove("copy_to");
4039

41-
var textMultiFieldMappingSupplier = DefaultMappingParametersHandler.textMapping(request, new HashMap<>());
40+
var textMultiFieldMappingSupplier = DefaultMappingParametersHandler.textMapping(request);
4241
var textMultiFieldMapping = textMultiFieldMappingSupplier.get();
4342
textMultiFieldMapping.put("type", "text");
4443
textMultiFieldMapping.remove("fields");

test/framework/src/main/java/org/elasticsearch/datageneration/MappingGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private void generateMapping(
104104
var mappingParametersGenerator = specification.dataSource()
105105
.get(
106106
new DataSourceRequest.LeafMappingParametersGenerator(
107+
specification.dataSource(),
107108
fieldName,
108109
leaf.type(),
109110
context.eligibleCopyToDestinations(),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public DataSourceResponse.ObjectArrayGenerator accept(DataSourceHandler handler)
199199
}
200200

201201
record LeafMappingParametersGenerator(
202+
DataSource dataSource,
202203
String fieldName,
203204
String fieldType,
204205
Set<String> eligibleCopyToFields,

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

Lines changed: 87 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,27 @@ public DataSourceResponse.LeafMappingParametersGenerator handle(DataSourceReques
3636
return null;
3737
}
3838

39-
var map = commonMappingParameters();
40-
if (ESTestCase.randomBoolean()) {
41-
map.put(Mapper.SYNTHETIC_SOURCE_KEEP_PARAM, ESTestCase.randomFrom("none", "arrays", "all"));
42-
}
43-
4439
return new DataSourceResponse.LeafMappingParametersGenerator(switch (fieldType) {
45-
case KEYWORD -> keywordMapping(request, map);
46-
case LONG, INTEGER, SHORT, BYTE, DOUBLE, FLOAT, HALF_FLOAT, UNSIGNED_LONG -> numberMapping(map, fieldType);
47-
case SCALED_FLOAT -> scaledFloatMapping(map);
48-
case COUNTED_KEYWORD -> plain(Map.of("index", ESTestCase.randomBoolean()));
49-
case BOOLEAN -> booleanMapping(map);
50-
case DATE -> dateMapping(map);
51-
case GEO_POINT -> geoPointMapping(map);
52-
case TEXT -> textMapping(request, new HashMap<>());
53-
case IP -> ipMapping(map);
54-
case CONSTANT_KEYWORD -> constantKeywordMapping(new HashMap<>());
55-
case WILDCARD -> wildcardMapping(new HashMap<>());
40+
case KEYWORD -> keywordMapping(request);
41+
case LONG, INTEGER, SHORT, BYTE, DOUBLE, FLOAT, HALF_FLOAT, UNSIGNED_LONG -> numberMapping(fieldType);
42+
case SCALED_FLOAT -> scaledFloatMapping();
43+
case COUNTED_KEYWORD -> countedKeywordMapping();
44+
case BOOLEAN -> booleanMapping();
45+
case DATE -> dateMapping();
46+
case GEO_POINT -> geoPointMapping();
47+
case TEXT -> textMapping(request);
48+
case IP -> ipMapping();
49+
case CONSTANT_KEYWORD -> constantKeywordMapping();
50+
case WILDCARD -> wildcardMapping();
5651
});
5752
}
5853

59-
private Supplier<Map<String, Object>> plain(Map<String, Object> injected) {
60-
return () -> injected;
61-
}
62-
63-
private Supplier<Map<String, Object>> numberMapping(Map<String, Object> injected, FieldType fieldType) {
54+
private Supplier<Map<String, Object>> numberMapping(FieldType fieldType) {
6455
return () -> {
56+
var mapping = commonMappingParameters();
57+
6558
if (ESTestCase.randomBoolean()) {
66-
injected.put("ignore_malformed", ESTestCase.randomBoolean());
59+
mapping.put("ignore_malformed", ESTestCase.randomBoolean());
6760
}
6861
if (ESTestCase.randomDouble() <= 0.2) {
6962
Number value = switch (fieldType) {
@@ -77,18 +70,19 @@ private Supplier<Map<String, Object>> numberMapping(Map<String, Object> injected
7770
default -> throw new IllegalStateException("Unexpected field type");
7871
};
7972

80-
injected.put("null_value", value);
73+
mapping.put("null_value", value);
8174
}
8275

83-
return injected;
76+
return mapping;
8477
};
8578
}
8679

8780
public static Supplier<Map<String, Object>> keywordMapping(
88-
DataSourceRequest.LeafMappingParametersGenerator request,
89-
Map<String, Object> injected
81+
DataSourceRequest.LeafMappingParametersGenerator request
9082
) {
9183
return () -> {
84+
var mapping = commonMappingParameters();
85+
9286
// Inject copy_to sometimes but reflect that it is not widely used in reality.
9387
// We only add copy_to to keywords because we get into trouble with numeric fields that are copied to dynamic fields.
9488
// If first copied value is numeric, dynamic field is created with numeric field type and then copy of text values fail.
@@ -100,160 +94,179 @@ public static Supplier<Map<String, Object>> keywordMapping(
10094
.collect(Collectors.toSet());
10195

10296
if (options.isEmpty() == false) {
103-
injected.put("copy_to", ESTestCase.randomFrom(options));
97+
mapping.put("copy_to", ESTestCase.randomFrom(options));
10498
}
10599
}
106100

107101
if (ESTestCase.randomDouble() <= 0.2) {
108-
injected.put("ignore_above", ESTestCase.randomIntBetween(1, 100));
102+
mapping.put("ignore_above", ESTestCase.randomIntBetween(1, 100));
109103
}
110104
if (ESTestCase.randomDouble() <= 0.2) {
111-
injected.put("null_value", ESTestCase.randomAlphaOfLengthBetween(0, 10));
105+
mapping.put("null_value", ESTestCase.randomAlphaOfLengthBetween(0, 10));
112106
}
113107

114108
if (ESTestCase.randomDouble() <= 0.1) {
115-
var textMultiFieldMapping = textMapping(request, new HashMap<>()).get();
109+
var textMultiFieldMapping = textMapping(request).get();
116110
textMultiFieldMapping.put("type", "text");
117111
textMultiFieldMapping.remove("fields");
118112

119-
injected.put("fields", Map.of("txt", textMultiFieldMapping));
113+
mapping.put("fields", Map.of("txt", textMultiFieldMapping));
120114
}
121115

122-
return injected;
116+
return mapping;
123117
};
124118
}
125119

126-
private Supplier<Map<String, Object>> scaledFloatMapping(Map<String, Object> injected) {
120+
private Supplier<Map<String, Object>> scaledFloatMapping() {
127121
return () -> {
128-
injected.put("scaling_factor", ESTestCase.randomFrom(10, 1000, 100000, 100.5));
122+
var mapping = commonMappingParameters();
123+
124+
mapping.put("scaling_factor", ESTestCase.randomFrom(10, 1000, 100000, 100.5));
129125

130126
if (ESTestCase.randomDouble() <= 0.2) {
131-
injected.put("null_value", ESTestCase.randomDouble());
127+
mapping.put("null_value", ESTestCase.randomDouble());
132128
}
133129

134130
if (ESTestCase.randomBoolean()) {
135-
injected.put("ignore_malformed", ESTestCase.randomBoolean());
131+
mapping.put("ignore_malformed", ESTestCase.randomBoolean());
136132
}
137133

138-
return injected;
134+
return mapping;
139135
};
140136
}
141137

142-
private Supplier<Map<String, Object>> booleanMapping(Map<String, Object> injected) {
138+
private Supplier<Map<String, Object>> countedKeywordMapping() {
139+
return () -> Map.of("index", ESTestCase.randomBoolean());
140+
}
141+
142+
private Supplier<Map<String, Object>> booleanMapping() {
143143
return () -> {
144+
var mapping = commonMappingParameters();
145+
144146
if (ESTestCase.randomDouble() <= 0.2) {
145-
injected.put("null_value", ESTestCase.randomFrom(true, false, "true", "false"));
147+
mapping.put("null_value", ESTestCase.randomFrom(true, false, "true", "false"));
146148
}
147149

148150
if (ESTestCase.randomBoolean()) {
149-
injected.put("ignore_malformed", ESTestCase.randomBoolean());
151+
mapping.put("ignore_malformed", ESTestCase.randomBoolean());
150152
}
151153

152-
return injected;
154+
return mapping;
153155
};
154156
}
155157

156158
// just a custom format, specific format does not matter
157159
private static final String FORMAT = "yyyy_MM_dd_HH_mm_ss_n";
158160

159-
private Supplier<Map<String, Object>> dateMapping(Map<String, Object> injected) {
161+
private Supplier<Map<String, Object>> dateMapping() {
160162
return () -> {
163+
var mapping = commonMappingParameters();
164+
161165
String format = null;
162166
if (ESTestCase.randomBoolean()) {
163167
format = FORMAT;
164-
injected.put("format", format);
168+
mapping.put("format", format);
165169
}
166170

167171
if (ESTestCase.randomDouble() <= 0.2) {
168172
var instant = ESTestCase.randomInstantBetween(Instant.parse("2300-01-01T00:00:00Z"), Instant.parse("2350-01-01T00:00:00Z"));
169173

170174
if (format == null) {
171-
injected.put("null_value", instant.toEpochMilli());
175+
mapping.put("null_value", instant.toEpochMilli());
172176
} else {
173-
injected.put(
177+
mapping.put(
174178
"null_value",
175179
DateTimeFormatter.ofPattern(format, Locale.ROOT).withZone(ZoneId.from(ZoneOffset.UTC)).format(instant)
176180
);
177181
}
178182
}
179183

180184
if (ESTestCase.randomBoolean()) {
181-
injected.put("ignore_malformed", ESTestCase.randomBoolean());
185+
mapping.put("ignore_malformed", ESTestCase.randomBoolean());
182186
}
183187

184-
return injected;
188+
return mapping;
185189
};
186190
}
187191

188-
private Supplier<Map<String, Object>> geoPointMapping(Map<String, Object> injected) {
192+
private Supplier<Map<String, Object>> geoPointMapping() {
189193
return () -> {
194+
var mapping = commonMappingParameters();
195+
190196
if (ESTestCase.randomDouble() <= 0.2) {
191197
var point = GeometryTestUtils.randomPoint(false);
192-
injected.put("null_value", WellKnownText.toWKT(point));
198+
mapping.put("null_value", WellKnownText.toWKT(point));
193199
}
194200

195201
if (ESTestCase.randomBoolean()) {
196-
injected.put("ignore_malformed", ESTestCase.randomBoolean());
202+
mapping.put("ignore_malformed", ESTestCase.randomBoolean());
197203
}
198204

199-
return injected;
205+
return mapping;
200206
};
201207
}
202208

203209
public static Supplier<Map<String, Object>> textMapping(
204-
DataSourceRequest.LeafMappingParametersGenerator request,
205-
Map<String, Object> injected
210+
DataSourceRequest.LeafMappingParametersGenerator request
206211
) {
207212
return () -> {
208-
injected.put("store", ESTestCase.randomBoolean());
209-
injected.put("index", ESTestCase.randomBoolean());
213+
var mapping = new HashMap<String, Object>();
214+
215+
mapping.put("store", ESTestCase.randomBoolean());
216+
mapping.put("index", ESTestCase.randomBoolean());
210217

211218
if (ESTestCase.randomDouble() <= 0.1) {
212-
var keywordMultiFieldMapping = keywordMapping(request, commonMappingParameters()).get();
219+
var keywordMultiFieldMapping = keywordMapping(request).get();
213220
keywordMultiFieldMapping.put("type", "keyword");
214221
keywordMultiFieldMapping.remove("copy_to");
215222

216-
injected.put("fields", Map.of("kwd", keywordMultiFieldMapping));
223+
mapping.put("fields", Map.of("kwd", keywordMultiFieldMapping));
217224
}
218225

219-
return injected;
226+
return mapping;
220227
};
221228
}
222229

223-
private Supplier<Map<String, Object>> ipMapping(Map<String, Object> injected) {
230+
private Supplier<Map<String, Object>> ipMapping() {
224231
return () -> {
232+
var mapping = commonMappingParameters();
233+
225234
if (ESTestCase.randomDouble() <= 0.2) {
226-
injected.put("null_value", NetworkAddress.format(ESTestCase.randomIp(ESTestCase.randomBoolean())));
235+
mapping.put("null_value", NetworkAddress.format(ESTestCase.randomIp(ESTestCase.randomBoolean())));
227236
}
228237

229238
if (ESTestCase.randomBoolean()) {
230-
injected.put("ignore_malformed", ESTestCase.randomBoolean());
239+
mapping.put("ignore_malformed", ESTestCase.randomBoolean());
231240
}
232241

233-
return injected;
242+
return mapping;
234243
};
235244
}
236245

237-
private Supplier<Map<String, Object>> constantKeywordMapping(Map<String, Object> injected) {
246+
private Supplier<Map<String, Object>> constantKeywordMapping() {
238247
return () -> {
248+
var mapping = new HashMap<String, Object>();
249+
239250
// value is optional and can be set from the first document
240251
// we don't cover this case here
241-
injected.put("value", ESTestCase.randomAlphaOfLengthBetween(0, 10));
252+
mapping.put("value", ESTestCase.randomAlphaOfLengthBetween(0, 10));
242253

243-
return injected;
254+
return mapping;
244255
};
245256
}
246257

247-
private Supplier<Map<String, Object>> wildcardMapping(Map<String, Object> injected) {
258+
private Supplier<Map<String, Object>> wildcardMapping() {
248259
return () -> {
260+
var mapping = new HashMap<String, Object>();
261+
249262
if (ESTestCase.randomDouble() <= 0.2) {
250-
injected.put("ignore_above", ESTestCase.randomIntBetween(1, 100));
263+
mapping.put("ignore_above", ESTestCase.randomIntBetween(1, 100));
251264
}
252265
if (ESTestCase.randomDouble() <= 0.2) {
253-
injected.put("null_value", ESTestCase.randomAlphaOfLengthBetween(0, 10));
266+
mapping.put("null_value", ESTestCase.randomAlphaOfLengthBetween(0, 10));
254267
}
255268

256-
return injected;
269+
return mapping;
257270
};
258271
}
259272

@@ -262,6 +275,11 @@ public static HashMap<String, Object> commonMappingParameters() {
262275
map.put("store", ESTestCase.randomBoolean());
263276
map.put("index", ESTestCase.randomBoolean());
264277
map.put("doc_values", ESTestCase.randomBoolean());
278+
279+
if (ESTestCase.randomBoolean()) {
280+
map.put(Mapper.SYNTHETIC_SOURCE_KEEP_PARAM, ESTestCase.randomFrom("none", "arrays", "all"));
281+
}
282+
265283
return map;
266284
}
267285

0 commit comments

Comments
 (0)