summaryrefslogtreecommitdiffstats
path: root/config-model/src
diff options
context:
space:
mode:
authorArne Juul <arnej@vespa.ai>2023-12-14 08:26:50 +0000
committerArne Juul <arnej@vespa.ai>2023-12-14 08:26:50 +0000
commit990aab34103e545f17f3e05b02a6b2f7bcdca05c (patch)
treeebde890e7fd9f58a129cafc36a2fa75846fd55e7 /config-model/src
parent1ad5ec5fa814a92fdbf98db14121197023f434f0 (diff)
Reapply "add parsing of special strings for inf/nan cell values"
This reverts commit d976f82207c09b3215661e1d034ae9a42f28a63d.
Diffstat (limited to 'config-model/src')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidator.java16
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidatorTest.java9
2 files changed, 22 insertions, 3 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidator.java
index fcb99215565..9f1c072ad8b 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidator.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidator.java
@@ -7,6 +7,8 @@ import com.fasterxml.jackson.core.JsonToken;
import com.google.common.base.Joiner;
import com.yahoo.tensor.TensorType;
+import static com.yahoo.tensor.serialization.JsonFormat.decodeNumberString;
+
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
@@ -282,9 +284,19 @@ public class ConstantTensorJsonValidator {
}
private void validateNumeric(String where, JsonToken token) throws IOException {
- if (token != JsonToken.VALUE_NUMBER_FLOAT && token != JsonToken.VALUE_NUMBER_INT) {
- throw new InvalidConstantTensorException(parser, String.format("Inside '%s': cell value is not a number (%s)", where, token.toString()));
+ if (token == JsonToken.VALUE_NUMBER_FLOAT || token == JsonToken.VALUE_NUMBER_INT || token == JsonToken.VALUE_NULL) {
+ return; // ok
+ }
+ if (token == JsonToken.VALUE_STRING) {
+ String input = parser.getValueAsString();
+ try {
+ double d = decodeNumberString(input);
+ return;
+ } catch (NumberFormatException e) {
+ throw new InvalidConstantTensorException(parser, String.format("Inside '%s': %s", where, e.getMessage()));
+ }
}
+ throw new InvalidConstantTensorException(parser, String.format("Inside '%s': cell value is not a number (%s)", where, token.toString()));
}
private void assertCurrentTokenIs(JsonToken wantedToken) {
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidatorTest.java
index 4892c9acefa..9171aae170c 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidatorTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidatorTest.java
@@ -208,7 +208,7 @@ public class ConstantTensorJsonValidatorTest {
" ]",
"}"));
});
- assertTrue(exception.getMessage().contains("Inside 'value': cell value is not a number (VALUE_STRING)"));
+ assertTrue(exception.getMessage().contains("Inside 'value': Excepted a number, got string 'fruit'"));
}
@Test
@@ -295,6 +295,13 @@ public class ConstantTensorJsonValidatorTest {
}
@Test
+ void ensure_that_values_can_contain_special_values() {
+ validateTensorJson(
+ TensorType.fromSpec("tensor(x[5])"),
+ inputJsonToReader("['Infinity','+inf','NaN','-infinity','-nan']"));
+ }
+
+ @Test
void ensure_that_simple_object_for_map_works() {
validateTensorJson(
TensorType.fromSpec("tensor(x{})"),