blob: ef41b18d21db178af107041a152d522f53eccc04 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.grouping.request;
/**
* This class represents an aggregated value in a {@link GroupingExpression}. Because it operates on a list of data, it
* can not be used as a document-level expression (i.e. level 0, see {@link GroupingExpression#resolveLevel(int)}). The
* contained expression is evaluated at the level of the aggregator minus 1.
*
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
*/
public abstract class AggregatorNode extends GroupingExpression {
private final GroupingExpression exp;
protected AggregatorNode(String image) {
super(image + "()");
this.exp = null;
}
protected AggregatorNode(String image, GroupingExpression exp) {
super(image + "(" + exp.toString() + ")");
this.exp = exp;
}
/**
* Returns the expression that this node aggregates on.
*
* @return The expression.
*/
public GroupingExpression getExpression() {
return exp;
}
@Override
public void resolveLevel(int level) {
super.resolveLevel(level);
if (level < 1) {
throw new IllegalArgumentException("Expression '" + this + "' not applicable for " +
GroupingOperation.getLevelDesc(level) + ".");
}
if (exp != null) {
exp.resolveLevel(level - 1);
}
}
@Override
public void visit(ExpressionVisitor visitor) {
super.visit(visitor);
if (exp != null) {
exp.visit(visitor);
}
}
}
|