diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-02-04 14:54:44 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-02-04 14:54:44 +0100 |
commit | 7b992b88818a931665441c3fb0f0c16824116567 (patch) | |
tree | 66d6ff52ed406bad1b0017deac104e96189a2c52 /indexinglanguage/src/test/java | |
parent | e67031fd521c68ca66fdf897f8c6b0fd5a395f45 (diff) |
Add hash function
Diffstat (limited to 'indexinglanguage/src/test/java')
-rw-r--r-- | indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java index f9a6f2225b3..b8254f133bc 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java @@ -9,7 +9,6 @@ import com.yahoo.document.TensorDataType; import com.yahoo.document.datatypes.BoolFieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.datatypes.TensorFieldValue; -import com.yahoo.language.Language; import com.yahoo.language.process.Embedder; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.tensor.Tensor; @@ -100,6 +99,52 @@ public class ScriptTestCase { } @Test + public void testIntHash() throws ParseException { + var expression = Expression.fromString("input myText | hash | attribute 'myInt'"); + + SimpleTestAdapter adapter = new SimpleTestAdapter(); + adapter.createField(new Field("myText", DataType.STRING)); + var intField = new Field("myInt", DataType.INT); + adapter.createField(intField); + adapter.setValue("myText", new StringFieldValue("input text")); + expression.setStatementOutput(new DocumentType("myDocument"), intField); + + // Necessary to resolve output type + VerificationContext verificationContext = new VerificationContext(adapter); + assertEquals(DataType.INT, expression.verify(verificationContext)); + + ExecutionContext context = new ExecutionContext(adapter); + context.setValue(new StringFieldValue("input text")); + expression.execute(context); + assertNotNull(context); + assertTrue(adapter.values.containsKey("myInt")); + assertEquals(-1425622096, adapter.values.get("myInt").getWrappedValue()); + } + + @Test + public void testLongHash() throws ParseException { + var expression = Expression.fromString("input myText | hash | attribute 'myLong'"); + + SimpleTestAdapter adapter = new SimpleTestAdapter(); + adapter.createField(new Field("myText", DataType.STRING)); + var intField = new Field("myLong", DataType.LONG); + adapter.createField(intField); + adapter.setValue("myText", new StringFieldValue("input text")); + expression.setStatementOutput(new DocumentType("myDocument"), intField); + + // Necessary to resolve output type + VerificationContext verificationContext = new VerificationContext(adapter); + assertEquals(DataType.LONG, expression.verify(verificationContext)); + + ExecutionContext context = new ExecutionContext(adapter); + context.setValue(new StringFieldValue("input text")); + expression.execute(context); + assertNotNull(context); + assertTrue(adapter.values.containsKey("myLong")); + assertEquals(7678158186624760752L, adapter.values.get("myLong").getWrappedValue()); + } + + @Test public void testEmbed() throws ParseException { TensorType tensorType = TensorType.fromSpec("tensor(d[4])"); var expression = Expression.fromString("input myText | embed | attribute 'myTensor'", |