Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected int elementSize() {
}

@Override
public Block.Builder copyFrom(Block b, int beginInclusive, int endExclusive) {
public AggregateMetricDoubleBlockBuilder copyFrom(Block b, int beginInclusive, int endExclusive) {
Block minBlock;
Block maxBlock;
Block sumBlock;
Expand All @@ -84,7 +84,7 @@ public Block.Builder copyFrom(Block b, int beginInclusive, int endExclusive) {
}

@Override
public AbstractBlockBuilder appendNull() {
public AggregateMetricDoubleBlockBuilder appendNull() {
minBuilder.appendNull();
maxBuilder.appendNull();
sumBuilder.appendNull();
Expand All @@ -93,7 +93,7 @@ public AbstractBlockBuilder appendNull() {
}

@Override
public Block.Builder mvOrdering(Block.MvOrdering mvOrdering) {
public AggregateMetricDoubleBlockBuilder mvOrdering(Block.MvOrdering mvOrdering) {
minBuilder.mvOrdering(mvOrdering);
maxBuilder.mvOrdering(mvOrdering);
sumBuilder.mvOrdering(mvOrdering);
Expand All @@ -102,7 +102,7 @@ public Block.Builder mvOrdering(Block.MvOrdering mvOrdering) {
}

@Override
public Block build() {
public AggregateMetricDoubleBlock build() {
DoubleBlock minBlock = null;
DoubleBlock maxBlock = null;
DoubleBlock sumBlock = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public AggregateMetricDoubleBlockBuilder newAggregateMetricDoubleBlockBuilder(in
return new AggregateMetricDoubleBlockBuilder(estimatedSize, this);
}

public final Block newConstantAggregateMetricDoubleBlock(
public final AggregateMetricDoubleBlock newConstantAggregateMetricDoubleBlock(
AggregateMetricDoubleBlockBuilder.AggregateMetricDoubleLiteral value,
int positions
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.compute.data;

import org.elasticsearch.compute.test.ComputeTestCase;
import org.elasticsearch.compute.test.TestBlockFactory;
import org.elasticsearch.core.Releasables;

import java.util.List;

public class AggregateMetricDoubleBlockEqualityTests extends ComputeTestCase {

static final BlockFactory blockFactory = TestBlockFactory.getNonBreakingInstance();

// TODO: Add additional tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am making a list of tests where AggregateMetricDoubleBlock is missing and making a github issue out of it and it is the first thing I will work on after I get this PR and the initial CSV tests PR merged in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test issue: #131951


public void testEmptyBlock() {
// all these "empty" vectors should be equivalent
var partialMetricBuilder = blockFactory.newAggregateMetricDoubleBlockBuilder(0);
for (var subBuilder : List.of(
partialMetricBuilder.min(),
partialMetricBuilder.max(),
partialMetricBuilder.sum(),
partialMetricBuilder.count()
)) {
if (randomBoolean()) {
subBuilder.appendNull();
} else {
if (subBuilder instanceof DoubleBlockBuilder doubleBlockBuilder) {
doubleBlockBuilder.appendDouble(0.0);
} else if (subBuilder instanceof IntBlockBuilder intBlockBuilder) {
intBlockBuilder.appendInt(0);
}
}
}

List<AggregateMetricDoubleBlock> blocks = List.of(
blockFactory.newAggregateMetricDoubleBlockBuilder(0).build(),
blockFactory.newAggregateMetricDoubleBlockBuilder(0).appendNull().build().filter(),
partialMetricBuilder.build().filter(),
blockFactory.newConstantAggregateMetricDoubleBlock(
new AggregateMetricDoubleBlockBuilder.AggregateMetricDoubleLiteral(0.0, 0.0, 0.0, 0),
0
).filter(),
(ConstantNullBlock) blockFactory.newConstantNullBlock(0)
);

assertAllEquals(blocks);
Releasables.close(blocks);
}

public void testSimpleBlockWithManyNulls() {
int positions = randomIntBetween(1, 256);
boolean grow = randomBoolean();
AggregateMetricDoubleBlockBuilder builder1 = blockFactory.newAggregateMetricDoubleBlockBuilder(grow ? 0 : positions);
AggregateMetricDoubleBlockBuilder builder2 = blockFactory.newAggregateMetricDoubleBlockBuilder(grow ? 0 : positions);
ConstantNullBlock.Builder builder3 = new ConstantNullBlock.Builder(blockFactory);
for (int p = 0; p < positions; p++) {
builder1.appendNull();
builder2.appendNull();
builder3.appendNull();
}
AggregateMetricDoubleBlock block1 = builder1.build();
AggregateMetricDoubleBlock block2 = builder2.build();
Block block3 = builder3.build();
assertEquals(positions, block1.getPositionCount());
assertTrue(block1.mayHaveNulls());
assertTrue(block1.isNull(0));

List<Block> blocks = List.of(block1, block2, block3);
assertAllEquals(blocks);
}

static void assertAllEquals(List<?> objs) {
for (Object obj1 : objs) {
for (Object obj2 : objs) {
assertEquals(obj1, obj2);
assertEquals(obj2, obj1);
// equal objects must generate the same hash code
assertEquals(obj1.hashCode(), obj2.hashCode());
}
}
}
}
Loading