Skip to content

Commit 537dbc2

Browse files
committed
sanity check
1 parent 6a64375 commit 537dbc2

File tree

14 files changed

+508
-49
lines changed

14 files changed

+508
-49
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/AggregateMetricDoubleArrayBlock.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package org.elasticsearch.compute.data;
99

10+
import org.apache.lucene.util.RamUsageEstimator;
1011
import org.elasticsearch.common.io.stream.StreamInput;
1112
import org.elasticsearch.common.io.stream.StreamOutput;
1213
import org.elasticsearch.common.unit.ByteSizeValue;
@@ -24,6 +25,8 @@ public final class AggregateMetricDoubleArrayBlock extends AbstractNonThreadSafe
2425
private final IntBlock countBlock;
2526
private final int positionCount;
2627

28+
static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(AggregateMetricDoubleArrayBlock.class);
29+
2730
public AggregateMetricDoubleArrayBlock(DoubleBlock minBlock, DoubleBlock maxBlock, DoubleBlock sumBlock, IntBlock countBlock) {
2831
this.minBlock = minBlock;
2932
this.maxBlock = maxBlock;
@@ -242,7 +245,18 @@ public static Block readFrom(StreamInput in) throws IOException {
242245

243246
@Override
244247
public long ramBytesUsed() {
245-
return minBlock.ramBytesUsed() + maxBlock.ramBytesUsed() + sumBlock.ramBytesUsed() + countBlock.ramBytesUsed();
248+
// 40
249+
System.err.println("BASE RAM BYTES " + BASE_RAM_BYTES_USED);
250+
// 144 * 3
251+
System.err.println("BLOCK BYTES USED " + minBlock.ramBytesUsed());
252+
System.err.println("BLOCK BYTES USED " + maxBlock.ramBytesUsed());
253+
System.err.println("BLOCK BYTES USED " + sumBlock.ramBytesUsed());
254+
// 152 == 584 + 40 == 624
255+
System.err.println("BLOCK BYTES USED " + countBlock.ramBytesUsed());
256+
return
257+
// BASE_RAM_BYTES_USED +
258+
minBlock.ramBytesUsed() + maxBlock.ramBytesUsed() + sumBlock.ramBytesUsed() + countBlock
259+
.ramBytesUsed();
246260
}
247261

248262
@Override
@@ -289,4 +303,9 @@ public Block getMetricBlock(int index) {
289303
}
290304
throw new UnsupportedOperationException("Received an index (" + index + ") outside of range for AggregateMetricDoubleBlock.");
291305
}
306+
307+
@Override
308+
public String toString() {
309+
return "Min: " + minBlock + " \nMax: " + maxBlock + "\nSum: " + sumBlock + "\nCount: " + countBlock + "\n\n";
310+
}
292311
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/AggregateMetricDoubleBlockBuilder.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ protected int elementSize() {
5858
throw new UnsupportedOperationException("Not available on aggregate_metric_double");
5959
}
6060

61+
@Override
62+
public long estimatedBytes() {
63+
return minBuilder.estimatedBytes() + maxBuilder.estimatedBytes() + sumBuilder.estimatedBytes() + countBuilder.estimatedBytes();
64+
}
65+
6166
@Override
6267
public AggregateMetricDoubleBlockBuilder copyFrom(Block b, int beginInclusive, int endExclusive) {
6368
Block minBlock;
@@ -83,6 +88,36 @@ public AggregateMetricDoubleBlockBuilder copyFrom(Block b, int beginInclusive, i
8388
return this;
8489
}
8590

91+
public AggregateMetricDoubleBlockBuilder copyFrom(AggregateMetricDoubleBlock block, int position) {
92+
if (block.isNull(position)) {
93+
appendNull();
94+
return this;
95+
}
96+
// multivalue support?
97+
98+
if (block.minBlock().isNull(position)) {
99+
min().appendNull();
100+
} else {
101+
min().appendDouble(block.minBlock().getDouble(position));
102+
}
103+
if (block.maxBlock().isNull(position)) {
104+
max().appendNull();
105+
} else {
106+
max().appendDouble(block.maxBlock().getDouble(position));
107+
}
108+
if (block.sumBlock().isNull(position)) {
109+
sum().appendNull();
110+
} else {
111+
sum().appendDouble(block.sumBlock().getDouble(position));
112+
}
113+
if (block.countBlock().isNull(position)) {
114+
count().appendNull();
115+
} else {
116+
count().appendInt(block.countBlock().getInt(position));
117+
}
118+
return this;
119+
}
120+
86121
@Override
87122
public AggregateMetricDoubleBlockBuilder appendNull() {
88123
minBuilder.appendNull();

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/BlockFactory.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -441,30 +441,43 @@ public final AggregateMetricDoubleBlock newConstantAggregateMetricDoubleBlock(
441441
int positions
442442
) {
443443
try (AggregateMetricDoubleBlockBuilder builder = newAggregateMetricDoubleBlockBuilder(positions)) {
444-
if (value.min() != null) {
445-
builder.min().appendDouble(value.min());
446-
} else {
447-
builder.min().appendNull();
448-
}
449-
if (value.max() != null) {
450-
builder.max().appendDouble(value.max());
451-
} else {
452-
builder.max().appendNull();
453-
}
454-
if (value.sum() != null) {
455-
builder.sum().appendDouble(value.sum());
456-
} else {
457-
builder.sum().appendNull();
458-
}
459-
if (value.count() != null) {
460-
builder.count().appendInt(value.count());
461-
} else {
462-
builder.count().appendNull();
444+
for (int i = 0; i < positions; i++) {
445+
if (value.min() != null) {
446+
builder.min().appendDouble(value.min());
447+
} else {
448+
builder.min().appendNull();
449+
}
450+
if (value.max() != null) {
451+
builder.max().appendDouble(value.max());
452+
} else {
453+
builder.max().appendNull();
454+
}
455+
if (value.sum() != null) {
456+
builder.sum().appendDouble(value.sum());
457+
} else {
458+
builder.sum().appendNull();
459+
}
460+
if (value.count() != null) {
461+
builder.count().appendInt(value.count());
462+
} else {
463+
builder.count().appendNull();
464+
}
463465
}
464466
return builder.build();
465467
}
466468
}
467469

470+
public final AggregateMetricDoubleBlock newAggregateMetricDoubleBlock(
471+
double[] minValues, double[] maxValues, double[] sumValues, int[] countValues, int positions
472+
) {
473+
// currently only in tests, might need to add to equality tests...
474+
DoubleBlock min = newDoubleArrayVector(minValues, positions).asBlock();
475+
DoubleBlock max = newDoubleArrayVector(maxValues, positions).asBlock();
476+
DoubleBlock sum = newDoubleArrayVector(sumValues, positions).asBlock();
477+
IntBlock count = newIntArrayVector(countValues, positions).asBlock();
478+
return new AggregateMetricDoubleArrayBlock(min, max, sum, count);
479+
}
480+
468481
/**
469482
* Returns the maximum number of bytes that a Block should be backed by a primitive array before switching to using BigArrays.
470483
*/

0 commit comments

Comments
 (0)