use of com.yahoo.searchlib.expression.IntegerResultNode in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatUnexpectedGroupingResultsAreIgnored.
@Test
public void requireThatUnexpectedGroupingResultsAreIgnored() {
Query query = newQuery();
GroupingRequest req = GroupingRequest.newInstance(query);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(output(max(bar))))"));
Grouping grpExpected = new Grouping(0);
grpExpected.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("expected")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(69)).setTag(3))));
Grouping grpUnexpected = new Grouping(1);
grpUnexpected.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("unexpected")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(96)).setTag(3))));
Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grpExpected), null), new GroupingListHit(Arrays.asList(grpUnexpected), null))));
Group grp = req.getResultGroup(exec.search(query));
assertEquals(1, grp.size());
Hit hit = grp.get(0);
assertTrue(hit instanceof GroupList);
GroupList lst = (GroupList) hit;
assertEquals(1, lst.size());
assertNotNull(hit = lst.get("group:string:expected"));
assertEquals(69L, hit.getField("max(bar)"));
assertNull(lst.get("group:string:unexpected"));
}
use of com.yahoo.searchlib.expression.IntegerResultNode in project vespa by vespa-engine.
the class ExpressionConverter method toTime.
private TimeStampFunctionNode toTime(GroupingExpression arg, TimeStampFunctionNode.TimePart timePart) {
if (timeOffset == 0) {
return new TimeStampFunctionNode(toExpressionNode(arg), timePart, true);
}
AddFunctionNode exp = new AddFunctionNode();
exp.addArg(toExpressionNode(arg));
exp.addArg(new ConstantNode(new IntegerResultNode(timeOffset)));
return new TimeStampFunctionNode(exp, timePart, true);
}
use of com.yahoo.searchlib.expression.IntegerResultNode in project vespa by vespa-engine.
the class ExpressionConverter method toExpressionNode.
/**
* Converts the given ast type grouping expression to a corresponding back-end type expression.
*
* @param exp The expression to convert.
* @return The corresponding back-end expression.
* @throws UnsupportedOperationException Thrown if the given expression could not be converted.
*/
public ExpressionNode toExpressionNode(GroupingExpression exp) {
if (exp instanceof AddFunction) {
return addArguments(new AddFunctionNode(), (AddFunction) exp);
}
if (exp instanceof AggregatorNode) {
return new AggregationRefNode(toAggregationResult(exp));
}
if (exp instanceof AndFunction) {
return addArguments(new AndFunctionNode(), (AndFunction) exp);
}
if (exp instanceof AttributeValue) {
return new AttributeNode(((AttributeValue) exp).getAttributeName());
}
if (exp instanceof AttributeFunction) {
return new AttributeNode(((AttributeFunction) exp).getAttributeName());
}
if (exp instanceof CatFunction) {
return addArguments(new CatFunctionNode(), (CatFunction) exp);
}
if (exp instanceof DebugWaitFunction) {
return new DebugWaitFunctionNode(toExpressionNode(((DebugWaitFunction) exp).getArg(0)), ((DebugWaitFunction) exp).getWaitTime(), ((DebugWaitFunction) exp).getBusyWait());
}
if (exp instanceof DocIdNsSpecificValue) {
return new GetDocIdNamespaceSpecificFunctionNode();
}
if (exp instanceof DoubleValue) {
return new ConstantNode(new FloatResultNode(((DoubleValue) exp).getValue()));
}
if (exp instanceof DivFunction) {
return addArguments(new DivideFunctionNode(), (DivFunction) exp);
}
if (exp instanceof FixedWidthFunction) {
Number w = ((FixedWidthFunction) exp).getWidth();
return new FixedWidthBucketFunctionNode(w instanceof Double ? new FloatResultNode(w.doubleValue()) : new IntegerResultNode(w.longValue()), toExpressionNode(((FixedWidthFunction) exp).getArg(0)));
}
if (exp instanceof LongValue) {
return new ConstantNode(new IntegerResultNode(((LongValue) exp).getValue()));
}
if (exp instanceof MaxFunction) {
return addArguments(new MaxFunctionNode(), (MaxFunction) exp);
}
if (exp instanceof Md5Function) {
return new MD5BitFunctionNode().setNumBits(((Md5Function) exp).getNumBits()).addArg(toExpressionNode(((Md5Function) exp).getArg(0)));
}
if (exp instanceof UcaFunction) {
UcaFunction uca = (UcaFunction) exp;
return new UcaFunctionNode(toExpressionNode(uca.getArg(0)), uca.getLocale(), uca.getStrength());
}
if (exp instanceof MinFunction) {
return addArguments(new MinFunctionNode(), (MinFunction) exp);
}
if (exp instanceof ModFunction) {
return addArguments(new ModuloFunctionNode(), (ModFunction) exp);
}
if (exp instanceof MulFunction) {
return addArguments(new MultiplyFunctionNode(), (MulFunction) exp);
}
if (exp instanceof NegFunction) {
return new NegateFunctionNode(toExpressionNode(((NegFunction) exp).getArg(0)));
}
if (exp instanceof NormalizeSubjectFunction) {
return new NormalizeSubjectFunctionNode(toExpressionNode(((NormalizeSubjectFunction) exp).getArg(0)));
}
if (exp instanceof NowFunction) {
return new ConstantNode(new IntegerResultNode(System.currentTimeMillis() / 1000));
}
if (exp instanceof OrFunction) {
return addArguments(new OrFunctionNode(), (OrFunction) exp);
}
if (exp instanceof PredefinedFunction) {
return new RangeBucketPreDefFunctionNode(toBucketList((PredefinedFunction) exp), toExpressionNode(((PredefinedFunction) exp).getArg(0)));
}
if (exp instanceof RelevanceValue) {
return new RelevanceNode();
}
if (exp instanceof ReverseFunction) {
return new ReverseFunctionNode(toExpressionNode(((ReverseFunction) exp).getArg(0)));
}
if (exp instanceof SizeFunction) {
return new NumElemFunctionNode(toExpressionNode(((SizeFunction) exp).getArg(0)));
}
if (exp instanceof SortFunction) {
return new SortFunctionNode(toExpressionNode(((SortFunction) exp).getArg(0)));
}
if (exp instanceof ArrayAtLookup) {
ArrayAtLookup aal = (ArrayAtLookup) exp;
return new ArrayAtLookupNode(aal.getAttributeName(), toExpressionNode(aal.getIndexArgument()));
}
if (exp instanceof InterpolatedLookup) {
InterpolatedLookup sarl = (InterpolatedLookup) exp;
return new InterpolatedLookupNode(sarl.getAttributeName(), toExpressionNode(sarl.getLookupArgument()));
}
if (exp instanceof StrCatFunction) {
return addArguments(new StrCatFunctionNode(), (StrCatFunction) exp);
}
if (exp instanceof StringValue) {
return new ConstantNode(new StringResultNode(((StringValue) exp).getValue()));
}
if (exp instanceof StrLenFunction) {
return new StrLenFunctionNode(toExpressionNode(((StrLenFunction) exp).getArg(0)));
}
if (exp instanceof SubFunction) {
return toSubNode((SubFunction) exp);
}
if (exp instanceof ToDoubleFunction) {
return new ToFloatFunctionNode(toExpressionNode(((ToDoubleFunction) exp).getArg(0)));
}
if (exp instanceof ToLongFunction) {
return new ToIntFunctionNode(toExpressionNode(((ToLongFunction) exp).getArg(0)));
}
if (exp instanceof ToRawFunction) {
return new ToRawFunctionNode(toExpressionNode(((ToRawFunction) exp).getArg(0)));
}
if (exp instanceof ToStringFunction) {
return new ToStringFunctionNode(toExpressionNode(((ToStringFunction) exp).getArg(0)));
}
if (exp instanceof DateFunction) {
StrCatFunctionNode ret = new StrCatFunctionNode();
GroupingExpression arg = ((DateFunction) exp).getArg(0);
ret.addArg(new ToStringFunctionNode(toTime(arg, TimeStampFunctionNode.TimePart.Year)));
ret.addArg(new ConstantNode(new StringResultNode("-")));
ret.addArg(new ToStringFunctionNode(toTime(arg, TimeStampFunctionNode.TimePart.Month)));
ret.addArg(new ConstantNode(new StringResultNode("-")));
ret.addArg(new ToStringFunctionNode(toTime(arg, TimeStampFunctionNode.TimePart.MonthDay)));
return ret;
}
if (exp instanceof MathSqrtFunction) {
return new MathFunctionNode(toExpressionNode(((MathSqrtFunction) exp).getArg(0)), MathFunctionNode.Function.SQRT);
}
if (exp instanceof MathCbrtFunction) {
return new MathFunctionNode(toExpressionNode(((MathCbrtFunction) exp).getArg(0)), MathFunctionNode.Function.CBRT);
}
if (exp instanceof MathLogFunction) {
return new MathFunctionNode(toExpressionNode(((MathLogFunction) exp).getArg(0)), MathFunctionNode.Function.LOG);
}
if (exp instanceof MathLog1pFunction) {
return new MathFunctionNode(toExpressionNode(((MathLog1pFunction) exp).getArg(0)), MathFunctionNode.Function.LOG1P);
}
if (exp instanceof MathLog10Function) {
return new MathFunctionNode(toExpressionNode(((MathLog10Function) exp).getArg(0)), MathFunctionNode.Function.LOG10);
}
if (exp instanceof MathExpFunction) {
return new MathFunctionNode(toExpressionNode(((MathExpFunction) exp).getArg(0)), MathFunctionNode.Function.EXP);
}
if (exp instanceof MathPowFunction) {
return new MathFunctionNode(toExpressionNode(((MathPowFunction) exp).getArg(0)), MathFunctionNode.Function.POW).addArg(toExpressionNode(((MathPowFunction) exp).getArg(1)));
}
if (exp instanceof MathHypotFunction) {
return new MathFunctionNode(toExpressionNode(((MathHypotFunction) exp).getArg(0)), MathFunctionNode.Function.HYPOT).addArg(toExpressionNode(((MathHypotFunction) exp).getArg(1)));
}
if (exp instanceof MathSinFunction) {
return new MathFunctionNode(toExpressionNode(((MathSinFunction) exp).getArg(0)), MathFunctionNode.Function.SIN);
}
if (exp instanceof MathASinFunction) {
return new MathFunctionNode(toExpressionNode(((MathASinFunction) exp).getArg(0)), MathFunctionNode.Function.ASIN);
}
if (exp instanceof MathCosFunction) {
return new MathFunctionNode(toExpressionNode(((MathCosFunction) exp).getArg(0)), MathFunctionNode.Function.COS);
}
if (exp instanceof MathACosFunction) {
return new MathFunctionNode(toExpressionNode(((MathACosFunction) exp).getArg(0)), MathFunctionNode.Function.ACOS);
}
if (exp instanceof MathTanFunction) {
return new MathFunctionNode(toExpressionNode(((MathTanFunction) exp).getArg(0)), MathFunctionNode.Function.TAN);
}
if (exp instanceof MathATanFunction) {
return new MathFunctionNode(toExpressionNode(((MathATanFunction) exp).getArg(0)), MathFunctionNode.Function.ATAN);
}
if (exp instanceof MathSinHFunction) {
return new MathFunctionNode(toExpressionNode(((MathSinHFunction) exp).getArg(0)), MathFunctionNode.Function.SINH);
}
if (exp instanceof MathASinHFunction) {
return new MathFunctionNode(toExpressionNode(((MathASinHFunction) exp).getArg(0)), MathFunctionNode.Function.ASINH);
}
if (exp instanceof MathCosHFunction) {
return new MathFunctionNode(toExpressionNode(((MathCosHFunction) exp).getArg(0)), MathFunctionNode.Function.COSH);
}
if (exp instanceof MathACosHFunction) {
return new MathFunctionNode(toExpressionNode(((MathACosHFunction) exp).getArg(0)), MathFunctionNode.Function.ACOSH);
}
if (exp instanceof MathTanHFunction) {
return new MathFunctionNode(toExpressionNode(((MathTanHFunction) exp).getArg(0)), MathFunctionNode.Function.TANH);
}
if (exp instanceof MathATanHFunction) {
return new MathFunctionNode(toExpressionNode(((MathATanHFunction) exp).getArg(0)), MathFunctionNode.Function.ATANH);
}
if (exp instanceof MathFloorFunction) {
return new MathFunctionNode(toExpressionNode(((MathFloorFunction) exp).getArg(0)), MathFunctionNode.Function.FLOOR);
}
if (exp instanceof ZCurveXFunction) {
return new ZCurveFunctionNode(toExpressionNode(((ZCurveXFunction) exp).getArg(0)), ZCurveFunctionNode.Dimension.X);
}
if (exp instanceof ZCurveYFunction) {
return new ZCurveFunctionNode(toExpressionNode(((ZCurveYFunction) exp).getArg(0)), ZCurveFunctionNode.Dimension.Y);
}
if (exp instanceof DayOfMonthFunction) {
return toTime(((DayOfMonthFunction) exp).getArg(0), TimeStampFunctionNode.TimePart.MonthDay);
}
if (exp instanceof DayOfWeekFunction) {
return toTime(((DayOfWeekFunction) exp).getArg(0), TimeStampFunctionNode.TimePart.WeekDay);
}
if (exp instanceof DayOfYearFunction) {
return toTime(((DayOfYearFunction) exp).getArg(0), TimeStampFunctionNode.TimePart.YearDay);
}
if (exp instanceof HourOfDayFunction) {
return toTime(((HourOfDayFunction) exp).getArg(0), TimeStampFunctionNode.TimePart.Hour);
}
if (exp instanceof MinuteOfHourFunction) {
return toTime(((MinuteOfHourFunction) exp).getArg(0), TimeStampFunctionNode.TimePart.Minute);
}
if (exp instanceof MonthOfYearFunction) {
return toTime(((MonthOfYearFunction) exp).getArg(0), TimeStampFunctionNode.TimePart.Month);
}
if (exp instanceof SecondOfMinuteFunction) {
return toTime(((SecondOfMinuteFunction) exp).getArg(0), TimeStampFunctionNode.TimePart.Second);
}
if (exp instanceof YearFunction) {
return toTime(((YearFunction) exp).getArg(0), TimeStampFunctionNode.TimePart.Year);
}
if (exp instanceof XorFunction) {
return addArguments(new XorFunctionNode(), (XorFunction) exp);
}
if (exp instanceof XorBitFunction) {
return new XorBitFunctionNode().setNumBits(((XorBitFunction) exp).getNumBits()).addArg(toExpressionNode(((XorBitFunction) exp).getArg(0)));
}
if (exp instanceof YmumValue) {
return new GetYMUMChecksumFunctionNode();
}
throw new UnsupportedOperationException("Can not convert '" + exp + "' of class " + exp.getClass().getName() + " to an expression.");
}
use of com.yahoo.searchlib.expression.IntegerResultNode in project vespa by vespa-engine.
the class ObjectVisitorTestCase method testObjectDumper.
public void testObjectDumper() {
assertDump("test: <NULL>\n", null);
assertDump("test: 1\n", 1);
assertDump("test: 'foo'\n", "foo");
assertDump("test: List {\n" + " [0]: 'foo'\n" + " [1]: 69\n" + " [2]: <NULL>\n" + "}\n", Arrays.asList("foo", 69, null));
assertDump("test: String[] {\n" + " [0]: 'foo'\n" + " [1]: 'bar'\n" + " [2]: 'baz'\n" + "}\n", new String[] { "foo", "bar", "baz" });
assertDump("test: IntegerResultNode {\n" + " classId: 16491\n" + " value: 5\n" + "}\n", new IntegerResultNode(5));
assertDump("test: FixedWidthBucketFunctionNode {\n" + " classId: 16461\n" + " result: <NULL>\n" + " args: List {\n" + " [0]: AttributeNode {\n" + " classId: 16439\n" + " result: <NULL>\n" + " attribute: 'foo'\n" + " }\n" + " }\n" + " width: IntegerResultNode {\n" + " classId: 16491\n" + " value: 5\n" + " }\n" + "}\n", new FixedWidthBucketFunctionNode(new IntegerResultNode(5), new AttributeNode("foo")));
}
use of com.yahoo.searchlib.expression.IntegerResultNode in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatPassResultsAreMerged.
@Test
public void requireThatPassResultsAreMerged() {
Query query = newQuery();
GroupingRequest req = GroupingRequest.newInstance(query);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(output(min(bar), max(bar))))"));
Grouping grpA = new Grouping(0);
grpA.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("uniqueA")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(6)).setTag(4))).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("common")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(9)).setTag(4))));
Grouping grpB = new Grouping(0);
grpB.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("uniqueB")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(9)).setTag(4))).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("common")).addAggregationResult(new MinAggregationResult().setMin(new IntegerResultNode(6)).setTag(3))));
Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grpA), null), new GroupingListHit(Arrays.asList(grpB), null))));
Group grp = req.getResultGroup(exec.search(query));
assertEquals(1, grp.size());
Hit hit = grp.get(0);
assertTrue(hit instanceof GroupList);
GroupList lst = (GroupList) hit;
assertEquals(3, lst.size());
assertNotNull(hit = lst.get("group:string:uniqueA"));
assertEquals(6L, hit.getField("max(bar)"));
assertNotNull(hit = lst.get("group:string:uniqueB"));
assertEquals(9L, hit.getField("max(bar)"));
assertNotNull(hit = lst.get("group:string:common"));
assertEquals(6L, hit.getField("min(bar)"));
assertEquals(9L, hit.getField("max(bar)"));
}
Aggregations