Search in sources :

Example 1 with RangeItem

use of com.yahoo.prelude.query.RangeItem in project vespa by vespa-engine.

the class RangeItemTestCase method testRangeConstruction.

@Test
public void testRangeConstruction() {
    verifyRange(new RangeItem(5, 7, 9, "a", true), 9, true);
    verifyRange(new RangeItem(5, 7, "a", true), 0, true);
    verifyRange(new RangeItem(5, 7, "a"), 0, false);
}
Also used : RangeItem(com.yahoo.prelude.query.RangeItem) Test(org.junit.Test)

Example 2 with RangeItem

use of com.yahoo.prelude.query.RangeItem in project vespa by vespa-engine.

the class YqlParser method instantiateRangeItem.

@NonNull
private IntItem instantiateRangeItem(List<OperatorNode<ExpressionOperator>> args, OperatorNode<ExpressionOperator> spec) {
    Preconditions.checkArgument(args.size() == 3, "Expected 3 arguments, got %s.", args.size());
    Number lowerArg = getBound(args.get(1));
    Number upperArg = getBound(args.get(2));
    String bounds = getAnnotation(spec, BOUNDS, String.class, null, "whether bounds should be open or closed");
    // TODO: add support for implicit transforms
    if (bounds == null) {
        return new RangeItem(lowerArg, upperArg, getIndex(args.get(0)));
    } else {
        Limit from;
        Limit to;
        if (BOUNDS_OPEN.equals(bounds)) {
            from = new Limit(lowerArg, false);
            to = new Limit(upperArg, false);
        } else if (BOUNDS_LEFT_OPEN.equals(bounds)) {
            from = new Limit(lowerArg, false);
            to = new Limit(upperArg, true);
        } else if (BOUNDS_RIGHT_OPEN.equals(bounds)) {
            from = new Limit(lowerArg, true);
            to = new Limit(upperArg, false);
        } else {
            throw newUnexpectedArgumentException(bounds, BOUNDS_OPEN, BOUNDS_LEFT_OPEN, BOUNDS_RIGHT_OPEN);
        }
        return new IntItem(from, to, getIndex(args.get(0)));
    }
}
Also used : RangeItem(com.yahoo.prelude.query.RangeItem) IntItem(com.yahoo.prelude.query.IntItem) Limit(com.yahoo.prelude.query.Limit) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

RangeItem (com.yahoo.prelude.query.RangeItem)2 IntItem (com.yahoo.prelude.query.IntItem)1 Limit (com.yahoo.prelude.query.Limit)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Test (org.junit.Test)1