summaryrefslogtreecommitdiffstats
path: root/indexinglanguage
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-02-06 13:35:44 +0100
committerJon Bratseth <bratseth@gmail.com>2022-02-06 13:35:44 +0100
commit69ce8870e81669dd0fa56b9ec6487949b7b60ffb (patch)
tree4faa3fb65497f922af533e2c76d222b0f7bbde1a /indexinglanguage
parent7b992b88818a931665441c3fb0f0c16824116567 (diff)
Cleanup
Diffstat (limited to 'indexinglanguage')
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java28
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeExpression.java1
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java3
3 files changed, 17 insertions, 15 deletions
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java
index c69ceda2210..5b04720dad4 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java
@@ -3,6 +3,7 @@ package com.yahoo.vespa.indexinglanguage.expressions;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
+import com.yahoo.document.ArrayDataType;
import com.yahoo.document.DataType;
import com.yahoo.document.DocumentType;
import com.yahoo.document.Field;
@@ -21,10 +22,7 @@ public class HashExpression extends Expression {
private final HashFunction hasher = Hashing.sipHash24();
- /** The destination the embedding will be written to on the form [schema name].[field name] */
- private String destination;
-
- /** The target type we are embedding into. */
+ /** The target type we are hashing into. */
private DataType targetType;
public HashExpression() {
@@ -33,11 +31,11 @@ public class HashExpression extends Expression {
@Override
public void setStatementOutput(DocumentType documentType, Field field) {
- if (field.getDataType() != DataType.INT && field.getDataType() != DataType.LONG)
+ if ( ! canStoreHash(field.getDataType()))
throw new IllegalArgumentException("Cannot use the hash function on an indexing statement for " +
field.getName() +
- ": The hash function can only be used when the target field is int or long, not " +
- field.getDataType());
+ ": The hash function can only be used when the target field " +
+ "is int or long, not " + field.getDataType());
targetType = field.getDataType();
}
@@ -67,25 +65,31 @@ public class HashExpression extends Expression {
throw new VerificationException(this, "No output field in this statement: " +
"Don't know what value to hash to.");
DataType outputFieldType = context.getInputType(this, outputField);
- if (outputFieldType != DataType.INT && outputFieldType != DataType.LONG)
+ if ( ! canStoreHash(outputFieldType))
throw new VerificationException(this, "The type of the output field " + outputField +
- " is not an int or long but " + outputField);
+ " is not int or long but " + outputFieldType);
targetType = outputFieldType;
context.setValueType(createdOutputType());
}
+ private boolean canStoreHash(DataType type) {
+ if (type.equals(DataType.INT)) return true;
+ if (type.equals(DataType.LONG)) return true;
+ return false;
+ }
+
@Override
public DataType createdOutputType() {
return targetType;
}
@Override
- public String toString() { return "embed"; }
+ public String toString() { return "hash"; }
@Override
- public int hashCode() { return 1; }
+ public int hashCode() { return 987; }
@Override
- public boolean equals(Object o) { return o instanceof EmbedExpression; }
+ public boolean equals(Object o) { return o instanceof HashExpression; }
}
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeExpression.java
index 5e7288b8ecc..ca2be7c3400 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeExpression.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeExpression.java
@@ -13,6 +13,7 @@ public final class HexEncodeExpression extends Expression {
public HexEncodeExpression() {
super(DataType.LONG);
}
+
@Override
protected void doExecute(ExecutionContext context) {
long input = ((LongFieldValue) context.getValue()).getLong();
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 b8254f133bc..778d95fcaef 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java
@@ -116,7 +116,6 @@ public class ScriptTestCase {
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());
}
@@ -139,7 +138,6 @@ public class ScriptTestCase {
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());
}
@@ -165,7 +163,6 @@ public class ScriptTestCase {
ExecutionContext context = new ExecutionContext(adapter);
context.setValue(new StringFieldValue("input text"));
expression.execute(context);
- assertNotNull(context);
assertTrue(adapter.values.containsKey("myTensor"));
assertEquals(Tensor.from(tensorType, "[7,3,0,0]"),
((TensorFieldValue)adapter.values.get("myTensor")).getTensor().get());