-
Notifications
You must be signed in to change notification settings - Fork 24.3k
/
Min.java
53 lines (44 loc) · 1.6 KB
/
Min.java
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 Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.Expressions;
import org.elasticsearch.xpack.sql.expression.Expressions.ParamOrdinal;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import java.util.List;
/**
* Find the minimum value in matched documents.
*/
public class Min extends NumericAggregate implements EnclosedAgg {
public Min(Location location, Expression field) {
super(location, field);
}
@Override
protected NodeInfo<Min> info() {
return NodeInfo.create(this, Min::new, field());
}
@Override
public Min replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Min(location(), newChildren.get(0));
}
@Override
public DataType dataType() {
return field().dataType();
}
@Override
public String innerName() {
return "min";
}
@Override
protected TypeResolution resolveType() {
return Expressions.typeMustBeNumericOrDate(field(), functionName(), ParamOrdinal.DEFAULT);
}
}