Fixing Scaled float field mapper to respect ignoreMalformed setting (#2918)

* Fixing Scaled float field mapper to respect ignoreMalformed setting

Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>

* Adding unit tests

Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>
This commit is contained in:
Sarat Vemulapalli 2022-04-15 16:07:10 -07:00 committed by GitHub
parent ca9151fa24
commit 1eda2bbe3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -32,6 +32,7 @@
package org.opensearch.index.mapper;
import com.fasterxml.jackson.core.JsonParseException;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReaderContext;
@ -392,7 +393,7 @@ public class ScaledFloatFieldMapper extends ParametrizedFieldMapper {
} else {
try {
numericValue = parse(parser, coerce.value());
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | JsonParseException e) {
if (ignoreMalformed.value()) {
return;
} else {

View File

@ -229,6 +229,7 @@ public class ScaledFloatFieldMapperTests extends MapperTestCase {
public void testIgnoreMalformed() throws Exception {
doTestIgnoreMalformed("a", "For input string: \"a\"");
doTestIgnoreMalformed(true, "Current token (VALUE_TRUE) not numeric");
List<String> values = Arrays.asList("NaN", "Infinity", "-Infinity");
for (String value : values) {
@ -236,7 +237,7 @@ public class ScaledFloatFieldMapperTests extends MapperTestCase {
}
}
private void doTestIgnoreMalformed(String value, String exceptionMessageContains) throws Exception {
private void doTestIgnoreMalformed(Object value, String exceptionMessageContains) throws Exception {
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
ThrowingRunnable runnable = () -> mapper.parse(
new SourceToParse(