Search in sources :

Example 6 with Expression

use of com.yahoo.vespa.indexinglanguage.expressions.Expression in project vespa by vespa-engine.

the class DocumentTestCase method requireThatConcatenationWorks.

@Test
public void requireThatConcatenationWorks() throws ParseException {
    DocumentType docType = new DocumentType("my_input");
    docType.addField(new Field("arr_a", DataType.getArray(DataType.STRING)));
    docType.addField(new Field("arr_b", DataType.getArray(DataType.STRING)));
    docType.addField(new Field("out", DataType.getArray(DataType.STRING)));
    Expression exp = Expression.fromString("input arr_a . input arr_b | index out");
    {
        Document doc = new Document(docType, "doc:scheme:");
        assertNotNull(doc = Expression.execute(exp, doc));
        FieldValue val = doc.getFieldValue("out");
        assertNotNull(val);
        assertEquals(DataType.getArray(DataType.STRING), val.getDataType());
        assertTrue(val instanceof Array);
        Array arr = (Array) val;
        assertEquals(0, arr.size());
    }
    {
        Document doc = new Document(docType, "doc:scheme:");
        Array<StringFieldValue> arr = new Array<>(DataType.getArray(DataType.STRING));
        arr.add(new StringFieldValue("a1"));
        doc.setFieldValue("arr_a", arr);
        assertNotNull(doc = Expression.execute(exp, doc));
        FieldValue val = doc.getFieldValue("out");
        assertNotNull(val);
        assertEquals(DataType.getArray(DataType.STRING), val.getDataType());
        assertTrue(val instanceof Array);
        arr = (Array) val;
        assertEquals(1, arr.size());
    }
    {
        Document doc = new Document(docType, "doc:scheme:");
        Array<StringFieldValue> arr = new Array<>(DataType.getArray(DataType.STRING));
        arr.add(new StringFieldValue("a1"));
        arr.add(new StringFieldValue("a2"));
        doc.setFieldValue("arr_a", arr);
        arr = new Array<StringFieldValue>(DataType.getArray(DataType.STRING));
        arr.add(new StringFieldValue("b1"));
        doc.setFieldValue("arr_b", arr);
        assertNotNull(doc = Expression.execute(exp, doc));
        FieldValue val = doc.getFieldValue("out");
        assertNotNull(val);
        assertEquals(DataType.getArray(DataType.STRING), val.getDataType());
        assertTrue(val instanceof Array);
        arr = (Array) val;
        assertEquals(3, arr.size());
    }
}
Also used : Expression(com.yahoo.vespa.indexinglanguage.expressions.Expression) Test(org.junit.Test)

Example 7 with Expression

use of com.yahoo.vespa.indexinglanguage.expressions.Expression in project vespa by vespa-engine.

the class ExpressionConverterTestCase method requireThatConversionExceptionCanBeThrown.

@Test
public void requireThatConversionExceptionCanBeThrown() {
    final RuntimeException expectedCause = new RuntimeException();
    try {
        new ExpressionConverter() {

            @Override
            protected boolean shouldConvert(Expression exp) {
                return exp instanceof AttributeExpression;
            }

            @Override
            protected Expression doConvert(Expression exp) {
                throw expectedCause;
            }
        }.convert(new StatementExpression(new AttributeExpression("foo")));
        fail();
    } catch (RuntimeException e) {
        assertSame(expectedCause, e);
    }
}
Also used : GetFieldExpression(com.yahoo.vespa.indexinglanguage.expressions.GetFieldExpression) SetVarExpression(com.yahoo.vespa.indexinglanguage.expressions.SetVarExpression) Base64DecodeExpression(com.yahoo.vespa.indexinglanguage.expressions.Base64DecodeExpression) SummaryExpression(com.yahoo.vespa.indexinglanguage.expressions.SummaryExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) IndexExpression(com.yahoo.vespa.indexinglanguage.expressions.IndexExpression) SubstringExpression(com.yahoo.vespa.indexinglanguage.expressions.SubstringExpression) ClearStateExpression(com.yahoo.vespa.indexinglanguage.expressions.ClearStateExpression) EchoExpression(com.yahoo.vespa.indexinglanguage.expressions.EchoExpression) ToByteExpression(com.yahoo.vespa.indexinglanguage.expressions.ToByteExpression) TrimExpression(com.yahoo.vespa.indexinglanguage.expressions.TrimExpression) GuardExpression(com.yahoo.vespa.indexinglanguage.expressions.GuardExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) JoinExpression(com.yahoo.vespa.indexinglanguage.expressions.JoinExpression) LowerCaseExpression(com.yahoo.vespa.indexinglanguage.expressions.LowerCaseExpression) GetVarExpression(com.yahoo.vespa.indexinglanguage.expressions.GetVarExpression) NowExpression(com.yahoo.vespa.indexinglanguage.expressions.NowExpression) HostNameExpression(com.yahoo.vespa.indexinglanguage.expressions.HostNameExpression) SwitchExpression(com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression) CompositeExpression(com.yahoo.vespa.indexinglanguage.expressions.CompositeExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) CatExpression(com.yahoo.vespa.indexinglanguage.expressions.CatExpression) SetLanguageExpression(com.yahoo.vespa.indexinglanguage.expressions.SetLanguageExpression) Expression(com.yahoo.vespa.indexinglanguage.expressions.Expression) SetValueExpression(com.yahoo.vespa.indexinglanguage.expressions.SetValueExpression) ToLongExpression(com.yahoo.vespa.indexinglanguage.expressions.ToLongExpression) ZCurveExpression(com.yahoo.vespa.indexinglanguage.expressions.ZCurveExpression) ToDoubleExpression(com.yahoo.vespa.indexinglanguage.expressions.ToDoubleExpression) ArithmeticExpression(com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression) InputExpression(com.yahoo.vespa.indexinglanguage.expressions.InputExpression) ToFloatExpression(com.yahoo.vespa.indexinglanguage.expressions.ToFloatExpression) OptimizePredicateExpression(com.yahoo.vespa.indexinglanguage.expressions.OptimizePredicateExpression) TokenizeExpression(com.yahoo.vespa.indexinglanguage.expressions.TokenizeExpression) ToArrayExpression(com.yahoo.vespa.indexinglanguage.expressions.ToArrayExpression) ToIntegerExpression(com.yahoo.vespa.indexinglanguage.expressions.ToIntegerExpression) ThisExpression(com.yahoo.vespa.indexinglanguage.expressions.ThisExpression) ForEachExpression(com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression) NormalizeExpression(com.yahoo.vespa.indexinglanguage.expressions.NormalizeExpression) RandomExpression(com.yahoo.vespa.indexinglanguage.expressions.RandomExpression) Base64EncodeExpression(com.yahoo.vespa.indexinglanguage.expressions.Base64EncodeExpression) IfThenExpression(com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression) HexDecodeExpression(com.yahoo.vespa.indexinglanguage.expressions.HexDecodeExpression) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) ToWsetExpression(com.yahoo.vespa.indexinglanguage.expressions.ToWsetExpression) ParenthesisExpression(com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression) HexEncodeExpression(com.yahoo.vespa.indexinglanguage.expressions.HexEncodeExpression) ToPositionExpression(com.yahoo.vespa.indexinglanguage.expressions.ToPositionExpression) ToStringExpression(com.yahoo.vespa.indexinglanguage.expressions.ToStringExpression) SplitExpression(com.yahoo.vespa.indexinglanguage.expressions.SplitExpression) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) Test(org.junit.Test)

Example 8 with Expression

use of com.yahoo.vespa.indexinglanguage.expressions.Expression in project vespa by vespa-engine.

the class ExpressionConverterTestCase method requireThatCatConversionIgnoresNull.

@Test
public void requireThatCatConversionIgnoresNull() {
    Expression exp = new ExpressionConverter() {

        @Override
        protected boolean shouldConvert(Expression exp) {
            return exp instanceof AttributeExpression;
        }

        @Override
        protected Expression doConvert(Expression exp) {
            return null;
        }
    }.convert(new CatExpression(new AttributeExpression("foo"), new IndexExpression("bar")));
    assertEquals(new CatExpression(new IndexExpression("bar")), exp);
}
Also used : GetFieldExpression(com.yahoo.vespa.indexinglanguage.expressions.GetFieldExpression) SetVarExpression(com.yahoo.vespa.indexinglanguage.expressions.SetVarExpression) Base64DecodeExpression(com.yahoo.vespa.indexinglanguage.expressions.Base64DecodeExpression) SummaryExpression(com.yahoo.vespa.indexinglanguage.expressions.SummaryExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) IndexExpression(com.yahoo.vespa.indexinglanguage.expressions.IndexExpression) SubstringExpression(com.yahoo.vespa.indexinglanguage.expressions.SubstringExpression) ClearStateExpression(com.yahoo.vespa.indexinglanguage.expressions.ClearStateExpression) EchoExpression(com.yahoo.vespa.indexinglanguage.expressions.EchoExpression) ToByteExpression(com.yahoo.vespa.indexinglanguage.expressions.ToByteExpression) TrimExpression(com.yahoo.vespa.indexinglanguage.expressions.TrimExpression) GuardExpression(com.yahoo.vespa.indexinglanguage.expressions.GuardExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) JoinExpression(com.yahoo.vespa.indexinglanguage.expressions.JoinExpression) LowerCaseExpression(com.yahoo.vespa.indexinglanguage.expressions.LowerCaseExpression) GetVarExpression(com.yahoo.vespa.indexinglanguage.expressions.GetVarExpression) NowExpression(com.yahoo.vespa.indexinglanguage.expressions.NowExpression) HostNameExpression(com.yahoo.vespa.indexinglanguage.expressions.HostNameExpression) SwitchExpression(com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression) CompositeExpression(com.yahoo.vespa.indexinglanguage.expressions.CompositeExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) CatExpression(com.yahoo.vespa.indexinglanguage.expressions.CatExpression) SetLanguageExpression(com.yahoo.vespa.indexinglanguage.expressions.SetLanguageExpression) Expression(com.yahoo.vespa.indexinglanguage.expressions.Expression) SetValueExpression(com.yahoo.vespa.indexinglanguage.expressions.SetValueExpression) ToLongExpression(com.yahoo.vespa.indexinglanguage.expressions.ToLongExpression) ZCurveExpression(com.yahoo.vespa.indexinglanguage.expressions.ZCurveExpression) ToDoubleExpression(com.yahoo.vespa.indexinglanguage.expressions.ToDoubleExpression) ArithmeticExpression(com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression) InputExpression(com.yahoo.vespa.indexinglanguage.expressions.InputExpression) ToFloatExpression(com.yahoo.vespa.indexinglanguage.expressions.ToFloatExpression) OptimizePredicateExpression(com.yahoo.vespa.indexinglanguage.expressions.OptimizePredicateExpression) TokenizeExpression(com.yahoo.vespa.indexinglanguage.expressions.TokenizeExpression) ToArrayExpression(com.yahoo.vespa.indexinglanguage.expressions.ToArrayExpression) ToIntegerExpression(com.yahoo.vespa.indexinglanguage.expressions.ToIntegerExpression) ThisExpression(com.yahoo.vespa.indexinglanguage.expressions.ThisExpression) ForEachExpression(com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression) NormalizeExpression(com.yahoo.vespa.indexinglanguage.expressions.NormalizeExpression) RandomExpression(com.yahoo.vespa.indexinglanguage.expressions.RandomExpression) Base64EncodeExpression(com.yahoo.vespa.indexinglanguage.expressions.Base64EncodeExpression) IfThenExpression(com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression) HexDecodeExpression(com.yahoo.vespa.indexinglanguage.expressions.HexDecodeExpression) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) ToWsetExpression(com.yahoo.vespa.indexinglanguage.expressions.ToWsetExpression) ParenthesisExpression(com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression) HexEncodeExpression(com.yahoo.vespa.indexinglanguage.expressions.HexEncodeExpression) ToPositionExpression(com.yahoo.vespa.indexinglanguage.expressions.ToPositionExpression) ToStringExpression(com.yahoo.vespa.indexinglanguage.expressions.ToStringExpression) SplitExpression(com.yahoo.vespa.indexinglanguage.expressions.SplitExpression) CatExpression(com.yahoo.vespa.indexinglanguage.expressions.CatExpression) IndexExpression(com.yahoo.vespa.indexinglanguage.expressions.IndexExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) Test(org.junit.Test)

Example 9 with Expression

use of com.yahoo.vespa.indexinglanguage.expressions.Expression in project vespa by vespa-engine.

the class ExpressionSearcherTestCase method requireThatExpressionsCanBeFound.

@Test
public void requireThatExpressionsCanBeFound() {
    IndexExpression exp = new IndexExpression("foo");
    assertFound(exp, new ArithmeticExpression(exp, ArithmeticExpression.Operator.ADD, new AttributeExpression("foo")));
    assertFound(exp, new ArithmeticExpression(new AttributeExpression("foo"), ArithmeticExpression.Operator.ADD, exp));
    assertFound(exp, new CatExpression(exp));
    assertFound(exp, new CatExpression(new AttributeExpression("foo"), exp));
    assertFound(exp, new ForEachExpression(exp));
    assertFound(exp, new GuardExpression(exp));
    assertFound(exp, new IfThenExpression(exp, IfThenExpression.Comparator.EQ, new AttributeExpression("foo"), new AttributeExpression("bar"), new AttributeExpression("baz")));
    assertFound(exp, new IfThenExpression(new AttributeExpression("foo"), IfThenExpression.Comparator.EQ, exp, new AttributeExpression("bar"), new AttributeExpression("baz")));
    assertFound(exp, new IfThenExpression(new AttributeExpression("foo"), IfThenExpression.Comparator.EQ, new AttributeExpression("bar"), exp, new AttributeExpression("baz")));
    assertFound(exp, new IfThenExpression(new AttributeExpression("foo"), IfThenExpression.Comparator.EQ, new AttributeExpression("bar"), new AttributeExpression("baz"), exp));
    assertFound(exp, new ParenthesisExpression(exp));
    assertFound(exp, new ScriptExpression(new StatementExpression(exp)));
    assertFound(exp, new ScriptExpression(new StatementExpression(new AttributeExpression("foo")), new StatementExpression(exp)));
    assertFound(exp, new SelectInputExpression(Arrays.asList(new Pair<String, Expression>("foo", exp), new Pair<String, Expression>("bar", new AttributeExpression("bar")))));
    assertFound(exp, new SelectInputExpression(Arrays.asList(new Pair<String, Expression>("foo", new AttributeExpression("bar")), new Pair<String, Expression>("bar", exp))));
    assertFound(exp, new StatementExpression(exp));
    assertFound(exp, new StatementExpression(new AttributeExpression("foo"), exp));
    assertFound(exp, new SwitchExpression(Collections.singletonMap("foo", exp), new AttributeExpression("bar")));
    assertFound(exp, new SwitchExpression(Collections.singletonMap("foo", new AttributeExpression("bar")), exp));
}
Also used : SwitchExpression(com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) CatExpression(com.yahoo.vespa.indexinglanguage.expressions.CatExpression) GuardExpression(com.yahoo.vespa.indexinglanguage.expressions.GuardExpression) ParenthesisExpression(com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression) IndexExpression(com.yahoo.vespa.indexinglanguage.expressions.IndexExpression) ArithmeticExpression(com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) IfThenExpression(com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression) SwitchExpression(com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) CatExpression(com.yahoo.vespa.indexinglanguage.expressions.CatExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) IndexExpression(com.yahoo.vespa.indexinglanguage.expressions.IndexExpression) ForEachExpression(com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression) Expression(com.yahoo.vespa.indexinglanguage.expressions.Expression) ParenthesisExpression(com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression) GuardExpression(com.yahoo.vespa.indexinglanguage.expressions.GuardExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) ArithmeticExpression(com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression) ForEachExpression(com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression) IfThenExpression(com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) Test(org.junit.Test)

Aggregations

Expression (com.yahoo.vespa.indexinglanguage.expressions.Expression)9 GuardExpression (com.yahoo.vespa.indexinglanguage.expressions.GuardExpression)6 ScriptExpression (com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)6 StatementExpression (com.yahoo.vespa.indexinglanguage.expressions.StatementExpression)6 ArithmeticExpression (com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression)5 AttributeExpression (com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression)5 CatExpression (com.yahoo.vespa.indexinglanguage.expressions.CatExpression)5 ClearStateExpression (com.yahoo.vespa.indexinglanguage.expressions.ClearStateExpression)5 ForEachExpression (com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression)5 IfThenExpression (com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression)5 IndexExpression (com.yahoo.vespa.indexinglanguage.expressions.IndexExpression)5 InputExpression (com.yahoo.vespa.indexinglanguage.expressions.InputExpression)5 ParenthesisExpression (com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression)5 SelectInputExpression (com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression)5 SwitchExpression (com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression)5 Test (org.junit.Test)5 Base64DecodeExpression (com.yahoo.vespa.indexinglanguage.expressions.Base64DecodeExpression)4 Base64EncodeExpression (com.yahoo.vespa.indexinglanguage.expressions.Base64EncodeExpression)4 CompositeExpression (com.yahoo.vespa.indexinglanguage.expressions.CompositeExpression)4 EchoExpression (com.yahoo.vespa.indexinglanguage.expressions.EchoExpression)4