Search in sources :

Example 11 with FieldValue

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

the class NormalizeTestCase method requireThatInputIsNormalized.

@Test
public void requireThatInputIsNormalized() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setLanguage(Language.ENGLISH);
    ctx.setValue(new StringFieldValue("b\u00e9yonc\u00e8"));
    new NormalizeExpression(new SimpleLinguistics()).execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof StringFieldValue);
    assertEquals("beyonce", ((StringFieldValue) val).getString());
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Example 12 with FieldValue

use of com.yahoo.document.datatypes.FieldValue 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 13 with FieldValue

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

the class RandomTestCase method requireThatRandomValueIsSet.

@Test
public void requireThatRandomValueIsSet() {
    for (int i = 0; i < 666; ++i) {
        ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
        new RandomExpression(69).execute(ctx);
        FieldValue val = ctx.getValue();
        assertTrue(val instanceof IntegerFieldValue);
        assertTrue(((IntegerFieldValue) val).getInteger() < 69);
    }
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 14 with FieldValue

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

the class RandomTestCase method requireThatInputValueIsParsedAsMaxIfNoneIsConfigured.

@Test
public void requireThatInputValueIsParsedAsMaxIfNoneIsConfigured() {
    for (int i = 0; i < 666; ++i) {
        ExecutionContext ctx = new ExecutionContext().setValue(new IntegerFieldValue(69));
        new RandomExpression().execute(ctx);
        FieldValue val = ctx.getValue();
        assertTrue(val instanceof IntegerFieldValue);
        assertTrue(((IntegerFieldValue) val).getInteger() < 69);
    }
}
Also used : IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 15 with FieldValue

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

the class SplitTestCase method requireThatValueIsSplit.

@Test
public void requireThatValueIsSplit() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("6;9"));
    new SplitExpression(";").execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val.getDataType().equals(DataType.getArray(DataType.STRING)));
    assertTrue(val instanceof Array);
    Array arr = (Array) val;
    assertEquals(new StringFieldValue("6"), arr.get(0));
    assertEquals(new StringFieldValue("9"), arr.get(1));
}
Also used : Array(com.yahoo.document.datatypes.Array) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Aggregations

FieldValue (com.yahoo.document.datatypes.FieldValue)106 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)69 Test (org.junit.Test)52 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)45 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)30 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)26 Array (com.yahoo.document.datatypes.Array)20 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)20 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)18 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)14 Struct (com.yahoo.document.datatypes.Struct)13 DataType (com.yahoo.document.DataType)12 Document (com.yahoo.document.Document)12 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)12 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)12 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)11 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)11 ByteArrayInputStream (java.io.ByteArrayInputStream)11 InputStream (java.io.InputStream)11 DocumentPut (com.yahoo.document.DocumentPut)10