use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class IndexSchema method flattenField.
static List<Field> flattenField(Field field) {
DataType fieldType = field.getDataType();
if (fieldType.getPrimitiveType() != null) {
return Collections.singletonList(field);
}
if (fieldType instanceof ArrayDataType) {
boolean header = field.isHeader();
List<Field> ret = new LinkedList<>();
Field innerField = new Field(field.getName(), ((ArrayDataType) fieldType).getNestedType(), header);
for (Field flatField : flattenField(innerField)) {
ret.add(new Field(flatField.getName(), DataType.getArray(flatField.getDataType()), header));
}
return ret;
}
if (fieldType instanceof StructuredDataType) {
List<Field> ret = new LinkedList<>();
String fieldName = field.getName();
for (Field childField : ((StructuredDataType) fieldType).getFields()) {
for (Field flatField : flattenField(childField)) {
ret.add(new Field(fieldName + "." + flatField.getName(), flatField));
}
}
return ret;
}
throw new UnsupportedOperationException(fieldType.getName());
}
use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class ArraysWeightedSetsTestCase method testArrayWeightedSetsImporting.
@Test
public void testArrayWeightedSetsImporting() throws java.io.IOException, com.yahoo.searchdefinition.parser.ParseException {
Search search = SearchBuilder.buildFromFile("src/test/examples/arraysweightedsets.sd");
SDField tags = (SDField) search.getDocument().getField("tags");
assertTrue(tags.getDataType() instanceof ArrayDataType);
assertEquals(DataType.STRING, ((CollectionDataType) tags.getDataType()).getNestedType());
SDField ratings = (SDField) search.getDocument().getField("ratings");
assertTrue(ratings.getDataType() instanceof ArrayDataType);
assertEquals(DataType.INT, ((CollectionDataType) ratings.getDataType()).getNestedType());
SDField flags = (SDField) search.getDocument().getField("flags");
assertTrue(flags.getDataType() instanceof WeightedSetDataType);
assertEquals(DataType.STRING, ((CollectionDataType) flags.getDataType()).getNestedType());
SDField banners = (SDField) search.getDocument().getField("banners");
assertTrue(banners.getDataType() instanceof WeightedSetDataType);
assertEquals(DataType.INT, ((CollectionDataType) banners.getDataType()).getNestedType());
}
use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class CreatePositionZCurve method createZCurveField.
private SDField createZCurveField(SDField inputField, String fieldName, boolean validate) {
if (validate && search.getConcreteField(fieldName) != null || search.getAttribute(fieldName) != null) {
throw newProcessException(search, null, "Incompatible position attribute '" + fieldName + "' already created.");
}
boolean isArray = inputField.getDataType() instanceof ArrayDataType;
SDField field = new SDField(fieldName, isArray ? DataType.getArray(DataType.LONG) : DataType.LONG);
Attribute attribute = new Attribute(fieldName, Attribute.Type.LONG, isArray ? Attribute.CollectionType.ARRAY : Attribute.CollectionType.SINGLE);
attribute.setPosition(true);
attribute.setFastSearch(true);
field.addAttribute(attribute);
ScriptExpression script = inputField.getIndexingScript();
script = (ScriptExpression) new RemoveSummary(inputField.getName()).convert(script);
script = (ScriptExpression) new PerformZCurve(field, fieldName).convert(script);
field.setIndexingScript(script);
return field;
}
use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class ArraysTestCase method testArrayImporting.
@Test
public void testArrayImporting() throws IOException, ParseException {
Search search = UnprocessingSearchBuilder.buildUnprocessedFromFile("src/test/examples/arrays.sd");
SDField tags = (SDField) search.getDocument().getField("tags");
assertEquals(DataType.STRING, ((CollectionDataType) tags.getDataType()).getNestedType());
SDField ratings = (SDField) search.getDocument().getField("ratings");
assertTrue(ratings.getDataType() instanceof ArrayDataType);
assertEquals(DataType.INT, ((ArrayDataType) ratings.getDataType()).getNestedType());
}
use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class SplitterDocumentProcessor method validate.
static void validate(DocumentTypeManager manager, String documentTypeName, String arrayFieldName) {
DocumentType docType = manager.getDocumentType(documentTypeName);
if (docType == null) {
// the document type does not exist, return
throw new IllegalStateException("The document type " + documentTypeName + " is not deployed.");
}
if (docType.getField(arrayFieldName) == null) {
// the document type does not have the field, return
throw new IllegalStateException("The document type " + documentTypeName + " does not have a field named " + arrayFieldName + ".");
}
if (!(docType.getField(arrayFieldName).getDataType() instanceof ArrayDataType)) {
// the data type of the field is wrong, return
throw new IllegalStateException("The data type of the field named " + arrayFieldName + " in document type " + documentTypeName + " is not an array type");
}
ArrayDataType fieldDataType = (ArrayDataType) docType.getField(arrayFieldName).getDataType();
if (!(fieldDataType.getNestedType() instanceof DocumentType)) {
// the subtype of tye array data type of the field is wrong, return
throw new IllegalStateException("The data type of the field named " + arrayFieldName + " in document type " + documentTypeName + " is not an array of Document.");
}
}
Aggregations