Forráskód Böngészése

Fixing delta function (#135384)

* Fixing delta function

* fixes for delta function
P 2 hete
szülő
commit
1d222fa809

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

@@ -23,6 +23,7 @@ import org.elasticsearch.compute.data.FloatBlock;
 import org.elasticsearch.compute.data.IntBlock;
 import org.elasticsearch.compute.data.IntVector;
 import org.elasticsearch.compute.data.LongBlock;
+import org.elasticsearch.compute.data.LongVector;
 import org.elasticsearch.compute.operator.DriverContext;
 import org.elasticsearch.core.Releasable;
 import org.elasticsearch.core.Releasables;
@@ -136,7 +137,6 @@ public class DeltaDoubleAggregator {
             ensureCapacity(groupId);
             append(groupId, timestamps.getLong(firstTs), values.getDouble(firstIndex));
             if (valueCount > 1) {
-                ensureCapacity(groupId);
                 append(groupId, timestamps.getLong(firstTs + 1), values.getDouble(firstIndex + 1));
             }
             // We are merging the state from upstream, which means we have seen
@@ -161,7 +161,7 @@ public class DeltaDoubleAggregator {
             final BlockFactory blockFactory = driverContext.blockFactory();
             final int positionCount = selected.getPositionCount();
             try (
-                LongBlock.Builder samples = blockFactory.newLongBlockBuilder(positionCount);
+                LongVector.FixedBuilder samples = blockFactory.newLongVectorFixedBuilder(positionCount);
                 LongBlock.Builder timestamps = blockFactory.newLongBlockBuilder(positionCount * 2);
                 DoubleBlock.Builder values = blockFactory.newDoubleBlockBuilder(positionCount * 2);
             ) {
@@ -169,9 +169,7 @@ public class DeltaDoubleAggregator {
                     final var groupId = selected.getInt(i);
                     final var state = groupId < states.size() ? states.get(groupId) : null;
                     if (state != null) {
-                        samples.beginPositionEntry();
                         samples.appendLong(state.valuesSeen);
-                        samples.endPositionEntry();
                         timestamps.beginPositionEntry();
                         timestamps.appendLong(state.lastTimestamp);
                         if (state.valuesSeen > 1) {
@@ -191,7 +189,7 @@ public class DeltaDoubleAggregator {
                         values.appendNull();
                     }
                 }
-                blocks[offset] = samples.build();
+                blocks[offset] = samples.build().asBlock();
                 blocks[offset + 1] = timestamps.build();
                 blocks[offset + 2] = values.build();
             }
@@ -216,7 +214,7 @@ public class DeltaDoubleAggregator {
                             continue;
                         }
                         double startGap = state.firstTimestamp - rangeStart;
-                        final double averageSampleInterval = (state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
+                        final double averageSampleInterval = ((double) state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
                         final double slope = (state.lastValue - state.firstValue) / (state.lastTimestamp - state.firstTimestamp);
                         double endGap = rangeEnd - state.lastTimestamp;
                         double calculatedFirstValue = state.firstValue;

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

@@ -23,6 +23,7 @@ import org.elasticsearch.compute.data.FloatBlock;
 import org.elasticsearch.compute.data.IntBlock;
 import org.elasticsearch.compute.data.IntVector;
 import org.elasticsearch.compute.data.LongBlock;
+import org.elasticsearch.compute.data.LongVector;
 import org.elasticsearch.compute.operator.DriverContext;
 import org.elasticsearch.core.Releasable;
 import org.elasticsearch.core.Releasables;
@@ -136,7 +137,6 @@ public class DeltaFloatAggregator {
             ensureCapacity(groupId);
             append(groupId, timestamps.getLong(firstTs), values.getFloat(firstIndex));
             if (valueCount > 1) {
-                ensureCapacity(groupId);
                 append(groupId, timestamps.getLong(firstTs + 1), values.getFloat(firstIndex + 1));
             }
             // We are merging the state from upstream, which means we have seen
@@ -161,7 +161,7 @@ public class DeltaFloatAggregator {
             final BlockFactory blockFactory = driverContext.blockFactory();
             final int positionCount = selected.getPositionCount();
             try (
-                LongBlock.Builder samples = blockFactory.newLongBlockBuilder(positionCount);
+                LongVector.FixedBuilder samples = blockFactory.newLongVectorFixedBuilder(positionCount);
                 LongBlock.Builder timestamps = blockFactory.newLongBlockBuilder(positionCount * 2);
                 FloatBlock.Builder values = blockFactory.newFloatBlockBuilder(positionCount * 2);
             ) {
@@ -169,9 +169,7 @@ public class DeltaFloatAggregator {
                     final var groupId = selected.getInt(i);
                     final var state = groupId < states.size() ? states.get(groupId) : null;
                     if (state != null) {
-                        samples.beginPositionEntry();
                         samples.appendLong(state.valuesSeen);
-                        samples.endPositionEntry();
                         timestamps.beginPositionEntry();
                         timestamps.appendLong(state.lastTimestamp);
                         if (state.valuesSeen > 1) {
@@ -191,7 +189,7 @@ public class DeltaFloatAggregator {
                         values.appendNull();
                     }
                 }
-                blocks[offset] = samples.build();
+                blocks[offset] = samples.build().asBlock();
                 blocks[offset + 1] = timestamps.build();
                 blocks[offset + 2] = values.build();
             }
@@ -216,7 +214,7 @@ public class DeltaFloatAggregator {
                             continue;
                         }
                         double startGap = state.firstTimestamp - rangeStart;
-                        final double averageSampleInterval = (state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
+                        final double averageSampleInterval = ((double) state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
                         final double slope = (state.lastValue - state.firstValue) / (state.lastTimestamp - state.firstTimestamp);
                         double endGap = rangeEnd - state.lastTimestamp;
                         double calculatedFirstValue = state.firstValue;

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

@@ -23,6 +23,7 @@ import org.elasticsearch.compute.data.FloatBlock;
 import org.elasticsearch.compute.data.IntBlock;
 import org.elasticsearch.compute.data.IntVector;
 import org.elasticsearch.compute.data.LongBlock;
+import org.elasticsearch.compute.data.LongVector;
 import org.elasticsearch.compute.operator.DriverContext;
 import org.elasticsearch.core.Releasable;
 import org.elasticsearch.core.Releasables;
@@ -136,7 +137,6 @@ public class DeltaIntAggregator {
             ensureCapacity(groupId);
             append(groupId, timestamps.getLong(firstTs), values.getInt(firstIndex));
             if (valueCount > 1) {
-                ensureCapacity(groupId);
                 append(groupId, timestamps.getLong(firstTs + 1), values.getInt(firstIndex + 1));
             }
             // We are merging the state from upstream, which means we have seen
@@ -161,7 +161,7 @@ public class DeltaIntAggregator {
             final BlockFactory blockFactory = driverContext.blockFactory();
             final int positionCount = selected.getPositionCount();
             try (
-                LongBlock.Builder samples = blockFactory.newLongBlockBuilder(positionCount);
+                LongVector.FixedBuilder samples = blockFactory.newLongVectorFixedBuilder(positionCount);
                 LongBlock.Builder timestamps = blockFactory.newLongBlockBuilder(positionCount * 2);
                 IntBlock.Builder values = blockFactory.newIntBlockBuilder(positionCount * 2);
             ) {
@@ -169,9 +169,7 @@ public class DeltaIntAggregator {
                     final var groupId = selected.getInt(i);
                     final var state = groupId < states.size() ? states.get(groupId) : null;
                     if (state != null) {
-                        samples.beginPositionEntry();
                         samples.appendLong(state.valuesSeen);
-                        samples.endPositionEntry();
                         timestamps.beginPositionEntry();
                         timestamps.appendLong(state.lastTimestamp);
                         if (state.valuesSeen > 1) {
@@ -191,7 +189,7 @@ public class DeltaIntAggregator {
                         values.appendNull();
                     }
                 }
-                blocks[offset] = samples.build();
+                blocks[offset] = samples.build().asBlock();
                 blocks[offset + 1] = timestamps.build();
                 blocks[offset + 2] = values.build();
             }
@@ -216,7 +214,7 @@ public class DeltaIntAggregator {
                             continue;
                         }
                         double startGap = state.firstTimestamp - rangeStart;
-                        final double averageSampleInterval = (state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
+                        final double averageSampleInterval = ((double) state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
                         final double slope = (state.lastValue - state.firstValue) / (state.lastTimestamp - state.firstTimestamp);
                         double endGap = rangeEnd - state.lastTimestamp;
                         double calculatedFirstValue = state.firstValue;

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

@@ -23,6 +23,7 @@ import org.elasticsearch.compute.data.FloatBlock;
 import org.elasticsearch.compute.data.IntBlock;
 import org.elasticsearch.compute.data.IntVector;
 import org.elasticsearch.compute.data.LongBlock;
+import org.elasticsearch.compute.data.LongVector;
 import org.elasticsearch.compute.operator.DriverContext;
 import org.elasticsearch.core.Releasable;
 import org.elasticsearch.core.Releasables;
@@ -136,7 +137,6 @@ public class DeltaLongAggregator {
             ensureCapacity(groupId);
             append(groupId, timestamps.getLong(firstTs), values.getLong(firstIndex));
             if (valueCount > 1) {
-                ensureCapacity(groupId);
                 append(groupId, timestamps.getLong(firstTs + 1), values.getLong(firstIndex + 1));
             }
             // We are merging the state from upstream, which means we have seen
@@ -161,7 +161,7 @@ public class DeltaLongAggregator {
             final BlockFactory blockFactory = driverContext.blockFactory();
             final int positionCount = selected.getPositionCount();
             try (
-                LongBlock.Builder samples = blockFactory.newLongBlockBuilder(positionCount);
+                LongVector.FixedBuilder samples = blockFactory.newLongVectorFixedBuilder(positionCount);
                 LongBlock.Builder timestamps = blockFactory.newLongBlockBuilder(positionCount * 2);
                 LongBlock.Builder values = blockFactory.newLongBlockBuilder(positionCount * 2);
             ) {
@@ -169,9 +169,7 @@ public class DeltaLongAggregator {
                     final var groupId = selected.getInt(i);
                     final var state = groupId < states.size() ? states.get(groupId) : null;
                     if (state != null) {
-                        samples.beginPositionEntry();
                         samples.appendLong(state.valuesSeen);
-                        samples.endPositionEntry();
                         timestamps.beginPositionEntry();
                         timestamps.appendLong(state.lastTimestamp);
                         if (state.valuesSeen > 1) {
@@ -191,7 +189,7 @@ public class DeltaLongAggregator {
                         values.appendNull();
                     }
                 }
-                blocks[offset] = samples.build();
+                blocks[offset] = samples.build().asBlock();
                 blocks[offset + 1] = timestamps.build();
                 blocks[offset + 2] = values.build();
             }
@@ -216,7 +214,7 @@ public class DeltaLongAggregator {
                             continue;
                         }
                         double startGap = state.firstTimestamp - rangeStart;
-                        final double averageSampleInterval = (state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
+                        final double averageSampleInterval = ((double) state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
                         final double slope = (state.lastValue - state.firstValue) / (state.lastTimestamp - state.firstTimestamp);
                         double endGap = rangeEnd - state.lastTimestamp;
                         double calculatedFirstValue = state.firstValue;

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

@@ -23,6 +23,7 @@ import org.elasticsearch.compute.data.FloatBlock;
 import org.elasticsearch.compute.data.IntBlock;
 import org.elasticsearch.compute.data.IntVector;
 import org.elasticsearch.compute.data.LongBlock;
+import org.elasticsearch.compute.data.LongVector;
 import org.elasticsearch.compute.operator.DriverContext;
 import org.elasticsearch.core.Releasable;
 import org.elasticsearch.core.Releasables;
@@ -136,7 +137,6 @@ public class Delta$Type$Aggregator {
             ensureCapacity(groupId);
             append(groupId, timestamps.getLong(firstTs), values.get$Type$(firstIndex));
             if (valueCount > 1) {
-                ensureCapacity(groupId);
                 append(groupId, timestamps.getLong(firstTs + 1), values.get$Type$(firstIndex + 1));
             }
             // We are merging the state from upstream, which means we have seen
@@ -161,7 +161,7 @@ public class Delta$Type$Aggregator {
             final BlockFactory blockFactory = driverContext.blockFactory();
             final int positionCount = selected.getPositionCount();
             try (
-                LongBlock.Builder samples = blockFactory.newLongBlockBuilder(positionCount);
+                LongVector.FixedBuilder samples = blockFactory.newLongVectorFixedBuilder(positionCount);
                 LongBlock.Builder timestamps = blockFactory.newLongBlockBuilder(positionCount * 2);
                 $Type$Block.Builder values = blockFactory.new$Type$BlockBuilder(positionCount * 2);
             ) {
@@ -169,9 +169,7 @@ public class Delta$Type$Aggregator {
                     final var groupId = selected.getInt(i);
                     final var state = groupId < states.size() ? states.get(groupId) : null;
                     if (state != null) {
-                        samples.beginPositionEntry();
                         samples.appendLong(state.valuesSeen);
-                        samples.endPositionEntry();
                         timestamps.beginPositionEntry();
                         timestamps.appendLong(state.lastTimestamp);
                         if (state.valuesSeen > 1) {
@@ -191,7 +189,7 @@ public class Delta$Type$Aggregator {
                         values.appendNull();
                     }
                 }
-                blocks[offset] = samples.build();
+                blocks[offset] = samples.build().asBlock();
                 blocks[offset + 1] = timestamps.build();
                 blocks[offset + 2] = values.build();
             }
@@ -216,7 +214,7 @@ public class Delta$Type$Aggregator {
                             continue;
                         }
                         double startGap = state.firstTimestamp - rangeStart;
-                        final double averageSampleInterval = (state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
+                        final double averageSampleInterval = ((double) state.lastTimestamp - state.firstTimestamp) / state.valuesSeen;
                         final double slope = (state.lastValue - state.firstValue) / (state.lastTimestamp - state.firstTimestamp);
                         double endGap = rangeEnd - state.lastTimestamp;
                         double calculatedFirstValue = state.firstValue;