Search in sources :

Example 6 with WeightedSetDataType

use of com.yahoo.document.WeightedSetDataType in project vespa by vespa-engine.

the class DocumentGenTest method testComplex.

@Test
public void testComplex() throws MojoFailureException {
    DocumentGenMojo mojo = new DocumentGenMojo();
    mojo.execute(new File("etc/complex/"), new File("target/generated-test-sources/vespa-documentgen-plugin/"), "com.yahoo.vespa.document");
    Map<String, Search> searches = mojo.getSearches();
    assertEquals(searches.get("video").getDocument("video").getField("weight").getDataType(), DataType.FLOAT);
    assertTrue(searches.get("book").getDocument("book").getField("mystruct").getDataType() instanceof StructDataType);
    assertTrue(searches.get("book").getDocument("book").getField("mywsfloat").getDataType() instanceof WeightedSetDataType);
    assertTrue(((WeightedSetDataType) (searches.get("book").getDocument("book").getField("mywsfloat").getDataType())).getNestedType() == DataType.FLOAT);
}
Also used : StructDataType(com.yahoo.document.StructDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) Search(com.yahoo.searchdefinition.Search) File(java.io.File) Test(org.junit.Test)

Example 7 with WeightedSetDataType

use of com.yahoo.document.WeightedSetDataType 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);
    }
}
Also used : Field(com.yahoo.document.Field) TensorDataType(com.yahoo.document.TensorDataType) StructDataType(com.yahoo.document.StructDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) JsonFactory(com.fasterxml.jackson.core.JsonFactory) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType) DataType(com.yahoo.document.DataType) MapDataType(com.yahoo.document.MapDataType) TensorDataType(com.yahoo.document.TensorDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) PositionDataType(com.yahoo.document.PositionDataType) MapDataType(com.yahoo.document.MapDataType) ArrayDataType(com.yahoo.document.ArrayDataType) TensorType(com.yahoo.tensor.TensorType) Before(org.junit.Before)

Example 8 with WeightedSetDataType

use of com.yahoo.document.WeightedSetDataType in project vespa by vespa-engine.

the class JsonWriterTestCase method registerSetDocumentType.

private void registerSetDocumentType() {
    DocumentType x = new DocumentType("testset");
    DataType d = new WeightedSetDataType(DataType.STRING, true, true);
    x.addField(new Field("actualset", d));
    types.registerDocumentType(x);
}
Also used : Field(com.yahoo.document.Field) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) DocumentType(com.yahoo.document.DocumentType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) MapDataType(com.yahoo.document.MapDataType) PositionDataType(com.yahoo.document.PositionDataType) TensorDataType(com.yahoo.document.TensorDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType)

Example 9 with WeightedSetDataType

use of com.yahoo.document.WeightedSetDataType in project vespa by vespa-engine.

the class MapValueUpdate method checkCompatibility.

@Override
protected void checkCompatibility(DataType fieldType) {
    if (fieldType instanceof ArrayDataType) {
        if (!(value instanceof IntegerFieldValue)) {
            throw new IllegalArgumentException("Expected integer, got " + value.getClass().getName() + ".");
        }
        update.checkCompatibility(((ArrayDataType) fieldType).getNestedType());
    } else if (fieldType instanceof WeightedSetDataType) {
        ((WeightedSetDataType) fieldType).getNestedType().createFieldValue().assign(value);
        update.checkCompatibility(DataType.INT);
    } else if (fieldType instanceof StructuredDataType) {
        if (!(value instanceof StringFieldValue)) {
            throw new IllegalArgumentException("Expected string, got " + value.getClass().getName() + ".");
        }
        Field field = ((StructuredDataType) fieldType).getField(((StringFieldValue) value).getString());
        if (field == null) {
            throw new IllegalArgumentException("Field '" + value + "' not found.");
        }
        update.checkCompatibility(field.getDataType());
    } else {
        throw new UnsupportedOperationException("Field type " + fieldType.getName() + " not supported.");
    }
}
Also used : Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StructuredDataType(com.yahoo.document.StructuredDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 10 with WeightedSetDataType

use of com.yahoo.document.WeightedSetDataType in project vespa by vespa-engine.

the class VespaDocumentDeserializer42 method read.

public <T extends FieldValue> void read(FieldBase field, WeightedSet<T> ws) {
    WeightedSetDataType type = ws.getDataType();
    // Have no need for type
    getInt(null);
    int numElements = getInt(null);
    if (numElements < 0) {
        throw new DeserializationException("Bad number of weighted set elements, " + numElements);
    }
    // Avoid resizing
    ws.clearAndReserve(numElements * 2);
    for (int i = 0; i < numElements; i++) {
        int size = getInt(null);
        FieldValue value = type.getNestedType().createFieldValue();
        value.deserialize(null, this);
        IntegerFieldValue weight = new IntegerFieldValue(getInt(null));
        ws.putUnChecked((T) value, weight);
    }
}
Also used : WeightedSetDataType(com.yahoo.document.WeightedSetDataType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) ReferenceFieldValue(com.yahoo.document.datatypes.ReferenceFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue)

Aggregations

WeightedSetDataType (com.yahoo.document.WeightedSetDataType)12 ArrayDataType (com.yahoo.document.ArrayDataType)5 FieldValue (com.yahoo.document.datatypes.FieldValue)5 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)5 StructDataType (com.yahoo.document.StructDataType)4 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)4 DataType (com.yahoo.document.DataType)3 Field (com.yahoo.document.Field)3 WeightedSet (com.yahoo.document.datatypes.WeightedSet)3 Test (org.junit.Test)3 DocumentType (com.yahoo.document.DocumentType)2 MapDataType (com.yahoo.document.MapDataType)2 PositionDataType (com.yahoo.document.PositionDataType)2 TensorDataType (com.yahoo.document.TensorDataType)2 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)2 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)2 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)2 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)2 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)2 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)2