Search in sources :

Example 6 with PredicateFieldValue

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

the class XmlDocumentWriterTestCase method requireThatPredicateFieldValuesAreSerializedAsString.

@Test
public void requireThatPredicateFieldValuesAreSerializedAsString() {
    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);
    new XmlDocumentWriter().write(doc);
    Mockito.verify(predicate, Mockito.times(1)).printXml(Mockito.any(XmlStream.class));
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Test(org.junit.Test)

Example 7 with PredicateFieldValue

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

the class OptimizePredicateTestCase method requireThatPredicateOptionsAreSet.

@Test
public void requireThatPredicateOptionsAreSet() {
    final Predicate predicate = Mockito.mock(Predicate.class);
    final PredicateFieldValue input = new PredicateFieldValue(predicate);
    ExecutionContext ctx = new ExecutionContext().setValue(input).setVariable("arity", new IntegerFieldValue(10));
    new OptimizePredicateExpression((predicate1, options) -> {
        assertEquals(10, options.getArity());
        assertEquals(0x8000000000000000L, options.getLowerBound());
        assertEquals(0x7fffffffffffffffL, options.getUpperBound());
        return predicate1;
    }).execute(ctx);
    ctx.setVariable("upper_bound", new LongFieldValue(1000));
    ctx.setVariable("lower_bound", new LongFieldValue(0));
    new OptimizePredicateExpression((value, options) -> {
        assertEquals(10, options.getArity());
        assertEquals(0, options.getLowerBound());
        assertEquals(1000, options.getUpperBound());
        return value;
    }).execute(ctx);
}
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) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 8 with PredicateFieldValue

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

the class OptimizePredicateExpression method doExecute.

@Override
protected void doExecute(ExecutionContext ctx) {
    PredicateFieldValue predicate = ((PredicateFieldValue) ctx.getValue()).clone();
    IntegerFieldValue arity = (IntegerFieldValue) ctx.getVariable("arity");
    LongFieldValue lower_bound = (LongFieldValue) ctx.getVariable("lower_bound");
    LongFieldValue upper_bound = (LongFieldValue) ctx.getVariable("upper_bound");
    Long lower = lower_bound != null ? lower_bound.getLong() : null;
    Long upper = upper_bound != null ? upper_bound.getLong() : null;
    PredicateOptions options = new PredicateOptions(arity.getInteger(), lower, upper);
    predicate.setPredicate(optimizer.process(predicate.getPredicate(), options));
    ctx.setValue(predicate);
}
Also used : PredicateOptions(com.yahoo.search.predicate.optimization.PredicateOptions) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue)

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