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:
parent
ca9151fa24
commit
1eda2bbe3a
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
package org.opensearch.index.mapper;
|
package org.opensearch.index.mapper;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParseException;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.index.DocValues;
|
import org.apache.lucene.index.DocValues;
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
|
@ -392,7 +393,7 @@ public class ScaledFloatFieldMapper extends ParametrizedFieldMapper {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
numericValue = parse(parser, coerce.value());
|
numericValue = parse(parser, coerce.value());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException | JsonParseException e) {
|
||||||
if (ignoreMalformed.value()) {
|
if (ignoreMalformed.value()) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -229,6 +229,7 @@ public class ScaledFloatFieldMapperTests extends MapperTestCase {
|
||||||
|
|
||||||
public void testIgnoreMalformed() throws Exception {
|
public void testIgnoreMalformed() throws Exception {
|
||||||
doTestIgnoreMalformed("a", "For input string: \"a\"");
|
doTestIgnoreMalformed("a", "For input string: \"a\"");
|
||||||
|
doTestIgnoreMalformed(true, "Current token (VALUE_TRUE) not numeric");
|
||||||
|
|
||||||
List<String> values = Arrays.asList("NaN", "Infinity", "-Infinity");
|
List<String> values = Arrays.asList("NaN", "Infinity", "-Infinity");
|
||||||
for (String value : values) {
|
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));
|
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
|
||||||
ThrowingRunnable runnable = () -> mapper.parse(
|
ThrowingRunnable runnable = () -> mapper.parse(
|
||||||
new SourceToParse(
|
new SourceToParse(
|
||||||
|
|
Loading…
Reference in New Issue