Skip to content

Commit 1e7eda4

Browse files
committed
Merge remote-tracking branch 'origin/esql-decay-function' into esql-decay-function
2 parents 19e6c8f + 42890f6 commit 1e7eda4

File tree

2 files changed

+19
-17
lines changed
  • x-pack/plugin/esql/src
    • main/java/org/elasticsearch/xpack/esql/expression/function/fulltext
    • test/java/org/elasticsearch/xpack/esql/analysis

2 files changed

+19
-17
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Decay.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,34 @@ protected TypeResolution resolveType() {
177177

178178
// Spatial decay
179179
if (isSpatialPoint(valueDataType)) {
180-
TypeResolution originResolution = isNotNull(origin, sourceText(), SECOND).and(isType(origin, DataType::isSpatialPoint, sourceText(), SECOND, "spatial point"));
180+
TypeResolution originResolution = isNotNull(origin, sourceText(), SECOND).and(
181+
isType(origin, DataType::isSpatialPoint, sourceText(), SECOND, "spatial point")
182+
);
181183
if (originResolution.unresolved()) {
182184
return originResolution;
183185
}
184186

185187
// For a spatial decay the scale should be a distance unit string (e.g. "100km")
186-
TypeResolution scaleResolution = isNotNull(scale, sourceText(), THIRD).and(isType(scale, DataType::isString, sourceText(), THIRD, "keyword or text"));
188+
TypeResolution scaleResolution = isNotNull(scale, sourceText(), THIRD).and(
189+
isType(scale, DataType::isString, sourceText(), THIRD, "keyword or text")
190+
);
187191
if (scaleResolution.unresolved()) {
188192
return scaleResolution;
189193
}
190194
}
191195
// Temporal decay
192196
else if (isMillisOrNanos(valueDataType)) {
193-
TypeResolution originResolution = isNotNull(origin, sourceText(), SECOND).and(isType(origin, DataType::isMillisOrNanos, sourceText(), SECOND, "datetime or date_nanos"));
197+
TypeResolution originResolution = isNotNull(origin, sourceText(), SECOND).and(
198+
isType(origin, DataType::isMillisOrNanos, sourceText(), SECOND, "datetime or date_nanos")
199+
);
194200
if (originResolution.unresolved()) {
195201
return originResolution;
196202
}
197203

198204
// For a temporal decay the scale should be a time value string (e.g. "5h")
199-
TypeResolution scaleResolution = isNotNull(scale, sourceText(), THIRD).and(isType(scale, DataType::isString, sourceText(), THIRD, "date_period or time_duration"));
205+
TypeResolution scaleResolution = isNotNull(scale, sourceText(), THIRD).and(
206+
isType(scale, DataType::isString, sourceText(), THIRD, "date_period or time_duration")
207+
);
200208
if (scaleResolution.unresolved()) {
201209
return scaleResolution;
202210
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,41 +2346,35 @@ public void testRemoteLookupJoinIsDisabled() {
23462346

23472347
}
23482348

2349-
public void testDecayFunctionNullArgs(){
2349+
public void testDecayFunctionNullArgs() {
23502350
assumeTrue("Decay function not enabled", EsqlCapabilities.Cap.DECAY_FUNCTION.isEnabled());
23512351

23522352
// First arg cannot be null
23532353
assertEquals(
23542354
"2:23: first argument of [decay(null, origin, scale, 0, 0.5, \"linear\")] cannot be null, received [null]",
2355-
error("row origin = 10, scale = 10\n"
2356-
+ "| eval decay_result = decay(null, origin, scale, 0, 0.5, \"linear\")")
2355+
error("row origin = 10, scale = 10\n" + "| eval decay_result = decay(null, origin, scale, 0, 0.5, \"linear\")")
23572356
);
23582357

23592358
// Second arg cannot be null
23602359
assertEquals(
23612360
"2:23: second argument of [decay(value, null, scale, 0, 0.5, \"linear\")] cannot be null, received [null]",
2362-
error("row value = 10, scale = 10\n"
2363-
+ "| eval decay_result = decay(value, null, scale, 0, 0.5, \"linear\")")
2361+
error("row value = 10, scale = 10\n" + "| eval decay_result = decay(value, null, scale, 0, 0.5, \"linear\")")
23642362
);
23652363

23662364
// Third arg cannot be null
23672365
assertEquals(
23682366
"2:23: third argument of [decay(value, origin, null, 0, 0.5, \"linear\")] cannot be null, received [null]",
2369-
error("row value = 10, origin = 10\n"
2370-
+ "| eval decay_result = decay(value, origin, null, 0, 0.5, \"linear\")")
2367+
error("row value = 10, origin = 10\n" + "| eval decay_result = decay(value, origin, null, 0, 0.5, \"linear\")")
23712368
);
23722369

23732370
// Fourth arg can be null
2374-
query("row value = 10, origin = 10, scale = 10\n"
2375-
+ "| eval decay_result = decay(value, origin, scale, null, 0.5, \"linear\")");
2371+
query("row value = 10, origin = 10, scale = 10\n" + "| eval decay_result = decay(value, origin, scale, null, 0.5, \"linear\")");
23762372

23772373
// Fifth arg can be null
2378-
query("row value = 10, origin = 10, scale = 10\n"
2379-
+ "| eval decay_result = decay(value, origin, scale, 0, null, \"linear\")");
2374+
query("row value = 10, origin = 10, scale = 10\n" + "| eval decay_result = decay(value, origin, scale, 0, null, \"linear\")");
23802375

23812376
// Sixth arg can be null
2382-
query("row value = 10, origin = 10, scale = 10\n"
2383-
+ "| eval decay_result = decay(value, origin, scale, 0, 0.5, null)");
2377+
query("row value = 10, origin = 10, scale = 10\n" + "| eval decay_result = decay(value, origin, scale, 0, 0.5, null)");
23842378
}
23852379

23862380
private void checkFullTextFunctionsInStats(String functionInvocation) {

0 commit comments

Comments
 (0)