use of com.yahoo.document.Field in project vespa by vespa-engine.
the class JsonRendererTestCase method testFieldValueInHit.
@Test
public final void testFieldValueInHit() throws IOException, InterruptedException, ExecutionException, JSONException {
String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" + " {\n" + " \"fields\": {\n" + " \"fromDocumentApi\":{\"integerField\":123, \"stringField\":\"abc\"}" + " },\n" + " \"id\": \"fieldValueTest\",\n" + " \"relevance\": 1.0\n" + " }\n" + " ],\n" + " \"fields\": {\n" + " \"totalCount\": 1\n" + " },\n" + " \"id\": \"toplevel\",\n" + " \"relevance\": 1.0\n" + " }\n" + "}\n";
Result r = newEmptyResult();
Hit h = new Hit("fieldValueTest");
StructDataType structType = new StructDataType("jsonRenderer");
structType.addField(new Field("stringField", DataType.STRING));
structType.addField(new Field("integerField", DataType.INT));
Struct struct = structType.createFieldValue();
struct.setFieldValue("stringField", "abc");
struct.setFieldValue("integerField", 123);
h.setField("fromDocumentApi", struct);
r.hits().add(h);
r.setTotalHitCount(1L);
String summary = render(r);
assertEqualJson(expected, summary);
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class DocumentScriptTestCase method requireThatLinguisticsSpanTreeIsRemovedFromStructStringFields.
@Test
public void requireThatLinguisticsSpanTreeIsRemovedFromStructStringFields() {
StructDataType structType = new StructDataType("myStruct");
structType.addField(new Field("myString", DataType.STRING));
Struct in = new Struct(structType);
in.setFieldValue("myString", newString(SpanTrees.LINGUISTICS, "mySpanTree"));
Struct out = (Struct) processDocument(in);
assertSpanTrees(out.getFieldValue("myString"), "mySpanTree");
StringFieldValue str = (StringFieldValue) ((MapValueUpdate) processFieldUpdate(in)).getUpdate().getValue();
assertSpanTrees(str, "mySpanTree");
str = (StringFieldValue) ((MapValueUpdate) processFieldUpdate(in)).getUpdate().getValue();
assertSpanTrees(str, "mySpanTree");
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class JsonReaderTestCase method setUp.
@Before
public void setUp() throws Exception {
parserFactory = new JsonFactory();
types = new DocumentTypeManager();
{
DocumentType x = new DocumentType("smoke");
x.addField(new Field("something", DataType.STRING));
x.addField(new Field("nalle", DataType.STRING));
x.addField(new Field("int1", DataType.INT));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("mirrors");
StructDataType woo = new StructDataType("woo");
woo.addField(new Field("sandra", DataType.STRING));
woo.addField(new Field("cloud", DataType.STRING));
x.addField(new Field("skuggsjaa", woo));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testarray");
DataType d = new ArrayDataType(DataType.STRING);
x.addField(new Field("actualarray", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testset");
DataType d = new WeightedSetDataType(DataType.STRING, true, true);
x.addField(new Field("actualset", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testmap");
DataType d = new MapDataType(DataType.STRING, DataType.STRING);
x.addField(new Field("actualmap", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testraw");
DataType d = DataType.RAW;
x.addField(new Field("actualraw", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testMapStringToArrayOfInt");
DataType value = new ArrayDataType(DataType.INT);
DataType d = new MapDataType(DataType.STRING, value);
x.addField(new Field("actualMapStringToArrayOfInt", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testsinglepos");
DataType d = PositionDataType.INSTANCE;
x.addField(new Field("singlepos", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testtensor");
x.addField(new Field("mappedtensorfield", new TensorDataType(new TensorType.Builder().mapped("x").mapped("y").build())));
x.addField(new Field("indexedtensorfield", new TensorDataType(new TensorType.Builder().indexed("x").indexed("y").build())));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testpredicate");
x.addField(new Field("boolean", DataType.PREDICATE));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testint");
x.addField(new Field("integerfield", DataType.INT));
types.registerDocumentType(x);
}
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method predicate_field_values_are_serialized.
@Test
public void predicate_field_values_are_serialized() {
DocumentType docType = new DocumentType("my_type");
Field field = new Field("my_predicate", DataType.PREDICATE);
docType.addField(field);
Document doc = new Document(docType, "doc:scheme:");
PredicateFieldValue predicate = Mockito.mock(PredicateFieldValue.class);
doc.setFieldValue("my_predicate", predicate);
DocumentSerializerFactory.create42(new GrowableByteBuffer()).write(doc);
Mockito.verify(predicate, Mockito.times(1)).serialize(Mockito.same(field), Mockito.any(FieldWriter.class));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class VespaXmlUpdateReaderTestCase method requireThatWSetItemDeserializeExceptionIncludesFieldName.
@Test
public void requireThatWSetItemDeserializeExceptionIncludesFieldName() throws Exception {
Field field = new Field("my_field", DataType.getWeightedSet(DataType.BYTE));
assertThrows(field, "<assign field='my_field'><item>-129</item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 83)");
assertThrows(field, "<assign fieldpath='my_field'><item>-129</item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 87)");
assertThrows(field, "<add field='my_field'><item>-129</item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 80)");
assertThrows(field, "<add fieldpath='my_field'><item>-129</item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 84)");
assertThrows(field, "<remove field='my_field'><item>-129</item></remove>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 83)");
try {
readUpdate(field, "<remove fieldpath='my_field{-129}' />");
fail();
} catch (NumberFormatException e) {
}
}
Aggregations