Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,60 +630,18 @@ tests:
- class: org.elasticsearch.index.mapper.LongFieldMapperTests
method: testSyntheticSource
issue: https://github.com/elastic/elasticsearch/issues/133496
- class: org.elasticsearch.xpack.logsdb.qa.StandardVersusStandardReindexedIntoLogsDbChallengeRestIT
method: testEsqlSource
issue: https://github.com/elastic/elasticsearch/issues/132601
- class: org.elasticsearch.xpack.logsdb.qa.BulkChallengeRestIT
method: testEsqlSource
issue: https://github.com/elastic/elasticsearch/issues/132600
- class: org.elasticsearch.xpack.logsdb.qa.StoredSourceLogsDbVersusReindexedLogsDbChallengeRestIT
method: testEsqlSource
issue: https://github.com/elastic/elasticsearch/issues/132602
- class: org.elasticsearch.xpack.logsdb.qa.BulkChallengeRestIT
method: testMatchAllQuery
issue: https://github.com/elastic/elasticsearch/issues/133497
- class: org.elasticsearch.xpack.logsdb.qa.StandardVersusStandardReindexedIntoLogsDbChallengeRestIT
method: testMatchAllQuery
issue: https://github.com/elastic/elasticsearch/issues/133498
- class: org.elasticsearch.xpack.logsdb.qa.StoredSourceLogsDbVersusReindexedLogsDbChallengeRestIT
method: testMatchAllQuery
issue: https://github.com/elastic/elasticsearch/issues/133499
- class: org.elasticsearch.xpack.logsdb.qa.BulkChallengeRestIT
method: testRandomQueries
issue: https://github.com/elastic/elasticsearch/issues/133503
- class: org.elasticsearch.xpack.logsdb.qa.StandardVersusStandardReindexedIntoLogsDbChallengeRestIT
method: testRandomQueries
issue: https://github.com/elastic/elasticsearch/issues/133504
- class: org.elasticsearch.xpack.logsdb.qa.StoredSourceLogsDbVersusReindexedLogsDbChallengeRestIT
method: testRandomQueries
issue: https://github.com/elastic/elasticsearch/issues/133505
- class: org.elasticsearch.xpack.esql.qa.mixed.MixedClusterEsqlSpecIT
method: test {csv-spec:spatial.ConvertFromStringParseError}
issue: https://github.com/elastic/elasticsearch/issues/133507
- class: org.elasticsearch.test.rest.yaml.RcsCcsCommonYamlTestSuiteIT
method: test {p0=search.vectors/90_sparse_vector/Indexing and searching multi-value sparse vectors in >=8.15}
issue: https://github.com/elastic/elasticsearch/issues/133508
- class: org.elasticsearch.xpack.logsdb.qa.BulkChallengeRestIT
method: testTermsQuery
issue: https://github.com/elastic/elasticsearch/issues/133516
- class: org.elasticsearch.xpack.logsdb.qa.StandardVersusStandardReindexedIntoLogsDbChallengeRestIT
method: testTermsQuery
issue: https://github.com/elastic/elasticsearch/issues/133517
- class: org.elasticsearch.xpack.logsdb.qa.StoredSourceLogsDbVersusReindexedLogsDbChallengeRestIT
method: testTermsQuery
issue: https://github.com/elastic/elasticsearch/issues/133518
- class: org.elasticsearch.xpack.logsdb.qa.LogsDbVersusReindexedLogsDbChallengeRestIT
method: testEsqlSource
issue: https://github.com/elastic/elasticsearch/issues/133520
- class: org.elasticsearch.xpack.esql.action.EsqlActionBreakerIT
method: testTopNPushedToLucene
issue: https://github.com/elastic/elasticsearch/issues/133556
- class: org.elasticsearch.xpack.esql.action.EsqlActionBreakerIT
method: testFilterNestedFields
issue: https://github.com/elastic/elasticsearch/issues/133557
- class: org.elasticsearch.xpack.logsdb.qa.LogsDbVersusReindexedLogsDbChallengeRestIT
method: testMatchAllQuery
issue: https://github.com/elastic/elasticsearch/issues/133560
- class: org.elasticsearch.test.rest.yaml.RcsCcsCommonYamlTestSuiteIT
method: test {p0=search/10_source_filtering/no filtering}
issue: https://github.com/elastic/elasticsearch/issues/133561
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,12 @@ class NumberMatcher extends GenericMappingAwareMatcher {
@Override
Object convert(Object value, Object nullValue) {
if (value == null) {
return nullValue;
return cast(nullValue);
}

// Special case for number coercion from strings
if (value instanceof String s && s.isEmpty()) {
return nullValue;
return cast(nullValue);
}

// Attempt to coerce string values into numbers
Expand All @@ -394,9 +395,13 @@ Object convert(Object value, Object nullValue) {
}
}

// When a number mapping is coerced, the expected value will come from the above parser and will have the correct java type.
// Whereas, if it fits, the actual value will be in an Integer or a Double. To correctly treat expected and actual values as
// equal the actual value must be cast to the appropriate type.
return cast(value);
}

// When a number mapping is coerced, the expected value will come from the above parser and will have the correct java type.
// Whereas, if it fits, the actual value will be in an Integer or a Double. To correctly treat expected and actual values as
// equal the actual value must be cast to the appropriate type.
private Object cast(Object value) {
if (value instanceof Integer v) {
return switch (fieldType) {
case LONG -> v.longValue();
Expand All @@ -408,7 +413,6 @@ Object convert(Object value, Object nullValue) {
if (value instanceof Double v) {
return fieldType == FieldType.FLOAT ? v.floatValue() : value;
}

return value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,52 @@ public void testCoercedNumberField() throws IOException {
var sut = new SourceMatcher(Map.of(), mapping, Settings.builder(), mapping, Settings.builder(), actual, expected, false);
assertTrue(sut.match().isMatch());
}

public void testNullValueIntegerNumericMatcherCastsType() throws IOException {
String type = randomFrom("byte", "short", "integer", "long");
int nullValue = 51;
List<Map<String, Object>> actual = List.of(Map.of("field", List.of(5, nullValue, "")));
List<Map<String, Object>> expected = List.of(Map.of("field", List.of(5, nullValue, nullValue)));

var mapping = XContentBuilder.builder(XContentType.JSON.xContent());
mapping.startObject();
mapping.startObject("_doc");
{
mapping.startObject("field");
{
mapping.field("type", type);
mapping.field("null_value", nullValue);
}
mapping.endObject();
}
mapping.endObject();
mapping.endObject();

var sut = new SourceMatcher(Map.of(), mapping, Settings.builder(), mapping, Settings.builder(), actual, expected, false);
assertTrue(sut.match().isMatch());
}

public void testNullValueFloatingPointNumericMatcherCastsType() throws IOException {
String type = randomFrom("float", "double");
double nullValue = 51.123;
List<Map<String, Object>> actual = List.of(Map.of("field", List.of(5, nullValue, "")));
List<Map<String, Object>> expected = List.of(Map.of("field", List.of(5, nullValue, nullValue)));

var mapping = XContentBuilder.builder(XContentType.JSON.xContent());
mapping.startObject();
mapping.startObject("_doc");
{
mapping.startObject("field");
{
mapping.field("type", type);
mapping.field("null_value", nullValue);
}
mapping.endObject();
}
mapping.endObject();
mapping.endObject();

var sut = new SourceMatcher(Map.of(), mapping, Settings.builder(), mapping, Settings.builder(), actual, expected, false);
assertTrue(sut.match().isMatch());
}
}