Search in sources :

Example 1 with PredicateFieldValue

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

the class OptimizePredicateTestCase method requireThatOptimizerIsCalledWithCloneOfInput.

@Test
public void requireThatOptimizerIsCalledWithCloneOfInput() {
    final Predicate predicateA = Mockito.mock(Predicate.class);
    final Predicate predicateB = Mockito.mock(Predicate.class);
    final PredicateFieldValue input = new PredicateFieldValue(predicateA);
    ExecutionContext ctx = new ExecutionContext().setValue(input).setVariable("arity", new IntegerFieldValue(10));
    FieldValue output = new OptimizePredicateExpression((predicate, options) -> {
        assertNotSame(predicateA, predicate);
        return predicateB;
    }).execute(ctx);
    assertNotSame(output, input);
    assertTrue(output instanceof PredicateFieldValue);
    assertSame(predicateB, ((PredicateFieldValue) output).getPredicate());
}
Also used : Mockito(org.mockito.Mockito) ExpressionAssert.assertVerifyCtx(com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtx) Test(org.junit.Test) DataType(com.yahoo.document.DataType) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) ExpressionAssert.assertVerifyCtxThrows(com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtxThrows) FieldValue(com.yahoo.document.datatypes.FieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Assert(org.junit.Assert) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) ExpressionAssert.assertVerifyThrows(com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows) Predicate(com.yahoo.document.predicate.Predicate) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 2 with PredicateFieldValue

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

the class PredicateFieldValueSerializationTestCase method assertDeserialize.

private static void assertDeserialize(String fileName, Predicate expected) throws IOException {
    Document document = docFactory.createDocument();
    document.setFieldValue(PREDICATE_FIELD, new PredicateFieldValue(expected));
    SerializationTestUtils.assertSerializationMatchesCpp(PREDICATE_FILES, fileName, document, docFactory);
}
Also used : Document(com.yahoo.document.Document) SerializationTestUtils.serializeDocument(com.yahoo.document.serialization.SerializationTestUtils.serializeDocument) SerializationTestUtils.deserializeDocument(com.yahoo.document.serialization.SerializationTestUtils.deserializeDocument) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue)

Example 3 with PredicateFieldValue

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

the class VespaXmlFieldReaderTestCase method assertRead.

private static void assertRead(Predicate expected, String documentXml) throws Exception {
    DocumentTypeManager docManager = new DocumentTypeManager();
    DocumentType docType = new DocumentType("my_type");
    docType.addField("my_predicate", DataType.PREDICATE);
    docManager.register(docType);
    InputStream in = new ByteArrayInputStream(documentXml.getBytes(StandardCharsets.UTF_8));
    Document doc = new Document(docType, "doc:scheme:");
    new VespaXMLFieldReader(in, docManager).read(null, doc);
    FieldValue value = doc.getFieldValue("my_predicate");
    assertTrue(value instanceof PredicateFieldValue);
    assertEquals(expected, ((PredicateFieldValue) value).getPredicate());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FieldValue(com.yahoo.document.datatypes.FieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue)

Example 4 with PredicateFieldValue

use of com.yahoo.document.datatypes.PredicateFieldValue 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));
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Test(org.junit.Test)

Example 5 with PredicateFieldValue

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

the class PredicateFieldValueSerializationTestCase method requireThatPredicateFieldValuesAreDeserialized.

@Test
public void requireThatPredicateFieldValuesAreDeserialized() {
    Document prevDocument = docFactory.createDocument();
    PredicateFieldValue prevPredicate = new PredicateFieldValue(new Conjunction(new FeatureSet("foo", "bar"), new FeatureRange("baz", 6L, 9L)));
    prevDocument.setFieldValue(PREDICATE_FIELD, prevPredicate);
    byte[] buf = serializeDocument(prevDocument);
    Document nextDocument = deserializeDocument(buf, docFactory);
    assertEquals(prevDocument, nextDocument);
    assertEquals(prevPredicate, nextDocument.getFieldValue(PREDICATE_FIELD));
}
Also used : Conjunction(com.yahoo.document.predicate.Conjunction) FeatureRange(com.yahoo.document.predicate.FeatureRange) FeatureSet(com.yahoo.document.predicate.FeatureSet) Document(com.yahoo.document.Document) SerializationTestUtils.serializeDocument(com.yahoo.document.serialization.SerializationTestUtils.serializeDocument) SerializationTestUtils.deserializeDocument(com.yahoo.document.serialization.SerializationTestUtils.deserializeDocument) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Test(org.junit.Test)

Aggregations

PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)8 Test (org.junit.Test)5 Document (com.yahoo.document.Document)4 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)4 FieldValue (com.yahoo.document.datatypes.FieldValue)3 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)3 DataType (com.yahoo.document.DataType)2 DocumentType (com.yahoo.document.DocumentType)2 Field (com.yahoo.document.Field)2 Predicate (com.yahoo.document.predicate.Predicate)2 SerializationTestUtils.deserializeDocument (com.yahoo.document.serialization.SerializationTestUtils.deserializeDocument)2 SerializationTestUtils.serializeDocument (com.yahoo.document.serialization.SerializationTestUtils.serializeDocument)2 ExpressionAssert.assertVerifyCtx (com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtx)2 ExpressionAssert.assertVerifyCtxThrows (com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtxThrows)2 ExpressionAssert.assertVerifyThrows (com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows)2 Assert (org.junit.Assert)2 Mockito (org.mockito.Mockito)2 Conjunction (com.yahoo.document.predicate.Conjunction)1 FeatureRange (com.yahoo.document.predicate.FeatureRange)1 FeatureSet (com.yahoo.document.predicate.FeatureSet)1