use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ScriptTestCase method requireThatInputValueIsAvailableToAllStatements.
@Test
public void requireThatInputValueIsAvailableToAllStatements() {
SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out-1", DataType.INT), new Field("out-2", DataType.INT));
newStatement(new SetValueExpression(new IntegerFieldValue(69)), newScript(newStatement(new AttributeExpression("out-1"), new AttributeExpression("out-2")))).execute(adapter);
assertEquals(new IntegerFieldValue(69), adapter.getInputValue("out-1"));
assertEquals(new IntegerFieldValue(69), adapter.getInputValue("out-2"));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ScriptTestCase method requireThatVariablesAreAvailableOutsideScript.
@Test
public void requireThatVariablesAreAvailableOutsideScript() {
SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
newStatement(newScript(newStatement(new SetValueExpression(new IntegerFieldValue(69)), new SetVarExpression("tmp"))), new GetVarExpression("tmp"), new AttributeExpression("out")).execute(adapter);
assertEquals(new IntegerFieldValue(69), adapter.getInputValue("out"));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class FieldSetRepo method parseFieldCollection.
FieldSet parseFieldCollection(DocumentTypeManager docMan, String docType, String fieldNames) {
DocumentType type = docMan.getDocumentType(docType);
if (type == null) {
throw new IllegalArgumentException("Unknown document type " + docType);
}
StringTokenizer tokenizer = new StringTokenizer(fieldNames, ",");
FieldCollection collection = new FieldCollection(type);
for (; tokenizer.hasMoreTokens(); ) {
String token = tokenizer.nextToken();
Field f = type.getField(token);
if (f == null) {
throw new IllegalArgumentException("No such field " + token);
}
collection.add(f);
}
return collection;
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class FieldValueConverterTestCase method requireThatStructElementsAreConverted.
@Test
public void requireThatStructElementsAreConverted() {
StructDataType type = new StructDataType("foo");
type.addField(new Field("bar", DataType.STRING));
type.addField(new Field("baz", DataType.STRING));
Struct before = type.createFieldValue();
before.setFieldValue("bar", new StringFieldValue("6"));
before.setFieldValue("baz", new StringFieldValue("9"));
FieldValue after = new StringMarker().convert(before);
assertTrue(after instanceof Struct);
assertEquals(new StringFieldValue("6'"), ((Struct) after).getFieldValue("bar"));
assertEquals(new StringFieldValue("9'"), ((Struct) after).getFieldValue("baz"));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class FieldValueConverterTestCase method requireThatStructArrayElementsAreConverted.
@Test
public void requireThatStructArrayElementsAreConverted() {
StructDataType type = new StructDataType("foo");
type.addField(new Field("bar", DataType.STRING));
type.addField(new Field("baz", DataType.STRING));
Array<Struct> before = new Array<>(DataType.getArray(type));
Struct elem = type.createFieldValue();
elem.setFieldValue("bar", new StringFieldValue("6"));
elem.setFieldValue("baz", new StringFieldValue("9"));
before.add(elem);
elem = type.createFieldValue();
elem.setFieldValue("bar", new StringFieldValue("9"));
elem.setFieldValue("baz", new StringFieldValue("6"));
before.add(elem);
FieldValue after = new StringMarker().convert(before);
assertTrue(after instanceof Array);
FieldValue val = ((Array) after).getFieldValue(0);
assertTrue(val instanceof Struct);
assertEquals(new StringFieldValue("6'"), ((Struct) val).getFieldValue("bar"));
assertEquals(new StringFieldValue("9'"), ((Struct) val).getFieldValue("baz"));
val = ((Array) after).getFieldValue(1);
assertTrue(val instanceof Struct);
assertEquals(new StringFieldValue("9'"), ((Struct) val).getFieldValue("bar"));
assertEquals(new StringFieldValue("6'"), ((Struct) val).getFieldValue("baz"));
}
Aggregations