Skip to content

Commit 9b8fe64

Browse files
committed
Remove date_period as offset/scale and constant fold time durations during query planning
1 parent 5981802 commit 9b8fe64

File tree

10 files changed

+315
-490
lines changed

10 files changed

+315
-490
lines changed

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

Lines changed: 3 additions & 7 deletions
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: 9 additions & 177 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: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
import java.time.ZoneId;
2525
import java.time.ZonedDateTime;
26-
import java.time.temporal.ChronoUnit;
27-
import java.time.temporal.TemporalAmount;
2826

2927
import static com.carrotsearch.hppc.BitMixer.mix32;
3028

@@ -287,8 +285,4 @@ public double decayDateGauss(ZonedDateTime docValueDate) {
287285
}
288286
}
289287

290-
private static long temporalAmountToMillis(TemporalAmount temporalAmount) {
291-
return temporalAmount.get(ChronoUnit.SECONDS) * 1_000 + temporalAmount.get(ChronoUnit.NANOS) / 1_000_000;
292-
}
293-
294288
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ public static boolean isDateTime(DataType type) {
504504
return type == DATETIME;
505505
}
506506

507+
public static boolean isTimeDuration(DataType t) {
508+
return t == TIME_DURATION;
509+
}
510+
507511
public static boolean isNullOrTimeDuration(DataType t) {
508512
return t == TIME_DURATION || isNull(t);
509513
}
@@ -563,7 +567,15 @@ public static boolean isCounter(DataType t) {
563567
}
564568

565569
public static boolean isSpatialPoint(DataType t) {
566-
return t == GEO_POINT || t == CARTESIAN_POINT;
570+
return isGeoPoint(t) || isCartesianPoint(t);
571+
}
572+
573+
public static boolean isGeoPoint(DataType t) {
574+
return t == GEO_POINT;
575+
}
576+
577+
public static boolean isCartesianPoint(DataType t) {
578+
return t == CARTESIAN_POINT;
567579
}
568580

569581
public static boolean isSpatialShape(DataType t) {

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/EvalOperator.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,37 @@ public String toString() {
142142

143143
private static final String CONSTANT_DOUBLE_NAME = "ConstantDouble";
144144

145+
public static ExpressionEvaluator.Factory LongFactory(long value) {
146+
return new ExpressionEvaluator.Factory() {
147+
@Override
148+
public ExpressionEvaluator get(DriverContext driverContext) {
149+
return new ExpressionEvaluator() {
150+
@Override
151+
public Block eval(Page page) {
152+
return driverContext.blockFactory().newConstantLongBlockWith(value, page.getPositionCount());
153+
}
154+
155+
@Override
156+
public void close() {
157+
158+
}
159+
160+
@Override
161+
public String toString() {
162+
return CONSTANT_LONG_NAME + "[" + value + "]";
163+
}
164+
};
165+
}
166+
167+
@Override
168+
public String toString() {
169+
return CONSTANT_LONG_NAME + "[" + value + "]";
170+
}
171+
};
172+
}
173+
174+
private static final String CONSTANT_LONG_NAME = "ConstantLong";
175+
145176
public static ExpressionEvaluator.Factory BytesRefFactory(org.apache.lucene.util.BytesRef value) {
146177
return new ExpressionEvaluator.Factory() {
147178
@Override

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ decay_result:double
145145

146146
datetimeLinear1
147147

148-
ROW value = TO_DATETIME("2023-01-01T00:00:00Z"), origin = TO_DATETIME("2023-01-01T00:00:00Z"), scale = "24 hours"
149-
| EVAL decay_result = decay(value, origin, scale, "0 seconds", 0.5, "linear")
148+
ROW value = TO_DATETIME("2023-01-01T00:00:00Z"), origin = TO_DATETIME("2023-01-01T00:00:00Z")
149+
| EVAL decay_result = decay(value, origin, 24 hours, 0 seconds, 0.5, "linear")
150150
| KEEP decay_result;
151151

152152
decay_result:double
@@ -155,8 +155,8 @@ decay_result:double
155155

156156
datetimeLinear2
157157

158-
ROW value = TO_DATETIME("2023-01-01T12:00:00Z"), origin = TO_DATETIME("2023-01-01T00:00:00Z"), scale = "24 hours"
159-
| EVAL decay_result = decay(value, origin, scale, "0 seconds", 0.5, "linear")
158+
ROW value = TO_DATETIME("2023-01-01T12:00:00Z"), origin = TO_DATETIME("2023-01-01T00:00:00Z")
159+
| EVAL decay_result = decay(value, origin, 24 hours, 0 seconds, 0.5, "linear")
160160
| KEEP decay_result;
161161

162162
decay_result:double
@@ -165,8 +165,8 @@ decay_result:double
165165

166166
dateNanosLinear1
167167

168-
ROW value = TO_DATE_NANOS("2023-01-01T00:00:00Z"), origin = TO_DATE_NANOS("2023-01-01T00:00:00Z"), scale = "24 hours"
169-
| EVAL decay_result = decay(value, origin, scale, "0 seconds", 0.5, "linear")
168+
ROW value = TO_DATE_NANOS("2023-01-01T00:00:00Z"), origin = TO_DATE_NANOS("2023-01-01T00:00:00Z")
169+
| EVAL decay_result = decay(value, origin, 24 hours, 0 seconds, 0.5, "linear")
170170
| KEEP decay_result;
171171

172172
decay_result:double
@@ -175,8 +175,8 @@ decay_result:double
175175

176176
dateNanosLinear2
177177

178-
ROW value = TO_DATE_NANOS("2023-01-01T12:00:00Z"), origin = TO_DATE_NANOS("2023-01-01T00:00:00Z"), scale = "24 hours"
179-
| EVAL decay_result = decay(value, origin, scale, "0 seconds", 0.5, "linear")
178+
ROW value = TO_DATE_NANOS("2023-01-01T12:00:00Z"), origin = TO_DATE_NANOS("2023-01-01T00:00:00Z")
179+
| EVAL decay_result = decay(value, origin, 24 hours, 0 seconds, 0.5, "linear")
180180
| KEEP decay_result;
181181

182182
decay_result:double

0 commit comments

Comments
 (0)