use of com.yahoo.vespa.indexinglanguage.expressions.StatementExpression in project vespa by vespa-engine.
the class IndexingScript method generateSyntheticStatementsForUntouchedFields.
private void generateSyntheticStatementsForUntouchedFields(Builder ilscriptBuilder, Set<String> touchedFields) {
Set<String> fieldsWithSyntheticStatements = new HashSet<String>(docFields);
fieldsWithSyntheticStatements.removeAll(touchedFields);
List<String> orderedFields = new ArrayList<String>(fieldsWithSyntheticStatements);
Collections.sort(orderedFields);
for (String fieldName : orderedFields) {
StatementExpression copyField = new StatementExpression(new InputExpression(fieldName), new PassthroughExpression(fieldName));
ilscriptBuilder.content(copyField.toString());
}
}
use of com.yahoo.vespa.indexinglanguage.expressions.StatementExpression in project vespa by vespa-engine.
the class SearchClusterTest method testSdConfigLogical.
@Test
public void testSdConfigLogical() throws IOException, SAXException {
// sd1
SDDocumentType sdt1 = new SDDocumentType("s1");
Search search1 = new Search("s1", null);
SDField f1 = new SDField("f1", DataType.STRING);
f1.addAttribute(new Attribute("f1", DataType.STRING));
f1.setIndexingScript(new ScriptExpression(new StatementExpression(new AttributeExpression("f1"))));
sdt1.addField(f1);
search1.addDocument(sdt1);
// sd2
SDDocumentType sdt2 = new SDDocumentType("s2");
Search search2 = new Search("s2", null);
SDField f2 = new SDField("f2", DataType.STRING);
f2.addAttribute(new Attribute("f2", DataType.STRING));
f2.setIndexingScript(new ScriptExpression(new StatementExpression(new AttributeExpression("f2"))));
sdt2.addField(f2);
search2.addDocument(sdt2);
SearchBuilder builder = new SearchBuilder();
builder.importRawSearch(search1);
builder.importRawSearch(search2);
builder.build();
}
use of com.yahoo.vespa.indexinglanguage.expressions.StatementExpression in project vespa by vespa-engine.
the class ExpressionConverterTestCase method requireThatAllExpressionTypesCanBeTraversed.
@SuppressWarnings("unchecked")
@Test
public void requireThatAllExpressionTypesCanBeTraversed() {
assertConvertable(new ArithmeticExpression(new InputExpression("foo"), ArithmeticExpression.Operator.ADD, new InputExpression("bar")));
assertConvertable(new AttributeExpression("foo"));
assertConvertable(new Base64DecodeExpression());
assertConvertable(new Base64EncodeExpression());
assertConvertable(new CatExpression(new InputExpression("foo"), new IndexExpression("bar")));
assertConvertable(new ClearStateExpression());
assertConvertable(new EchoExpression());
assertConvertable(new ForEachExpression(new IndexExpression("foo")));
assertConvertable(new GetFieldExpression("foo"));
assertConvertable(new GetVarExpression("foo"));
assertConvertable(new GuardExpression(new IndexExpression("foo")));
assertConvertable(new HexDecodeExpression());
assertConvertable(new HexEncodeExpression());
assertConvertable(new HostNameExpression());
assertConvertable(new IfThenExpression(new InputExpression("foo"), IfThenExpression.Comparator.EQ, new InputExpression("bar"), new IndexExpression("baz"), new IndexExpression("cox")));
assertConvertable(new IndexExpression("foo"));
assertConvertable(new InputExpression("foo"));
assertConvertable(new JoinExpression("foo"));
assertConvertable(new LowerCaseExpression());
assertConvertable(new NormalizeExpression(new SimpleLinguistics()));
assertConvertable(new NowExpression());
assertConvertable(new OptimizePredicateExpression());
assertConvertable(new ParenthesisExpression(new InputExpression("foo")));
assertConvertable(new RandomExpression(69));
assertConvertable(new ScriptExpression(new StatementExpression(new InputExpression("foo"))));
assertConvertable(new SelectInputExpression(new Pair<String, Expression>("foo", new IndexExpression("bar")), new Pair<String, Expression>("bar", new IndexExpression("foo"))));
assertConvertable(new SetLanguageExpression());
assertConvertable(new SetValueExpression(new IntegerFieldValue(69)));
assertConvertable(new SetVarExpression("foo"));
assertConvertable(new SplitExpression("foo"));
assertConvertable(new StatementExpression(new InputExpression("foo")));
assertConvertable(new SubstringExpression(6, 9));
assertConvertable(new SummaryExpression("foo"));
assertConvertable(new SwitchExpression(Collections.singletonMap("foo", (Expression) new IndexExpression("bar")), new InputExpression("baz")));
assertConvertable(new ThisExpression());
assertConvertable(new ToArrayExpression());
assertConvertable(new ToByteExpression());
assertConvertable(new ToDoubleExpression());
assertConvertable(new ToFloatExpression());
assertConvertable(new ToIntegerExpression());
assertConvertable(new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig()));
assertConvertable(new ToLongExpression());
assertConvertable(new ToPositionExpression());
assertConvertable(new ToStringExpression());
assertConvertable(new ToWsetExpression(false, false));
assertConvertable(new TrimExpression());
assertConvertable(new ZCurveExpression());
}
use of com.yahoo.vespa.indexinglanguage.expressions.StatementExpression 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);
}
}
use of com.yahoo.vespa.indexinglanguage.expressions.StatementExpression 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));
}
Aggregations