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());
}
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);
}
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());
}
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));
}
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));
}
Aggregations