Skip to content

Commit 84ba583

Browse files
pabloemelasticsearchmachine
andauthored
A random-random test for time-series data (#132556)
* First test case in prototype messy test file * [CI] Auto commit changes from spotless * First two randomized test cases * smol cleanup * [CI] Auto commit changes from spotless * cleanup and ready for first check * Address comments * addressing comments * more addressing comments * include values check that guarantees avg,count are off --------- Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
1 parent f59ab9e commit 84ba583

File tree

10 files changed

+449
-10
lines changed

10 files changed

+449
-10
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public enum FieldType {
5151
TEXT("text"),
5252
IP("ip"),
5353
CONSTANT_KEYWORD("constant_keyword"),
54+
PASSTHROUGH("passthrough"), // For now this field type does not have default generators.
5455
WILDCARD("wildcard"),
5556
MATCH_ONLY_TEXT("match_only_text");
5657

@@ -81,6 +82,7 @@ public FieldDataGenerator generator(String fieldName, DataSource dataSource) {
8182
case CONSTANT_KEYWORD -> new ConstantKeywordFieldDataGenerator();
8283
case WILDCARD -> new WildcardFieldDataGenerator(dataSource);
8384
case MATCH_ONLY_TEXT -> new MatchOnlyTextFieldDataGenerator(dataSource);
85+
case PASSTHROUGH -> throw new IllegalArgumentException("Passthrough field type does not have a default generator");
8486
};
8587
}
8688

@@ -104,8 +106,9 @@ public static FieldType tryParse(String name) {
104106
case "ip" -> FieldType.IP;
105107
case "constant_keyword" -> FieldType.CONSTANT_KEYWORD;
106108
case "wildcard" -> FieldType.WILDCARD;
109+
case "passthrough" -> FieldType.PASSTHROUGH;
107110
case "match_only_text" -> FieldType.MATCH_ONLY_TEXT;
108-
default -> null;
111+
default -> throw new IllegalArgumentException("Unknown field type: " + name);
109112
};
110113
}
111114

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public Mapping generate(Template template) {
6767
if (specification.fullyDynamicMapping()) {
6868
// Has to be "true" for fully dynamic mapping
6969
topLevelMappingParameters.remove("dynamic");
70-
7170
return new Mapping(rawMapping, lookup);
7271
}
7372

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public <T extends DataSourceResponse> T get(DataSourceRequest<T> request) {
4646
return response;
4747
}
4848
}
49-
50-
throw new IllegalStateException("Request is not supported by data source");
49+
throw new IllegalStateException(
50+
"Request is not supported by data source. Request: "
51+
+ request.toString()
52+
+ "\n"
53+
+ "Available handlers: "
54+
+ handlers.stream().map(Object::getClass).map(Class::getName).toList().toString()
55+
);
5156
}
5257
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public DataSourceResponse.LeafMappingParametersGenerator handle(DataSourceReques
4949
case CONSTANT_KEYWORD -> constantKeywordMapping();
5050
case WILDCARD -> wildcardMapping();
5151
case MATCH_ONLY_TEXT -> matchOnlyTextMapping();
52+
case PASSTHROUGH -> throw new IllegalArgumentException("Unsupported field type: " + fieldType);
5253
});
5354
}
5455

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import org.elasticsearch.datageneration.FieldType;
1313
import org.elasticsearch.test.ESTestCase;
1414

15+
import java.util.Arrays;
1516
import java.util.Optional;
1617
import java.util.Set;
18+
import java.util.stream.Collectors;
1719

1820
import static org.elasticsearch.test.ESTestCase.randomDouble;
1921
import static org.elasticsearch.test.ESTestCase.randomIntBetween;
@@ -77,13 +79,17 @@ public String generateFieldName() {
7779

7880
// UNSIGNED_LONG is excluded because it is mapped as long
7981
// and values larger than long fail to parse.
80-
private static final Set<FieldType> EXCLUDED_FROM_DYNAMIC_MAPPING = Set.of(FieldType.UNSIGNED_LONG);
82+
private static final Set<FieldType> EXCLUDED_FROM_DYNAMIC_MAPPING = Set.of(FieldType.UNSIGNED_LONG, FieldType.PASSTHROUGH);
83+
private static final Set<FieldType> ALLOWED_FIELD_TYPES = Arrays.stream(FieldType.values())
84+
.filter(fieldType -> EXCLUDED_FROM_DYNAMIC_MAPPING.contains(fieldType) == false)
85+
.collect(Collectors.toSet());
8186

8287
@Override
8388
public DataSourceResponse.FieldTypeGenerator handle(DataSourceRequest.FieldTypeGenerator request) {
84-
return new DataSourceResponse.FieldTypeGenerator(
85-
() -> new DataSourceResponse.FieldTypeGenerator.FieldTypeInfo(ESTestCase.randomFrom(FieldType.values()).toString())
86-
);
89+
return new DataSourceResponse.FieldTypeGenerator(() -> {
90+
var fieldType = ESTestCase.randomFrom(ALLOWED_FIELD_TYPES);
91+
return new DataSourceResponse.FieldTypeGenerator.FieldTypeInfo(fieldType.toString());
92+
});
8793
}
8894

8995
@Override

test/framework/src/test/java/org/elasticsearch/logsdb/datageneration/DataGenerationTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.xpack.wildcard.Wildcard;
3232

3333
import java.io.IOException;
34+
import java.util.Arrays;
3435
import java.util.Collection;
3536
import java.util.List;
3637
import java.util.Optional;
@@ -94,11 +95,16 @@ public DataSourceResponse.ChildFieldGenerator handle(DataSourceRequest.ChildFiel
9495
return testChildFieldGenerator;
9596
}
9697

98+
private static final FieldType[] SUPPORTED_FIELD_TYPES = Arrays.asList(FieldType.values())
99+
.stream()
100+
.filter(fieldType -> fieldType != FieldType.PASSTHROUGH)
101+
.toArray(FieldType[]::new);
102+
97103
@Override
98104
public DataSourceResponse.FieldTypeGenerator handle(DataSourceRequest.FieldTypeGenerator request) {
99105
return new DataSourceResponse.FieldTypeGenerator(
100106
() -> new DataSourceResponse.FieldTypeGenerator.FieldTypeInfo(
101-
FieldType.values()[generatedFields++ % FieldType.values().length].toString()
107+
SUPPORTED_FIELD_TYPES[generatedFields++ % SUPPORTED_FIELD_TYPES.length].toString()
102108
)
103109
);
104110

x-pack/plugin/esql/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ dependencies {
3535
compileOnly project(':modules:lang-painless:spi')
3636
compileOnly project(xpackModule('esql-core'))
3737
compileOnly project(xpackModule('ml'))
38+
compileOnly project(path: xpackModule('mapper-aggregate-metric'))
39+
compileOnly project(path: xpackModule('downsample'))
3840
implementation project(xpackModule('kql'))
3941
implementation project('compute')
4042
implementation project('compute:ann')

0 commit comments

Comments
 (0)