Skip to content

Commit 1d222fa

Browse files
authored
Fixing delta function (elastic#135384)
* Fixing delta function * fixes for delta function
1 parent cadb7e9 commit 1d222fa

File tree

5 files changed

+20
-30
lines changed

5 files changed

+20
-30
lines changed

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/DeltaDoubleAggregator.java

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

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/DeltaFloatAggregator.java

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

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/DeltaIntAggregator.java

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

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/DeltaLongAggregator.java

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

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-DeltaAggregator.java.st

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.elasticsearch.compute.data.FloatBlock;
2323
import org.elasticsearch.compute.data.IntBlock;
2424
import org.elasticsearch.compute.data.IntVector;
2525
import org.elasticsearch.compute.data.LongBlock;
26+
import org.elasticsearch.compute.data.LongVector;
2627
import org.elasticsearch.compute.operator.DriverContext;
2728
import org.elasticsearch.core.Releasable;
2829
import org.elasticsearch.core.Releasables;
@@ -136,7 +137,6 @@ public class Delta$Type$Aggregator {
136137
ensureCapacity(groupId);
137138
append(groupId, timestamps.getLong(firstTs), values.get$Type$(firstIndex));
138139
if (valueCount > 1) {
139-
ensureCapacity(groupId);
140140
append(groupId, timestamps.getLong(firstTs + 1), values.get$Type$(firstIndex + 1));
141141
}
142142
// We are merging the state from upstream, which means we have seen
@@ -161,17 +161,15 @@ public class Delta$Type$Aggregator {
161161
final BlockFactory blockFactory = driverContext.blockFactory();
162162
final int positionCount = selected.getPositionCount();
163163
try (
164-
LongBlock.Builder samples = blockFactory.newLongBlockBuilder(positionCount);
164+
LongVector.FixedBuilder samples = blockFactory.newLongVectorFixedBuilder(positionCount);
165165
LongBlock.Builder timestamps = blockFactory.newLongBlockBuilder(positionCount * 2);
166166
$Type$Block.Builder values = blockFactory.new$Type$BlockBuilder(positionCount * 2);
167167
) {
168168
for (int i = 0; i < positionCount; i++) {
169169
final var groupId = selected.getInt(i);
170170
final var state = groupId < states.size() ? states.get(groupId) : null;
171171
if (state != null) {
172-
samples.beginPositionEntry();
173172
samples.appendLong(state.valuesSeen);
174-
samples.endPositionEntry();
175173
timestamps.beginPositionEntry();
176174
timestamps.appendLong(state.lastTimestamp);
177175
if (state.valuesSeen > 1) {
@@ -191,7 +189,7 @@ public class Delta$Type$Aggregator {
191189
values.appendNull();
192190
}
193191
}
194-
blocks[offset] = samples.build();
192+
blocks[offset] = samples.build().asBlock();
195193
blocks[offset + 1] = timestamps.build();
196194
blocks[offset + 2] = values.build();
197195
}
@@ -216,7 +214,7 @@ public class Delta$Type$Aggregator {
216214
continue;
217215
}
218216
double startGap = state.firstTimestamp - rangeStart;
219-
final double averageSampleInterval = (state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
217+
final double averageSampleInterval = ((double) state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
220218
final double slope = (state.lastValue - state.firstValue) / (state.lastTimestamp - state.firstTimestamp);
221219
double endGap = rangeEnd - state.lastTimestamp;
222220
double calculatedFirstValue = state.firstValue;

0 commit comments

Comments
 (0)