Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 0 additions & 5 deletions extensions-core/histogram/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@
import org.apache.druid.query.groupby.GroupByQueryRunnerTest;
import org.apache.druid.query.groupby.ResultRow;
import org.apache.druid.testing.InitializedNullHandlingTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -51,25 +50,23 @@
/**
*
*/
@RunWith(Parameterized.class)
public class ApproximateHistogramAggregationTest extends InitializedNullHandlingTest
{
private AggregationTestHelper helper;

@Rule
public final TemporaryFolder tempFolder = new TemporaryFolder();
@TempDir
public File tempFolder;

public ApproximateHistogramAggregationTest(final GroupByQueryConfig config)
public void initApproximateHistogramAggregationTest(final GroupByQueryConfig config)
{
ApproximateHistogramDruidModule.registerSerde();
helper = AggregationTestHelper.createGroupByQueryAggregationTestHelper(
helper = AggregationTestHelper.createGroupByQueryAggregationTestHelperWithTempDir(
Lists.newArrayList(new ApproximateHistogramDruidModule().getJacksonModules()),
config,
tempFolder
);
}

@Parameterized.Parameters(name = "{0}")
public static Collection<?> constructorFeeder()
{
final List<Object[]> constructors = new ArrayList<>();
Expand All @@ -79,32 +76,34 @@ public static Collection<?> constructorFeeder()
return constructors;
}

@After
@AfterEach
public void teardown() throws IOException
{
helper.close();
}

@Test
public void testIngestWithNullsIgnoredAndQuery() throws Exception
@MethodSource("constructorFeeder")
@ParameterizedTest(name = "{0}")
public void testIngestWithNullsIgnoredAndQuery(final GroupByQueryConfig config) throws Exception
{
initApproximateHistogramAggregationTest(config);
MapBasedRow row = ingestAndQuery(true);
Assert.assertEquals(92.782760, row.getMetric("index_min").floatValue(), 0.0001);
Assert.assertEquals(135.109191, row.getMetric("index_max").floatValue(), 0.0001);
Assert.assertEquals(133.69340, row.getMetric("index_quantile").floatValue(), 0.0001);
Assert.assertEquals(
Assertions.assertEquals(92.782760, row.getMetric("index_min").floatValue(), 0.0001);
Assertions.assertEquals(135.109191, row.getMetric("index_max").floatValue(), 0.0001);
Assertions.assertEquals(133.69340, row.getMetric("index_quantile").floatValue(), 0.0001);
Assertions.assertEquals(
new Quantiles(new float[]{0.2f, 0.7f}, new float[]{92.78276f, 103.195305f}, 92.78276f, 135.109191f),
row.getRaw("index_quantiles")
);
Assert.assertEquals(
Assertions.assertEquals(
"Histogram{breaks=[92.0, 94.0, 96.0, 98.0, 100.0, 106.0, 108.0, 134.0, 136.0], counts=[1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]}",
row.getRaw("index_buckets").toString()
);
Assert.assertEquals(
Assertions.assertEquals(
"Histogram{breaks=[50.0, 100.0], counts=[3.0]}",
row.getRaw("index_custom").toString()
);
Assert.assertEquals(
Assertions.assertEquals(
"Histogram{breaks=[71.61954498291016, 92.78276062011719, 113.94597625732422, 135.10919189453125], counts=[1.0, 3.0, 1.0]}",
row.getRaw("index_equal").toString()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest;
import org.apache.druid.segment.column.RowSignature;
import org.apache.druid.testing.InitializedNullHandlingTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.nio.ByteBuffer;

Expand Down Expand Up @@ -70,20 +70,18 @@ public void testBufferAggregate()

ApproximateHistogram h = ((ApproximateHistogram) agg.get(buf, position));

Assert.assertArrayEquals(
"final bin positions don't match expected positions",
new float[]{2, 9.5f, 19.33f, 32.67f, 45f}, h.positions, 0.01f
Assertions.assertArrayEquals(
new float[]{2, 9.5f, 19.33f, 32.67f, 45f}, h.positions, 0.01f, "final bin positions don't match expected positions"
);

Assert.assertArrayEquals(
"final bin counts don't match expected counts",
new long[]{1, 2, 3, 3, 1}, h.bins()
Assertions.assertArrayEquals(
new long[]{1, 2, 3, 3, 1}, h.bins(), "final bin counts don't match expected counts"
);

Assert.assertEquals("getMin value doesn't match expected getMin", 2, h.min(), 0);
Assert.assertEquals("getMax value doesn't match expected getMax", 45, h.max(), 0);
Assertions.assertEquals(2, h.min(), 0, "getMin value doesn't match expected getMin");
Assertions.assertEquals(45, h.max(), 0, "getMax value doesn't match expected getMax");

Assert.assertEquals("bin count doesn't match expected bin count", 5, h.binCount());
Assertions.assertEquals(5, h.binCount(), "bin count doesn't match expected bin count");
}

@Test
Expand Down Expand Up @@ -112,10 +110,10 @@ public void testFinalize() throws Exception
JsonNode expectedJson = objectMapper.readTree(
"{\"breaks\":[23.0,23.0,23.0,23.0,23.0,23.0],\"counts\":[0.0,0.0,0.0,0.0,0.0]}");
JsonNode actualJson = objectMapper.readTree(finalStringHumanReadable);
Assert.assertEquals(expectedJson, actualJson);
Assertions.assertEquals(expectedJson, actualJson);
Object finalizedObjectBinary = binaryFactory.finalizeComputation(agg.get());
String finalStringBinary = objectMapper.writeValueAsString(finalizedObjectBinary);
Assert.assertEquals(
Assertions.assertEquals(
"\"//sBQbgAAA==\"",
finalStringBinary
);
Expand All @@ -141,7 +139,7 @@ public void testResultArraySignature()
)
.build();

Assert.assertEquals(
Assertions.assertEquals(
RowSignature.builder()
.addTimeColumn()
.add("approxHisto", null)
Expand All @@ -167,7 +165,7 @@ public void testWithName()
null,
false
);
Assert.assertEquals(factory, factory.withName("approxHisto"));
Assert.assertEquals("newTest", factory.withName("newTest").getName());
Assertions.assertEquals(factory, factory.withName("approxHisto"));
Assertions.assertEquals("newTest", factory.withName("newTest").getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.apache.druid.data.input.MapBasedInputRow;
import org.apache.druid.segment.data.ObjectStrategy;
import org.apache.druid.segment.serde.ComplexMetricExtractor;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -45,34 +45,34 @@ public void testExtractor()

final MapBasedInputRow row = new MapBasedInputRow(0L, ImmutableList.of(), theMap);

Assert.assertEquals(
"nullValue",
Assertions.assertEquals(
new ApproximateHistogram(0),
extractor.extractValue(row, "nullValue")
extractor.extractValue(row, "nullValue"),
"nullValue"
);

Assert.assertEquals(
"missingValue",
Assertions.assertEquals(
new ApproximateHistogram(0),
extractor.extractValue(row, "missingValue")
extractor.extractValue(row, "missingValue"),
"missingValue"
);

Assert.assertEquals(
"listValue",
Assertions.assertEquals(
makeHistogram(1, 2, 3),
extractor.extractValue(row, "listValue")
extractor.extractValue(row, "listValue"),
"listValue"
);

Assert.assertEquals(
"stringValue",
Assertions.assertEquals(
makeHistogram(1),
extractor.extractValue(row, "stringValue")
extractor.extractValue(row, "stringValue"),
"stringValue"
);

Assert.assertEquals(
"numberValue",
Assertions.assertEquals(
makeHistogram(1),
extractor.extractValue(row, "numberValue")
extractor.extractValue(row, "numberValue"),
"numberValue"
);
}

Expand All @@ -81,7 +81,7 @@ public void testReadRetainsBufferReference()
{
final ApproximateHistogramFoldingSerde serde = new ApproximateHistogramFoldingSerde();
final ObjectStrategy<ApproximateHistogram> strategy = serde.getObjectStrategy();
Assert.assertFalse(strategy.readRetainsBufferReference());
Assertions.assertFalse(strategy.readRetainsBufferReference());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import org.apache.druid.segment.vector.VectorColumnSelectorFactory;
import org.apache.druid.segment.vector.VectorObjectSelector;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.nio.ByteBuffer;

Expand All @@ -41,7 +41,7 @@ public class ApproximateHistogramFoldingVectorAggregatorTest
private ApproximateHistogram h1;
private ApproximateHistogram h2;

@Before
@BeforeEach
public void setup()
{

Expand Down Expand Up @@ -79,28 +79,28 @@ public void setup()
public void doNotVectorizedNonComplexTypes()
{
ApproximateHistogramFoldingAggregatorFactory factory = buildHistogramFactory("string_field");
Assert.assertFalse(factory.canVectorize(vectorColumnSelectorFactory));
Assertions.assertFalse(factory.canVectorize(vectorColumnSelectorFactory));

factory = buildHistogramFactory("double_field");
Assert.assertFalse(factory.canVectorize(vectorColumnSelectorFactory));
Assertions.assertFalse(factory.canVectorize(vectorColumnSelectorFactory));
}

@Test
public void testAggregateSinglePosition()
{
ApproximateHistogramFoldingAggregatorFactory factory = buildHistogramFactory();
ByteBuffer byteBuffer = ByteBuffer.allocate(factory.getMaxIntermediateSize());
Assert.assertTrue(factory.canVectorize(vectorColumnSelectorFactory));
Assertions.assertTrue(factory.canVectorize(vectorColumnSelectorFactory));
VectorAggregator vectorAggregator = factory.factorizeVector(vectorColumnSelectorFactory);
vectorAggregator.init(byteBuffer, 0);
vectorAggregator.aggregate(byteBuffer, 0, 0, 4);
ApproximateHistogram h = (ApproximateHistogram) vectorAggregator.get(byteBuffer, 0);

Assert.assertArrayEquals(new float[]{19.6f, 45.0f}, h.positions(), 0.1f);
Assert.assertArrayEquals(new long[]{9, 1}, h.bins());
Assert.assertEquals(10, h.count());
Assert.assertEquals(2.0f, h.min(), 0.1f);
Assert.assertEquals(45.0f, h.max(), 0.1f);
Assertions.assertArrayEquals(new float[]{19.6f, 45.0f}, h.positions(), 0.1f);
Assertions.assertArrayEquals(new long[]{9, 1}, h.bins());
Assertions.assertEquals(10, h.count());
Assertions.assertEquals(2.0f, h.min(), 0.1f);
Assertions.assertEquals(45.0f, h.max(), 0.1f);
}

@Test
Expand All @@ -118,17 +118,17 @@ public void testAggregateMultiPositions()
ApproximateHistogram actualH1 = (ApproximateHistogram) vectorAggregator.get(byteBuffer, 0);
ApproximateHistogram actualH2 = (ApproximateHistogram) vectorAggregator.get(byteBuffer, positions[1]);

Assert.assertEquals(actualH1, h1);
Assert.assertEquals(actualH2, h2);
Assertions.assertEquals(actualH1, h1);
Assertions.assertEquals(actualH2, h2);

}

@Test
public void testWithName()
{
ApproximateHistogramFoldingAggregatorFactory factory = buildHistogramFactory();
Assert.assertEquals(factory, factory.withName("approximateHistoFold"));
Assert.assertEquals("newTest", factory.withName("newTest").getName());
Assertions.assertEquals(factory, factory.withName("approximateHistoFold"));
Assertions.assertEquals("newTest", factory.withName("newTest").getName());
}

private ApproximateHistogramFoldingAggregatorFactory buildHistogramFactory()
Expand Down
Loading
Loading