Skip to content

Commit 5981802

Browse files
committed
Adjust cartesian point scale and offset types to be numeric instead of distance unit strings
1 parent 1e7eda4 commit 5981802

File tree

7 files changed

+86
-153
lines changed

7 files changed

+86
-153
lines changed

docs/reference/query-languages/esql/_snippets/functions/types/decay.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/decay.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/main/java/org/elasticsearch/script/ScoreScriptUtils.java

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ public static final class DecayGeoLinear {
9797
double scaling;
9898

9999
public DecayGeoLinear(String originStr, String scaleStr, String offsetStr, double decay) {
100-
this(GeoUtils.parseGeoPoint(originStr, false), scaleStr, offsetStr, decay);
101-
}
102-
103-
public DecayGeoLinear(GeoPoint origin, String scaleStr, String offsetStr, double decay) {
100+
GeoPoint origin = GeoUtils.parseGeoPoint(originStr, false);
104101
double scale = DistanceUnit.DEFAULT.parse(scaleStr, DistanceUnit.DEFAULT);
105102
this.originLat = origin.lat();
106103
this.originLon = origin.lon();
@@ -122,10 +119,7 @@ public static final class DecayGeoExp {
122119
double scaling;
123120

124121
public DecayGeoExp(String originStr, String scaleStr, String offsetStr, double decay) {
125-
this(GeoUtils.parseGeoPoint(originStr, false), scaleStr, offsetStr, decay);
126-
}
127-
128-
public DecayGeoExp(GeoPoint origin, String scaleStr, String offsetStr, double decay) {
122+
GeoPoint origin = GeoUtils.parseGeoPoint(originStr, false);
129123
double scale = DistanceUnit.DEFAULT.parse(scaleStr, DistanceUnit.DEFAULT);
130124
this.originLat = origin.lat();
131125
this.originLon = origin.lon();
@@ -147,10 +141,7 @@ public static final class DecayGeoGauss {
147141
double scaling;
148142

149143
public DecayGeoGauss(String originStr, String scaleStr, String offsetStr, double decay) {
150-
this(GeoUtils.parseGeoPoint(originStr, false), scaleStr, offsetStr, decay);
151-
}
152-
153-
public DecayGeoGauss(GeoPoint origin, String scaleStr, String offsetStr, double decay) {
144+
GeoPoint origin = GeoUtils.parseGeoPoint(originStr, false);
154145
double scale = DistanceUnit.DEFAULT.parse(scaleStr, DistanceUnit.DEFAULT);
155146
this.originLat = origin.lat();
156147
this.originLon = origin.lon();
@@ -243,13 +234,6 @@ public DecayDateLinear(String originStr, String scaleStr, String offsetStr, doub
243234
this.scaling = scale / (1.0 - decay);
244235
}
245236

246-
public DecayDateLinear(long origin, TemporalAmount scale, TemporalAmount offset, double decay) {
247-
this.origin = origin;
248-
long scaleMillis = temporalAmountToMillis(scale);
249-
this.offset = temporalAmountToMillis(offset);
250-
this.scaling = scaleMillis / (1.0 - decay);
251-
}
252-
253237
public double decayDateLinear(ZonedDateTime docValueDate) {
254238
long docValue = docValueDate.toInstant().toEpochMilli();
255239
// as java.lang.Math#abs(long) is a forbidden API, have to use this comparison instead
@@ -273,13 +257,6 @@ public DecayDateExp(String originStr, String scaleStr, String offsetStr, double
273257
this.scaling = Math.log(decay) / scale;
274258
}
275259

276-
public DecayDateExp(long origin, TemporalAmount scale, TemporalAmount offset, double decay) {
277-
this.origin = origin;
278-
long scaleMillis = temporalAmountToMillis(scale);
279-
this.offset = temporalAmountToMillis(offset);
280-
this.scaling = Math.log(decay) / scaleMillis;
281-
}
282-
283260
public double decayDateExp(ZonedDateTime docValueDate) {
284261
long docValue = docValueDate.toInstant().toEpochMilli();
285262
long diff = (docValue >= origin) ? (docValue - origin) : (origin - docValue);
@@ -302,13 +279,6 @@ public DecayDateGauss(String originStr, String scaleStr, String offsetStr, doubl
302279
this.scaling = 0.5 * Math.pow(scale, 2.0) / Math.log(decay);
303280
}
304281

305-
public DecayDateGauss(long origin, TemporalAmount scale, TemporalAmount offset, double decay) {
306-
this.origin = origin;
307-
long scaleMillis = temporalAmountToMillis(scale);
308-
this.offset = temporalAmountToMillis(offset);
309-
this.scaling = 0.5 * Math.pow(scaleMillis, 2.0) / Math.log(decay);
310-
}
311-
312282
public double decayDateGauss(ZonedDateTime docValueDate) {
313283
long docValue = docValueDate.toInstant().toEpochMilli();
314284
long diff = (docValue >= origin) ? (docValue - origin) : (origin - docValue);

x-pack/plugin/esql/qa/testFixtures/src/main/resources/decay.csv-spec

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ decay_result:double
104104

105105
cartesianPointLinear1
106106

107-
ROW value = TO_CARTESIANPOINT("POINT(5 5)"), origin = TO_CARTESIANPOINT("POINT(0 0)"), scale = "10m"
108-
| EVAL decay_result = decay(value, origin, scale, "0m", 0.25, "linear")
107+
ROW value = TO_CARTESIANPOINT("POINT(5 5)"), origin = TO_CARTESIANPOINT("POINT(0 0)"), scale = 10.0
108+
| EVAL decay_result = decay(value, origin, scale, 0.0, 0.25, "linear")
109109
| KEEP decay_result;
110110

111111
decay_result:double
@@ -114,8 +114,8 @@ decay_result:double
114114

115115
cartesianPointLinear2
116116

117-
ROW value = TO_CARTESIANPOINT("POINT(10 0)"), origin = TO_CARTESIANPOINT("POINT(0 0)"), scale = "10m"
118-
| EVAL decay_result = ROUND(decay(value, origin, scale, "0m", 0.25, "linear"), 10)
117+
ROW value = TO_CARTESIANPOINT("POINT(10 0)"), origin = TO_CARTESIANPOINT("POINT(0 0)"), scale = 10.0
118+
| EVAL decay_result = ROUND(decay(value, origin, scale, 0.0, 0.25, "linear"), 10)
119119
| KEEP decay_result;
120120

121121
decay_result:double
@@ -124,8 +124,8 @@ decay_result:double
124124

125125
cartesianPointLinearWithOffset
126126

127-
ROW value = TO_CARTESIANPOINT("POINT(10 0)"), origin = TO_CARTESIANPOINT("POINT(0 0)"), scale = "10m"
128-
| EVAL decay_result = ROUND(decay(value, origin, scale, "5m", 0.25, "linear"), 10)
127+
ROW value = TO_CARTESIANPOINT("POINT(10 0)"), origin = TO_CARTESIANPOINT("POINT(0 0)"), scale = 10.0
128+
| EVAL decay_result = ROUND(decay(value, origin, scale, 5.0, 0.25, "linear"), 10)
129129
| KEEP decay_result;
130130

131131
decay_result:double

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

Lines changed: 8 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)