Search in sources :

Example 6 with ArrayDataType

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());
}
Also used : Field(com.yahoo.document.Field) ImmutableSDField(com.yahoo.searchdefinition.document.ImmutableSDField) StructuredDataType(com.yahoo.document.StructuredDataType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) StructuredDataType(com.yahoo.document.StructuredDataType) ArrayDataType(com.yahoo.document.ArrayDataType) LinkedList(java.util.LinkedList)

Example 7 with ArrayDataType

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());
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ArrayDataType(com.yahoo.document.ArrayDataType) Test(org.junit.Test)

Example 8 with ArrayDataType

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;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute) ArrayDataType(com.yahoo.document.ArrayDataType) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)

Example 9 with ArrayDataType

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());
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) ArrayDataType(com.yahoo.document.ArrayDataType) Test(org.junit.Test)

Example 10 with ArrayDataType

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.");
    }
}
Also used : DocumentType(com.yahoo.document.DocumentType) ArrayDataType(com.yahoo.document.ArrayDataType)

Aggregations

ArrayDataType (com.yahoo.document.ArrayDataType)20 DataType (com.yahoo.document.DataType)8 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)8 Field (com.yahoo.document.Field)7 MapDataType (com.yahoo.document.MapDataType)6 DocumentType (com.yahoo.document.DocumentType)5 StructDataType (com.yahoo.document.StructDataType)5 PositionDataType (com.yahoo.document.PositionDataType)4 TensorDataType (com.yahoo.document.TensorDataType)4 FieldValue (com.yahoo.document.datatypes.FieldValue)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)4 ReferenceDataType (com.yahoo.document.ReferenceDataType)3 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)3 SDField (com.yahoo.searchdefinition.document.SDField)3 Test (org.junit.Test)3 StructuredDataType (com.yahoo.document.StructuredDataType)2 Array (com.yahoo.document.datatypes.Array)2 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)2 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)2 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)2