use of com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression in project vespa by vespa-engine.
the class ExpressionVisitorTestCase method requireThatAllExpressionsAreVisited.
@SuppressWarnings("unchecked")
@Test
public void requireThatAllExpressionsAreVisited() {
assertCount(3, new ArithmeticExpression(new InputExpression("foo"), ArithmeticExpression.Operator.ADD, new InputExpression("bar")));
assertCount(1, new AttributeExpression("foo"));
assertCount(1, new Base64DecodeExpression());
assertCount(1, new Base64EncodeExpression());
assertCount(3, new CatExpression(new InputExpression("foo"), new IndexExpression("bar")));
assertCount(1, new ClearStateExpression());
assertCount(1, new EchoExpression());
assertCount(2, new ForEachExpression(new IndexExpression("foo")));
assertCount(1, new GetFieldExpression("foo"));
assertCount(1, new GetVarExpression("foo"));
assertCount(2, new GuardExpression(new IndexExpression("foo")));
assertCount(1, new HexDecodeExpression());
assertCount(1, new HexEncodeExpression());
assertCount(1, new HostNameExpression());
assertCount(5, new IfThenExpression(new InputExpression("foo"), IfThenExpression.Comparator.EQ, new InputExpression("bar"), new IndexExpression("baz"), new IndexExpression("cox")));
assertCount(1, new IndexExpression("foo"));
assertCount(1, new InputExpression("foo"));
assertCount(1, new JoinExpression("foo"));
assertCount(1, new LowerCaseExpression());
assertCount(1, new NormalizeExpression(new SimpleLinguistics()));
assertCount(1, new NowExpression());
assertCount(1, new OptimizePredicateExpression());
assertCount(2, new ParenthesisExpression(new InputExpression("foo")));
assertCount(1, new RandomExpression(69));
assertCount(3, new ScriptExpression(new StatementExpression(new InputExpression("foo"))));
assertCount(3, new SelectInputExpression(new Pair<String, Expression>("foo", new IndexExpression("bar")), new Pair<String, Expression>("bar", new IndexExpression("foo"))));
assertCount(1, new SetLanguageExpression());
assertCount(1, new SetValueExpression(new IntegerFieldValue(69)));
assertCount(1, new SetVarExpression("foo"));
assertCount(1, new SplitExpression("foo"));
assertCount(2, new StatementExpression(new InputExpression("foo")));
assertCount(1, new SummaryExpression("foo"));
assertCount(1, new SubstringExpression(6, 9));
assertCount(3, new SwitchExpression(Collections.singletonMap("foo", (Expression) new IndexExpression("bar")), new InputExpression("baz")));
assertCount(1, new ThisExpression());
assertCount(1, new ToArrayExpression());
assertCount(1, new ToByteExpression());
assertCount(1, new ToDoubleExpression());
assertCount(1, new ToFloatExpression());
assertCount(1, new ToIntegerExpression());
assertCount(1, new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig()));
assertCount(1, new ToLongExpression());
assertCount(1, new ToPositionExpression());
assertCount(1, new ToStringExpression());
assertCount(1, new ToWsetExpression(false, false));
assertCount(1, new TrimExpression());
assertCount(1, new ZCurveExpression());
}
use of com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression 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.ScriptExpression in project vespa by vespa-engine.
the class ScriptParserTestCase method requireThatExpressionParserCanBeInvoked.
@Test
public void requireThatExpressionParserCanBeInvoked() throws ParseException {
try {
ScriptParser.parseExpression(newContext("foo"));
} catch (ParseException e) {
assertException(e, "Encountered \" <IDENTIFIER> \"foo \"\" at line 1, column 1.");
}
assertEquals(new InputExpression("foo"), ScriptParser.parseExpression(newContext("input foo")));
assertEquals(new StatementExpression(new InputExpression("foo"), new EchoExpression()), ScriptParser.parseExpression(newContext("input foo | echo")));
assertEquals(new ScriptExpression(new StatementExpression(new InputExpression("foo")), new StatementExpression(new EchoExpression())), ScriptParser.parseExpression(newContext("{ input foo; echo }")));
}
use of com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression in project vespa by vespa-engine.
the class ScriptManager method createScriptsMap.
private static Map<String, Map<String, DocumentScript>> createScriptsMap(DocumentTypeManager docTypeMgr, IlscriptsConfig config, Linguistics linguistics) {
Map<String, Map<String, DocumentScript>> documentFieldScripts = new HashMap<>(config.ilscript().size());
ScriptParserContext parserContext = new ScriptParserContext(linguistics);
parserContext.getAnnotatorConfig().setMaxTermOccurrences(config.maxtermoccurrences());
parserContext.getAnnotatorConfig().setMaxTokenLength(config.fieldmatchmaxlength());
for (IlscriptsConfig.Ilscript ilscript : config.ilscript()) {
InputExpression.FieldPathOptimizer fieldPathOptimizer = new InputExpression.FieldPathOptimizer(docTypeMgr.getDocumentType(ilscript.doctype()));
List<StatementExpression> expressions = new ArrayList<>(ilscript.content().size());
Map<String, DocumentScript> fieldScripts = new HashMap<>(ilscript.content().size());
for (String content : ilscript.content()) {
expressions.add(parse(ilscript.doctype(), parserContext, content));
StatementExpression statement = parse(ilscript.doctype(), parserContext, content);
InputExpression.InputFieldNameExtractor inputFieldNameExtractor = new InputExpression.InputFieldNameExtractor();
statement.select(inputFieldNameExtractor, inputFieldNameExtractor);
statement.select(fieldPathOptimizer, fieldPathOptimizer);
if (inputFieldNameExtractor.getInputFieldNames().size() == 1) {
String fieldName = inputFieldNameExtractor.getInputFieldNames().get(0);
ScriptExpression script;
if (fieldScripts.containsKey(fieldName)) {
DocumentScript prev = fieldScripts.get(fieldName);
List<StatementExpression> appendedList = new ArrayList<>(((ScriptExpression) prev.getExpression()).asList());
appendedList.add(statement);
script = new ScriptExpression(appendedList);
log.log(Level.FINE, "Appending script for field '" + fieldName + "' = " + statement);
log.log(Level.FINE, "Full script for field '" + fieldName + "' = " + appendedList);
} else {
script = new ScriptExpression(statement);
log.log(Level.FINE, "Setting script for field '" + fieldName + "' = " + statement);
}
DocumentScript documentScript = new DocumentScript(ilscript.doctype(), inputFieldNameExtractor.getInputFieldNames(), script);
fieldScripts.put(fieldName, documentScript);
} else {
log.log(Level.FINE, "Non single(" + inputFieldNameExtractor.getInputFieldNames().size() + ") inputs = " + inputFieldNameExtractor.getInputFieldNames() + ". Script = " + statement);
}
}
ScriptExpression script = new ScriptExpression(expressions);
script.select(fieldPathOptimizer, fieldPathOptimizer);
fieldScripts.put(FULL, new DocumentScript(ilscript.doctype(), ilscript.docfield(), script));
documentFieldScripts.put(ilscript.doctype(), Collections.unmodifiableMap(fieldScripts));
}
return Collections.unmodifiableMap(documentFieldScripts);
}
use of com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression in project vespa by vespa-engine.
the class IntegerIndex2Attribute method process.
@Override
public void process(boolean validate) {
for (SDField field : search.allConcreteFields()) {
if (field.doesIndexing() && field.getDataType().getPrimitiveType() instanceof NumericDataType) {
if (field.getIndex(field.getName()) != null && !(field.getIndex(field.getName()).getType().equals(Index.Type.VESPA)))
continue;
ScriptExpression script = field.getIndexingScript();
Set<String> attributeNames = new HashSet<>();
new MyVisitor(attributeNames).visit(script);
field.setIndexingScript((ScriptExpression) new MyConverter(attributeNames).convert(script));
warn(search, field, "Changed to attribute because numerical indexes (field has type " + field.getDataType().getName() + ") is not currently supported." + " Index-only settings may fail. Ignore this warning for streaming search.");
}
}
}
Aggregations