Skip to content

Commit cd900e6

Browse files
committed
integrate into challenge tests
1 parent db3eb3a commit cd900e6

28 files changed

+420
-94
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ private GeometriesFallbackSyntheticSourceReader(Parser<T> geometryParser, Functi
217217
public void convertValue(Object value, List<BytesRef> accumulator) {
218218
final List<T> values = new ArrayList<>();
219219

220-
geometryParser.fetchFromSource(value, values::add);
220+
geometryParser.fetchFromSource(value, v -> {
221+
if (v != null) {
222+
values.add(v);
223+
} else if (nullValue != null) {
224+
values.add(nullValue);
225+
}
226+
});
221227
var formatted = formatter.apply(values);
222228

223229
for (var formattedValue : formatted) {
@@ -235,7 +241,13 @@ public void convertValue(Object value, List<BytesRef> accumulator) {
235241
public void parse(XContentParser parser, List<BytesRef> accumulator) throws IOException {
236242
final List<T> values = new ArrayList<>();
237243

238-
geometryParser.parseFromSource(parser, values::add);
244+
geometryParser.parseFromSource(parser, v -> {
245+
if (v != null) {
246+
values.add(v);
247+
} else if (nullValue != null) {
248+
values.add(nullValue);
249+
}
250+
});
239251
var formatted = formatter.apply(values);
240252

241253
for (var formattedValue : formatted) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private void generateMapping(
112112
)
113113
.mappingGenerator();
114114

115-
mappingParameters.put("type", leaf.type().toString());
115+
mappingParameters.put("type", leaf.type());
116116
mappingParameters.putAll(mappingParametersGenerator.get());
117117

118118
// For simplicity we only copy to keyword fields, synthetic source logic to handle copy_to is generic.

test/framework/src/main/java/org/elasticsearch/logsdb/datageneration/datasource/DataSourceHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ default DataSourceResponse.GeoShapeGenerator handle(DataSourceRequest.GeoShapeGe
6262
return null;
6363
}
6464

65+
default DataSourceResponse.ShapeGenerator handle(DataSourceRequest.ShapeGenerator request) {
66+
return null;
67+
}
68+
6569
default DataSourceResponse.NullWrapper handle(DataSourceRequest.NullWrapper request) {
6670
return null;
6771
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ public DataSourceResponse.GeoShapeGenerator accept(DataSourceHandler handler) {
100100
}
101101
}
102102

103+
record ShapeGenerator() implements DataSourceRequest<DataSourceResponse.ShapeGenerator> {
104+
public DataSourceResponse.ShapeGenerator accept(DataSourceHandler handler) {
105+
return handler.handle(this);
106+
}
107+
}
108+
103109
record NullWrapper() implements DataSourceRequest<DataSourceResponse.NullWrapper> {
104110
public DataSourceResponse.NullWrapper accept(DataSourceHandler handler) {
105111
return handler.handle(this);

test/framework/src/main/java/org/elasticsearch/logsdb/datageneration/datasource/DataSourceResponse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.logsdb.datageneration.datasource;
1111

1212
import org.elasticsearch.geometry.Geometry;
13-
import org.elasticsearch.logsdb.datageneration.FieldType;
1413

1514
import java.time.Instant;
1615
import java.util.Map;
@@ -45,6 +44,8 @@ record InstantGenerator(Supplier<Instant> generator) implements DataSourceRespon
4544

4645
record GeoShapeGenerator(Supplier<Geometry> generator) implements DataSourceResponse {}
4746

47+
record ShapeGenerator(Supplier<Geometry> generator) implements DataSourceResponse {}
48+
4849
record NullWrapper(Function<Supplier<Object>, Supplier<Object>> wrapper) implements DataSourceResponse {}
4950

5051
record ArrayWrapper(Function<Supplier<Object>, Supplier<Object>> wrapper) implements DataSourceResponse {}
@@ -68,7 +69,7 @@ interface ChildFieldGenerator extends DataSourceResponse {
6869
}
6970

7071
record FieldTypeGenerator(Supplier<FieldTypeInfo> generator) implements DataSourceResponse {
71-
public record FieldTypeInfo(FieldType fieldType) {}
72+
public record FieldTypeInfo(String fieldType) {}
7273
}
7374

7475
record ObjectArrayGenerator(Supplier<Optional<Integer>> lengthGenerator) implements DataSourceResponse {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public String generateFieldName() {
6262
public DataSourceResponse.FieldTypeGenerator handle(DataSourceRequest.FieldTypeGenerator request) {
6363

6464
return new DataSourceResponse.FieldTypeGenerator(
65-
() -> new DataSourceResponse.FieldTypeGenerator.FieldTypeInfo(ESTestCase.randomFrom(FieldType.values()))
65+
() -> new DataSourceResponse.FieldTypeGenerator.FieldTypeInfo(ESTestCase.randomFrom(FieldType.values()).toString())
6666
);
6767
}
6868

test/framework/src/main/java/org/elasticsearch/logsdb/datageneration/fields/leaf/Wrappers.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Wrappers {
1919
* Applies default wrappers for raw values - adds nulls and wraps values in arrays.
2020
* @return
2121
*/
22-
static Supplier<Object> defaults(Supplier<Object> rawValues, DataSource dataSource) {
22+
public static Supplier<Object> defaults(Supplier<Object> rawValues, DataSource dataSource) {
2323
var nulls = dataSource.get(new DataSourceRequest.NullWrapper());
2424
var arrays = dataSource.get(new DataSourceRequest.ArrayWrapper());
2525

@@ -30,7 +30,11 @@ static Supplier<Object> defaults(Supplier<Object> rawValues, DataSource dataSour
3030
* Applies default wrappers for raw values and also adds malformed values.
3131
* @return
3232
*/
33-
static Supplier<Object> defaultsWithMalformed(Supplier<Object> rawValues, Supplier<Object> malformedValues, DataSource dataSource) {
33+
public static Supplier<Object> defaultsWithMalformed(
34+
Supplier<Object> rawValues,
35+
Supplier<Object> malformedValues,
36+
DataSource dataSource
37+
) {
3438
var nulls = dataSource.get(new DataSourceRequest.NullWrapper());
3539
var malformed = dataSource.get(new DataSourceRequest.MalformedWrapper(malformedValues));
3640
var arrays = dataSource.get(new DataSourceRequest.ArrayWrapper());

test/framework/src/main/java/org/elasticsearch/logsdb/datageneration/matchers/Matcher.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public static MappingsStep<List<Map<String, Object>>> matchSource() {
3030
}
3131

3232
public interface MappingsStep<T> {
33-
SettingsStep<T> mappings(XContentBuilder actualMappings, XContentBuilder expectedMappings);
33+
SettingsStep<T> mappings(
34+
Map<String, Map<String, Object>> mappingLookup,
35+
XContentBuilder actualMappings,
36+
XContentBuilder expectedMappings
37+
);
3438
}
3539

3640
public interface SettingsStep<T> {
@@ -104,6 +108,7 @@ private static class SourceMatcherBuilder
104108
SettingsStep<List<Map<String, Object>>>,
105109
CompareStep<List<Map<String, Object>>>,
106110
ExpectedStep<List<Map<String, Object>>> {
111+
private Map<String, Map<String, Object>> mappingLookup;
107112
private XContentBuilder expectedMappings;
108113
private XContentBuilder actualMappings;
109114
private Settings.Builder expectedSettings;
@@ -121,9 +126,11 @@ public ExpectedStep<List<Map<String, Object>>> settings(Settings.Builder actualS
121126
private SourceMatcherBuilder() {}
122127

123128
public SettingsStep<List<Map<String, Object>>> mappings(
129+
final Map<String, Map<String, Object>> mappingLookup,
124130
final XContentBuilder actualMappings,
125131
final XContentBuilder expectedMappings
126132
) {
133+
this.mappingLookup = mappingLookup;
127134
this.actualMappings = actualMappings;
128135
this.expectedMappings = expectedMappings;
129136

@@ -132,8 +139,16 @@ public SettingsStep<List<Map<String, Object>>> mappings(
132139

133140
@Override
134141
public MatchResult isEqualTo(List<Map<String, Object>> actual) {
135-
return new SourceMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings, actual, expected, ignoringSort)
136-
.match();
142+
return new SourceMatcher(
143+
mappingLookup,
144+
actualMappings,
145+
actualSettings,
146+
expectedMappings,
147+
expectedSettings,
148+
actual,
149+
expected,
150+
ignoringSort
151+
).match();
137152
}
138153

139154
@Override

test/framework/src/main/java/org/elasticsearch/logsdb/datageneration/matchers/source/FieldSpecificMatcher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,13 @@ Object convert(Object value, Object nullValue, DateTimeFormatter dateTimeFormatt
473473
}
474474
}
475475

476-
class GeoShapeMatcher implements FieldSpecificMatcher {
476+
class ShapeMatcher implements FieldSpecificMatcher {
477477
private final XContentBuilder actualMappings;
478478
private final Settings.Builder actualSettings;
479479
private final XContentBuilder expectedMappings;
480480
private final Settings.Builder expectedSettings;
481481

482-
GeoShapeMatcher(
482+
ShapeMatcher(
483483
XContentBuilder actualMappings,
484484
Settings.Builder actualSettings,
485485
XContentBuilder expectedMappings,
@@ -498,7 +498,7 @@ public MatchResult match(
498498
Map<String, Object> actualMapping,
499499
Map<String, Object> expectedMapping
500500
) {
501-
// Since fallback synthetic source is used, should match exactly
501+
// Since fallback synthetic source is used, should always match exactly.
502502
return actual.equals(expected)
503503
? MatchResult.match()
504504
: MatchResult.noMatch(

test/framework/src/main/java/org/elasticsearch/logsdb/datageneration/matchers/source/SourceMatcher.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
import static org.elasticsearch.logsdb.datageneration.matchers.Messages.prettyPrintCollections;
2626

2727
public class SourceMatcher extends GenericEqualsMatcher<List<Map<String, Object>>> {
28+
private final Map<String, Map<String, Object>> mappingLookup;
29+
2830
private final Map<String, MappingTransforms.FieldMapping> actualNormalizedMapping;
2931
private final Map<String, MappingTransforms.FieldMapping> expectedNormalizedMapping;
3032

3133
private final Map<String, FieldSpecificMatcher> fieldSpecificMatchers;
3234
private final DynamicFieldMatcher dynamicFieldMatcher;
3335

3436
public SourceMatcher(
37+
final Map<String, Map<String, Object>> mappingLookup,
3538
final XContentBuilder actualMappings,
3639
final Settings.Builder actualSettings,
3740
final XContentBuilder expectedMappings,
@@ -42,6 +45,8 @@ public SourceMatcher(
4245
) {
4346
super(actualMappings, actualSettings, expectedMappings, expectedSettings, actual, expected, ignoringSort);
4447

48+
this.mappingLookup = mappingLookup;
49+
4550
var actualMappingAsMap = XContentHelper.convertToMap(BytesReference.bytes(actualMappings), false, actualMappings.contentType())
4651
.v2();
4752
this.actualNormalizedMapping = MappingTransforms.normalizeMapping(actualMappingAsMap);
@@ -95,10 +100,8 @@ public SourceMatcher(
95100
new FieldSpecificMatcher.CountedKeywordMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings)
96101
);
97102
put("boolean", new FieldSpecificMatcher.BooleanMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings));
98-
put(
99-
"geo_shape",
100-
new FieldSpecificMatcher.GeoShapeMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings)
101-
);
103+
put("geo_shape", new FieldSpecificMatcher.ShapeMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings));
104+
put("shape", new FieldSpecificMatcher.ShapeMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings));
102105
}
103106
};
104107
this.dynamicFieldMatcher = new DynamicFieldMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings);
@@ -118,8 +121,8 @@ public MatchResult match() {
118121
);
119122
}
120123

121-
var sortedAndFlattenedActual = actual.stream().map(SourceTransforms::normalize).toList();
122-
var sortedAndFlattenedExpected = expected.stream().map(SourceTransforms::normalize).toList();
124+
var sortedAndFlattenedActual = actual.stream().map(s -> SourceTransforms.normalize(s, mappingLookup)).toList();
125+
var sortedAndFlattenedExpected = expected.stream().map(s -> SourceTransforms.normalize(s, mappingLookup)).toList();
123126

124127
for (int i = 0; i < sortedAndFlattenedActual.size(); i++) {
125128
var actual = sortedAndFlattenedActual.get(i);

0 commit comments

Comments
 (0)