Skip to content

Commit 10d640d

Browse files
committed
fixup - comments
1 parent 36e8b0a commit 10d640d

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/k8s-timeseries-clamp.csv-spec

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,26 @@ bytes_in:long | clamped_network_bytes_in:long | time_bucket:datetime
7575
3850 | 1468 | 2024-05-10T00:09:00.000Z
7676

7777
;
78+
79+
clamp_without_stats_command
80+
required_capability: clamp_functions
81+
// tag::clamp[]
82+
TS k8s
83+
| EVAL full_clamped_cost = clamp(network.cost, 1, 20)
84+
| KEEP full_clamped_cost, @timestamp
85+
// end::clamp-max[]
86+
| SORT full_clamped_cost DESC, @timestamp | LIMIT 10;
87+
88+
// tag::clamp-max-result[]
89+
full_clamped_cost:double | @timestamp:datetime
90+
12.5 | 2024-05-10T00:09:52.000Z
91+
12.375 | 2024-05-10T00:01:29.000Z
92+
12.375 | 2024-05-10T00:06:42.000Z
93+
12.375 | 2024-05-10T00:17:12.000Z
94+
12.25 | 2024-05-10T00:19:48.000Z
95+
12.125 | 2024-05-10T00:00:57.000Z
96+
12.125 | 2024-05-10T00:03:26.000Z
97+
12.125 | 2024-05-10T00:07:19.000Z
98+
12.125 | 2024-05-10T00:17:39.000Z
99+
12.0 | 2024-05-10T00:08:08.000Z
100+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/Clamp.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
package org.elasticsearch.xpack.esql.expression.function.scalar;
99

10-
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
11-
import org.elasticsearch.common.io.stream.StreamInput;
1210
import org.elasticsearch.common.io.stream.StreamOutput;
1311
import org.elasticsearch.compute.operator.EvalOperator.ExpressionEvaluator;
1412
import org.elasticsearch.xpack.esql.core.expression.Expression;
@@ -22,7 +20,6 @@
2220
import org.elasticsearch.xpack.esql.expression.function.Param;
2321
import org.elasticsearch.xpack.esql.expression.function.scalar.conditional.ClampMax;
2422
import org.elasticsearch.xpack.esql.expression.function.scalar.conditional.ClampMin;
25-
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
2623

2724
import java.io.IOException;
2825
import java.util.List;
@@ -33,7 +30,6 @@
3330
* Clamps the values of all samples to have a lower limit of min and an upper limit of max.
3431
*/
3532
public class Clamp extends EsqlScalarFunction implements SurrogateExpression {
36-
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Clamp", Clamp::new);
3733

3834
private final Expression field;
3935
private final Expression min;
@@ -68,18 +64,9 @@ public Clamp(
6864
this.max = max;
6965
}
7066

71-
private Clamp(StreamInput in) throws IOException {
72-
this(
73-
Source.readFrom((PlanStreamInput) in),
74-
in.readNamedWriteable(Expression.class),
75-
in.readNamedWriteable(Expression.class),
76-
in.readNamedWriteable(Expression.class)
77-
);
78-
}
79-
8067
@Override
8168
public String getWriteableName() {
82-
return ENTRY.name;
69+
throw new UnsupportedOperationException("Clamp does not support serialization (as it should be replaced by ClampMin and ClampMax)");
8370
}
8471

8572
@Override
@@ -135,15 +122,14 @@ protected NodeInfo<? extends Expression> info() {
135122

136123
@Override
137124
public void writeTo(StreamOutput out) throws IOException {
138-
source().writeTo(out);
139-
out.writeNamedWriteable(field);
140-
out.writeNamedWriteable(min);
141-
out.writeNamedWriteable(max);
125+
throw new UnsupportedOperationException("Clamp does not support serialization (as it should be replaced by ClampMin and ClampMax)");
142126
}
143127

144128
@Override
145129
public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
146-
return null;
130+
throw new UnsupportedOperationException(
131+
"Clamp should have been replaced by ClampMin and ClampMax. Something went wrong in the ESQL engine."
132+
);
147133
}
148134

149135
@Override

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/ScalarFunctionWritables.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
9292
entries.add(MonthName.ENTRY);
9393
entries.add(IpPrefix.ENTRY);
9494
entries.add(Least.ENTRY);
95-
entries.add(Clamp.ENTRY);
9695
entries.add(ClampMax.ENTRY);
9796
entries.add(ClampMin.ENTRY);
9897
entries.add(Left.ENTRY);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/ClampMax.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import static org.elasticsearch.xpack.esql.core.type.DataType.NULL;
3535

3636
/**
37-
* Returns the input values clamped to have an upper limit of max.
37+
* Clamps the input values to have an upper limit of max.
3838
*/
3939
public class ClampMax extends EsqlScalarFunction {
4040
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "ClampMax", ClampMax::new);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/ClampMin.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@
3434
import static org.elasticsearch.xpack.esql.core.type.DataType.NULL;
3535

3636
/**
37-
* Returns the input values clamped to have a lower limit of min.
37+
* Clamps input values to have a lower limit of min.
3838
*/
3939
public class ClampMin extends EsqlScalarFunction {
4040
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "ClampMin", ClampMin::new);
4141

42-
private DataType dataType;
43-
4442
@FunctionInfo(
4543
returnType = { "double", "integer", "long", "double", "unsigned_long", "keyword", "ip", "boolean", "date", "version" },
4644
description = "Returns clamps the values of all input samples clamped to have a lower limit of min.",
@@ -80,10 +78,7 @@ public String getWriteableName() {
8078

8179
@Override
8280
public DataType dataType() {
83-
if (dataType == null) {
84-
resolveType();
85-
}
86-
return dataType;
81+
return children().getFirst().dataType();
8782
}
8883

8984
@Override
@@ -103,11 +98,9 @@ protected TypeResolution resolveType() {
10398
fieldDataType.typeName()
10499
);
105100
if (resolution.unresolved()) {
106-
dataType = NULL;
107101
return resolution;
108102
}
109103
if (fieldDataType == NULL) {
110-
dataType = NULL;
111104
return new TypeResolution("'field' must not be null in clamp()");
112105
}
113106
resolution = TypeResolutions.isType(
@@ -118,10 +111,8 @@ protected TypeResolution resolveType() {
118111
fieldDataType.typeName()
119112
);
120113
if (resolution.unresolved()) {
121-
dataType = NULL;
122114
return resolution;
123115
}
124-
dataType = fieldDataType;
125116
return TypeResolution.TYPE_RESOLVED;
126117
}
127118

0 commit comments

Comments
 (0)