use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class IndexSchemaTestCase method requireThatStructWithArrayOfArrayFieldIsFlattened.
@Test
public void requireThatStructWithArrayOfArrayFieldIsFlattened() {
StructDataType type = new StructDataType("my_struct");
type.addField(new Field("my_byte", DataType.getArray(DataType.getArray(DataType.BYTE))));
type.addField(new Field("my_double", DataType.getArray(DataType.getArray(DataType.DOUBLE))));
type.addField(new Field("my_float", DataType.getArray(DataType.getArray(DataType.FLOAT))));
type.addField(new Field("my_int", DataType.getArray(DataType.getArray(DataType.INT))));
type.addField(new Field("my_long", DataType.getArray(DataType.getArray(DataType.LONG))));
type.addField(new Field("my_raw", DataType.getArray(DataType.getArray(DataType.RAW))));
type.addField(new Field("my_string", DataType.getArray(DataType.getArray(DataType.STRING))));
type.addField(new Field("my_uri", DataType.getArray(DataType.getArray(DataType.URI))));
assertFlat(new Field("foo", type), new Field("foo.my_byte", DataType.getArray(DataType.getArray(DataType.BYTE))), new Field("foo.my_double", DataType.getArray(DataType.getArray(DataType.DOUBLE))), new Field("foo.my_float", DataType.getArray(DataType.getArray(DataType.FLOAT))), new Field("foo.my_int", DataType.getArray(DataType.getArray(DataType.INT))), new Field("foo.my_long", DataType.getArray(DataType.getArray(DataType.LONG))), new Field("foo.my_raw", DataType.getArray(DataType.getArray(DataType.RAW))), new Field("foo.my_string", DataType.getArray(DataType.getArray(DataType.STRING))), new Field("foo.my_uri", DataType.getArray(DataType.getArray(DataType.URI))));
}
use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class DocumentTypeChangeValidatorTest method createDocumentTypeWithReferenceField.
private static NewDocumentType createDocumentTypeWithReferenceField(String nameReferencedDocumentType) {
StructDataType headerfields = new StructDataType("headerfields");
headerfields.addField(new Field("ref", new ReferenceDataType(new DocumentType(nameReferencedDocumentType), 0)));
return new NewDocumentType(new NewDocumentType.Name("mydoc"), headerfields, new StructDataType("bodyfields"), new FieldSets(), Collections.emptySet());
}
use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class ForEachTestCase method requireThatStructFieldCompatibilityIsVerified.
@Test
public void requireThatStructFieldCompatibilityIsVerified() {
StructDataType type = new StructDataType("my_struct");
type.addField(new Field("foo", DataType.INT));
assertVerify(type, new ForEachExpression(new SimpleExpression()), type);
assertVerifyThrows(type, new ForEachExpression(SimpleExpression.newConversion(DataType.STRING, DataType.INT)), "Expected string input, got int.");
assertVerifyThrows(type, new ForEachExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING)), "Expected int output, got string.");
}
use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class SchemaMappingAndAccessesTest method getDoc.
private Document getDoc() {
DocumentType type = new DocumentType("album");
AnnotationType personType = new AnnotationType("person");
Annotation person = new Annotation(personType);
type.addField("title", DataType.STRING);
type.addField("artist", DataType.STRING);
type.addField("guitarist", DataType.STRING);
type.addField("year", DataType.INT);
type.addField("labels", DataType.getArray(DataType.STRING));
Document doc = new Document(type, new DocumentId("doc:map:test:1"));
doc.setFieldValue("title", new StringFieldValue("Black Rock"));
StringFieldValue joe = new StringFieldValue("Joe Bonamassa");
joe.setSpanTree(new SpanTree("mytree").annotate(person));
doc.setFieldValue("artist", joe);
doc.setFieldValue("year", new IntegerFieldValue(2010));
Array<StringFieldValue> labels = new Array<>(type.getField("labels").getDataType());
labels.add(new StringFieldValue("audun"));
labels.add(new StringFieldValue("tylden"));
doc.setFieldValue("labels", labels);
StructDataType personStructType = new StructDataType("artist");
personStructType.addField(new com.yahoo.document.Field("firstname", DataType.STRING));
personStructType.addField(new com.yahoo.document.Field("lastname", DataType.STRING));
type.addField("listeners", DataType.getArray(personStructType));
Array<Struct> listeners = new Array<>(type.getField("listeners").getDataType());
Struct listenerOne = new Struct(personStructType);
listenerOne.setFieldValue("firstname", new StringFieldValue("per"));
listenerOne.setFieldValue("lastname", new StringFieldValue("olsen"));
Struct listenerTwo = new Struct(personStructType);
listenerTwo.setFieldValue("firstname", new StringFieldValue("anders"));
listenerTwo.setFieldValue("lastname", new StringFieldValue("and"));
listeners.add(listenerOne);
listeners.add(listenerTwo);
doc.setFieldValue("listeners", listeners);
return doc;
}
use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class SchemaMappingAndAccessesTest method testMappedDocStruct.
public void testMappedDocStruct() {
StructDataType materialsStructType = new StructDataType("materialstype");
materialsStructType.addField(new com.yahoo.document.Field("ceiling", DataType.STRING));
materialsStructType.addField(new com.yahoo.document.Field("walls", DataType.STRING));
DocumentType docType = new DocumentType("album");
docType.addField("title", DataType.STRING);
docType.addField("artist", DataType.STRING);
StructDataType storeStructType = new StructDataType("storetype");
storeStructType.addField(new com.yahoo.document.Field("name", DataType.STRING));
storeStructType.addField(new com.yahoo.document.Field("city", DataType.STRING));
storeStructType.addField(new com.yahoo.document.Field("materials", materialsStructType));
docType.addField("store", storeStructType);
Document doc = new Document(docType, new DocumentId("doc:map:test:1"));
doc.setFieldValue("title", new StringFieldValue("Black Rock"));
doc.setFieldValue("artist", new StringFieldValue("Joe Bonamassa"));
Struct material = new Struct(materialsStructType);
material.setFieldValue("ceiling", new StringFieldValue("wood"));
material.setFieldValue("walls", new StringFieldValue("brick"));
Struct store = new Struct(storeStructType);
store.setFieldValue("name", new StringFieldValue("Platekompaniet"));
store.setFieldValue("city", new StringFieldValue("Trondheim"));
store.setFieldValue(storeStructType.getField("materials"), material);
doc.setFieldValue(docType.getField("store"), store);
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("t", "title");
fieldMap.put("c", "store.city");
fieldMap.put("w", "store.materials.walls");
ProxyDocument mapped = new ProxyDocument(new TestDocumentProcessor1(), doc, fieldMap);
assertEquals(new StringFieldValue("Trondheim"), mapped.getFieldValue("c"));
assertEquals(new StringFieldValue("Black Rock"), mapped.getFieldValue("t"));
assertEquals(new StringFieldValue("brick"), mapped.getFieldValue("w"));
assertEquals(new StringFieldValue("brick"), material.getFieldValue("walls"));
mapped.setFieldValue("c", new StringFieldValue("Steinkjer"));
mapped.setFieldValue("w", new StringFieldValue("plaster"));
assertEquals(new StringFieldValue("plaster"), mapped.getFieldValue("w"));
assertEquals(new StringFieldValue("plaster"), material.getFieldValue("walls"));
assertEquals(new StringFieldValue("Steinkjer"), store.getFieldValue("city"));
assertEquals(new StringFieldValue("Steinkjer"), mapped.getFieldValue("c"));
assertEquals(new StringFieldValue("Steinkjer"), mapped.getFieldValue("c"));
mapped.setFieldValue("c", new StringFieldValue("Levanger"));
assertEquals(new StringFieldValue("Levanger"), store.getFieldValue("city"));
assertEquals(new StringFieldValue("Levanger"), mapped.getFieldValue("c"));
mapped.setFieldValue("c", mapped.getFieldValue("c") + "Kommune");
assertEquals(new StringFieldValue("LevangerKommune"), mapped.getFieldValue("c"));
// mapped.set(mapped.getField("c"), mapped.get("c")+"Styre");
// assertEquals(new StringFieldValue("LevangerKommuneStyre"), mapped.getFieldValue("c"));
}
Aggregations