use of com.yahoo.vespa.indexinglanguage.expressions.Expression in project vespa by vespa-engine.
the class IndexingScript method addContentInOrder.
private void addContentInOrder(IlscriptsConfig.Ilscript.Builder ilscriptBuilder) {
ArrayList<Expression> later = new ArrayList<>();
Set<String> touchedFields = new HashSet<String>();
for (Expression exp : expressions) {
FieldScanVisitor fieldFetcher = new FieldScanVisitor();
if (modifiesSelf(exp)) {
later.add(exp);
} else {
ilscriptBuilder.content(exp.toString());
}
fieldFetcher.visit(exp);
touchedFields.addAll(fieldFetcher.touchedFields());
}
for (Expression exp : later) {
ilscriptBuilder.content(exp.toString());
}
generateSyntheticStatementsForUntouchedFields(ilscriptBuilder, touchedFields);
}
use of com.yahoo.vespa.indexinglanguage.expressions.Expression in project vespa by vespa-engine.
the class ExpressionConverterTestCase method requireThatSwitchElementsCanBeRemoved.
@Test
public void requireThatSwitchElementsCanBeRemoved() {
Map<String, Expression> cases = new HashMap<>();
Expression foo = new AttributeExpression("foo");
Expression bar = new AttributeExpression("bar");
cases.put("foo", foo);
cases.put("bar", bar);
SwitchExpression before = new SwitchExpression(cases);
Expression after = new SearchReplace(foo, null).convert(before);
assertTrue(after instanceof SwitchExpression);
assertEquals(1, ((SwitchExpression) after).getCases().size());
after = new SearchReplace(bar, null).convert(before);
assertTrue(after instanceof SwitchExpression);
assertEquals(1, ((SwitchExpression) after).getCases().size());
}
use of com.yahoo.vespa.indexinglanguage.expressions.Expression in project vespa by vespa-engine.
the class ExpressionConverterTestCase method requireThatScriptElementsCanBeRemoved.
@Test
public void requireThatScriptElementsCanBeRemoved() {
StatementExpression foo = new StatementExpression(new AttributeExpression("foo"));
StatementExpression bar = new StatementExpression(new AttributeExpression("bar"));
ScriptExpression before = new ScriptExpression(foo, bar);
Expression after = new SearchReplace(foo, null).convert(before);
assertTrue(after instanceof ScriptExpression);
assertEquals(1, ((ScriptExpression) after).size());
assertEquals(bar, ((ScriptExpression) after).get(0));
after = new SearchReplace(bar, null).convert(before);
assertTrue(after instanceof ScriptExpression);
assertEquals(1, ((ScriptExpression) after).size());
assertEquals(foo, ((ScriptExpression) after).get(0));
}
use of com.yahoo.vespa.indexinglanguage.expressions.Expression in project vespa by vespa-engine.
the class AssertIndexingScript method assertIndexing.
public static void assertIndexing(List<String> expected, Iterable<Expression> actual) {
List<String> parsedExpected = new LinkedList<>();
for (String str : expected) {
try {
parsedExpected.add(Expression.fromString(str).toString());
} catch (ParseException e) {
fail(e.getMessage());
}
}
for (Expression actualExp : actual) {
String str = actualExp.toString();
assertTrue("Unexpected: " + str, parsedExpected.remove(str));
}
assertTrue("Missing: " + parsedExpected.toString(), parsedExpected.isEmpty());
}
use of com.yahoo.vespa.indexinglanguage.expressions.Expression in project vespa by vespa-engine.
the class DocumentTestCase method requireThatConcatenationOfEmbracedStatementsWorks.
@Test
public void requireThatConcatenationOfEmbracedStatementsWorks() throws ParseException {
DocumentType docType = new DocumentType("my_input");
docType.addField(new Field("str_a", DataType.STRING));
docType.addField(new Field("str_b", DataType.STRING));
docType.addField(new Field("out", DataType.getArray(DataType.STRING)));
Expression exp = Expression.fromString("(input str_a | split ',') . (input str_b | split ',') | 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:");
doc.setFieldValue("str_a", new StringFieldValue("a1"));
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(1, arr.size());
}
{
Document doc = new Document(docType, "doc:scheme:");
doc.setFieldValue("str_a", new StringFieldValue("a1,a2"));
doc.setFieldValue("str_b", new StringFieldValue("b1"));
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(3, arr.size());
}
}
Aggregations