private BucketResultNode toBucket(GroupingExpression exp) {
        if (!(exp instanceof BucketValue bucketValue)) {
            throw new IllegalInputException("Can not convert '" + exp + "' to a bucket.");
        }
        ConstantValue<?> begin = bucketValue.getFrom();
        ConstantValue<?> end = bucketValue.getTo();
        if (begin instanceof DoubleValue || end instanceof DoubleValue) {
            return new FloatBucketResultNode(
                    begin instanceof InfiniteValue ? FloatResultNode.getNegativeInfinity().getFloat()
                                                   : Double.valueOf(begin.toString()),
                    end instanceof InfiniteValue ? FloatResultNode.getPositiveInfinity().getFloat()
                                                 : Double.valueOf(end.toString()));
        } else if (begin instanceof LongValue || end instanceof LongValue) {
            return new IntegerBucketResultNode(
                    begin instanceof InfiniteValue ? IntegerResultNode.getNegativeInfinity().getInteger()
                                                   : Long.valueOf(begin.toString()),
                    end instanceof InfiniteValue ? IntegerResultNode.getPositiveInfinity().getInteger()
                                                 : Long.valueOf(end.toString()));
        } else if (begin instanceof StringValue || end instanceof StringValue) {
            return new StringBucketResultNode(
                    begin instanceof InfiniteValue ? StringResultNode.getNegativeInfinity()
                                                   : new StringResultNode((String)begin.getValue()),
                    end instanceof InfiniteValue ? StringResultNode.getPositiveInfinity()
                                                 : new StringResultNode((String)end.getValue()));
        } else {
            return new RawBucketResultNode(
                    begin instanceof InfiniteValue ? RawResultNode.getNegativeInfinity()
                                                   : new RawResultNode(((RawValue)begin).getValue().getBytes()),
                    end instanceof InfiniteValue ? RawResultNode.getPositiveInfinity()
                                                 : new RawResultNode(((RawValue)end).getValue().getBytes()));
        }
    }
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 IllegalInputException Thrown if the given expression could not be converted.
container-search/src/main/java/com/yahoo/search/grouping/vespa/ExpressionConverter.java