Skip to content

Commit 284b621

Browse files
lktskanoshiou
andauthored
Fix failed ScaledFloatFieldMapperTests (#123144) (#123184)
(cherry picked from commit 7326928) # Conflicts: # muted-tests.yml Co-authored-by: kanoshiou <[email protected]>
1 parent 813e7ac commit 284b621

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapperTests.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@
3131
import org.elasticsearch.xcontent.XContentBuilder;
3232
import org.elasticsearch.xcontent.XContentFactory;
3333
import org.elasticsearch.xcontent.XContentType;
34-
import org.hamcrest.Matcher;
3534
import org.junit.AssumptionViolatedException;
3635

3736
import java.io.IOException;
3837
import java.util.Collection;
3938
import java.util.Collections;
4039
import java.util.List;
4140
import java.util.Map;
42-
import java.util.function.Function;
4341
import java.util.function.Supplier;
4442
import java.util.stream.Stream;
4543

@@ -48,7 +46,6 @@
4846
import static org.hamcrest.Matchers.empty;
4947
import static org.hamcrest.Matchers.equalTo;
5048
import static org.hamcrest.Matchers.is;
51-
import static org.hamcrest.Matchers.notANumber;
5249

5350
public class ScaledFloatFieldMapperTests extends NumberFieldMapperTests {
5451

@@ -382,7 +379,7 @@ public SyntheticSourceExample example(int maxValues) {
382379
if (randomBoolean()) {
383380
Value v = generateValue();
384381
if (v.malformedOutput == null) {
385-
return new SyntheticSourceExample(v.input, v.output, roundDocValues(v.output), this::mapping);
382+
return new SyntheticSourceExample(v.input, v.output, this::mapping);
386383
}
387384
return new SyntheticSourceExample(v.input, v.malformedOutput, null, this::mapping);
388385
}
@@ -396,9 +393,7 @@ public SyntheticSourceExample example(int maxValues) {
396393
List<Object> outList = Stream.concat(outputFromDocValues.stream(), malformedOutput).toList();
397394
Object out = outList.size() == 1 ? outList.get(0) : outList;
398395

399-
List<Double> outBlockList = outputFromDocValues.stream().map(this::roundDocValues).sorted().toList();
400-
Object outBlock = outBlockList.size() == 1 ? outBlockList.get(0) : outBlockList;
401-
return new SyntheticSourceExample(in, out, outBlock, this::mapping);
396+
return new SyntheticSourceExample(in, out, this::mapping);
402397
}
403398

404399
private record Value(Object input, Double output, Object malformedOutput) {}
@@ -442,16 +437,6 @@ private double round(double d) {
442437
return decoded;
443438
}
444439

445-
private double roundDocValues(double d) {
446-
// Special case due to rounding, see implementation.
447-
if (Math.abs(d) == Double.MAX_VALUE) {
448-
return d;
449-
}
450-
451-
long encoded = Math.round(d * scalingFactor);
452-
return encoded * (1 / scalingFactor);
453-
}
454-
455440
private void mapping(XContentBuilder b) throws IOException {
456441
b.field("type", "scaled_float");
457442
b.field("scaling_factor", scalingFactor);
@@ -475,14 +460,9 @@ public List<SyntheticSourceInvalidExample> invalidExample() throws IOException {
475460
}
476461
}
477462

478-
@Override
479-
protected Function<Object, Object> loadBlockExpected() {
480-
return v -> (Number) v;
481-
}
482-
483-
@Override
484-
protected Matcher<?> blockItemMatcher(Object expected) {
485-
return "NaN".equals(expected) ? notANumber() : equalTo(expected);
463+
protected BlockReaderSupport getSupportedReaders(MapperService mapper, String loaderFieldName) {
464+
assumeTrue("Disabled, tested by ScaledFloatFieldBlockLoaderTests instead", false);
465+
return null;
486466
}
487467

488468
@Override

0 commit comments

Comments
 (0)