Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,42 @@

package org.apache.druid.compressedbigdecimal;

import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.query.groupby.GroupByQuery;

import java.util.List;

public class CompressedBigDecimalGroupByQueryConfig
{
private final String jsonQueryFile;
private final String jsonAggregatorsFile;
private final List<AggregatorFactory> ingestionAggregators;
private final GroupByQuery query;
private final String stringRevenue;
private final String longRevenue;
private final String doubleRevenue;

public CompressedBigDecimalGroupByQueryConfig(
String jsonQueryFile,
String jsonAggregatorsFile,
List<AggregatorFactory> ingestionAggregators,
GroupByQuery query,
String stringRevenue,
String longRevenue,
String doubleRevenue
)
{
this.jsonQueryFile = jsonQueryFile;
this.jsonAggregatorsFile = jsonAggregatorsFile;
this.ingestionAggregators = ingestionAggregators;
this.query = query;
this.stringRevenue = stringRevenue;
this.longRevenue = longRevenue;
this.doubleRevenue = doubleRevenue;
}

public String getJsonQueryFile()
public List<AggregatorFactory> getIngestionAggregators()
{
return jsonQueryFile;
return ingestionAggregators;
}

public String getJsonAggregatorsFile()
public GroupByQuery getQuery()
{
return jsonAggregatorsFile;
return query;
}

public String getStringRevenue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@

package org.apache.druid.compressedbigdecimal.aggregator;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.Resources;
import org.apache.druid.compressedbigdecimal.ArrayCompressedBigDecimal;
import org.apache.druid.compressedbigdecimal.CompressedBigDecimalGroupByQueryConfig;
import org.apache.druid.compressedbigdecimal.CompressedBigDecimalModule;
import org.apache.druid.data.input.MapBasedRow;
import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.java.util.common.guava.Sequence;
import org.apache.druid.query.aggregation.AggregationTestHelper;
import org.apache.druid.query.groupby.GroupByQuery;
import org.apache.druid.query.groupby.GroupByQueryConfig;
import org.apache.druid.query.groupby.ResultRow;
import org.hamcrest.collection.IsCollectionWithSize;
Expand All @@ -47,7 +44,6 @@
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
Expand Down Expand Up @@ -99,32 +95,21 @@ public static void setupClass()
@Test
public void testIngestAndGroupByAllQuery() throws IOException, Exception
{

String groupByQueryJson = Resources.asCharSource(
this.getClass().getResource("/" + cbdGroupByQueryConfig.getJsonQueryFile()),
StandardCharsets.UTF_8
).read();

Sequence<ResultRow> seq = helper.createIndexAndRunQueryOnSegment(
this.getClass().getResourceAsStream("/" + "bd_test_data.csv"),
CompressedBigDecimalAggregatorTimeseriesTestBase.SCHEMA,
CompressedBigDecimalAggregatorTimeseriesTestBase.FORMAT,
Resources.asCharSource(
this.getClass().getResource("/" + cbdGroupByQueryConfig.getJsonAggregatorsFile()),
StandardCharsets.UTF_8
).read(),
cbdGroupByQueryConfig.getIngestionAggregators(),
0,
Granularities.NONE,
5,
groupByQueryJson
cbdGroupByQueryConfig.getQuery()
);

List<ResultRow> results = seq.toList();
Assert.assertThat(results, IsCollectionWithSize.hasSize(1));
ResultRow row = results.get(0);
ObjectMapper mapper = helper.getObjectMapper();
GroupByQuery groupByQuery = mapper.readValue(groupByQueryJson, GroupByQuery.class);
MapBasedRow mapBasedRow = row.toMapBasedRow(groupByQuery);
MapBasedRow mapBasedRow = row.toMapBasedRow(cbdGroupByQueryConfig.getQuery());
Map<String, Object> event = mapBasedRow.getEvent();
Assert.assertEquals(
new DateTime("2017-01-01T00:00:00Z", DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.apache.druid.compressedbigdecimal.aggregator;

import com.google.common.collect.Iterables;
import com.google.common.io.Resources;
import org.apache.druid.compressedbigdecimal.ArrayCompressedBigDecimal;
import org.apache.druid.compressedbigdecimal.CompressedBigDecimalModule;
import org.apache.druid.data.input.ColumnsFilter;
Expand All @@ -36,6 +35,8 @@
import org.apache.druid.java.util.common.guava.Sequence;
import org.apache.druid.query.Result;
import org.apache.druid.query.aggregation.AggregationTestHelper;
import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.query.timeseries.TimeseriesQuery;
import org.apache.druid.query.timeseries.TimeseriesResultValue;
import org.apache.druid.testing.InitializedNullHandlingTest;
import org.joda.time.DateTime;
Expand All @@ -47,7 +48,6 @@

import java.io.File;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -121,26 +121,20 @@ public static void setupClass()
public abstract void testIngestAndTimeseriesQuery() throws Exception;

protected void testIngestAndTimeseriesQueryHelper(
String jsonAggregatorsFile,
String jsonQueryFile,
List<AggregatorFactory> ingestionAggregators,
TimeseriesQuery query,
String expected
) throws Exception
{
Sequence seq = helper.createIndexAndRunQueryOnSegment(
this.getClass().getResourceAsStream("/" + "bd_test_data.csv"),
SCHEMA,
FORMAT,
Resources.asCharSource(
this.getClass().getResource("/" + jsonAggregatorsFile),
StandardCharsets.UTF_8
).read(),
ingestionAggregators,
0,
Granularities.NONE,
5,
Resources.asCharSource(
this.getClass().getResource("/" + jsonQueryFile),
StandardCharsets.UTF_8
).read()
query
);

TimeseriesResultValue result = ((Result<TimeseriesResultValue>) Iterables.getOnlyElement(seq.toList())).getValue();
Expand All @@ -165,8 +159,8 @@ protected void testIngestAndTimeseriesQueryHelper(
public abstract void testIngestMultipleSegmentsAndTimeseriesQuery() throws Exception;

protected void testIngestMultipleSegmentsAndTimeseriesQueryHelper(
String jsonAggregatorsFile,
String jsonQueryFile,
List<AggregatorFactory> ingestionAggregators,
TimeseriesQuery query,
String expected
) throws Exception
{
Expand All @@ -175,10 +169,7 @@ protected void testIngestMultipleSegmentsAndTimeseriesQueryHelper(
new File(this.getClass().getResource("/" + "bd_test_data.csv").getFile()),
SCHEMA,
FORMAT,
Resources.asCharSource(
this.getClass().getResource("/" + jsonAggregatorsFile),
StandardCharsets.UTF_8
).read(),
ingestionAggregators,
segmentDir1,
0,
Granularities.NONE,
Expand All @@ -189,10 +180,7 @@ protected void testIngestMultipleSegmentsAndTimeseriesQueryHelper(
new File(this.getClass().getResource("/" + "bd_test_zero_data.csv").getFile()),
SCHEMA,
FORMAT,
Resources.asCharSource(
this.getClass().getResource("/" + jsonAggregatorsFile),
StandardCharsets.UTF_8
).read(),
ingestionAggregators,
segmentDir2,
0,
Granularities.NONE,
Expand All @@ -201,10 +189,7 @@ protected void testIngestMultipleSegmentsAndTimeseriesQueryHelper(

Sequence seq = helper.runQueryOnSegments(
Arrays.asList(segmentDir1, segmentDir2),
Resources.asCharSource(
this.getClass().getResource("/" + jsonQueryFile),
StandardCharsets.UTF_8
).read()
query
);

TimeseriesResultValue result = ((Result<TimeseriesResultValue>) Iterables.getOnlyElement(seq.toList())).getValue();
Expand All @@ -221,4 +206,3 @@ protected void testIngestMultipleSegmentsAndTimeseriesQueryHelper(

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.apache.druid.compressedbigdecimal.CompressedBigDecimalGroupByQueryConfig;
import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalAggregatorGroupByTestBase;
import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.query.groupby.GroupByQuery;
import org.apache.druid.query.groupby.GroupByQueryConfig;
import org.apache.druid.query.groupby.GroupByQueryRunnerTest;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -50,8 +52,17 @@ public static Collection<?> constructorFeeder()
{
List<Object[]> constructors = new ArrayList<>();
CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig = new CompressedBigDecimalGroupByQueryConfig(
"bd_max_test_groupby_query.json",
"bd_max_test_aggregators.json",
List.of(new CompressedBigDecimalMaxAggregatorFactory("bigDecimalRevenue", "revenue", 3, 9, null)),
GroupByQuery.builder()
.setDataSource("test_datasource")
.setGranularity(Granularities.ALL)
.setInterval("2017-01-01T00:00:00.000Z/P1D")
.setAggregatorSpecs(
new CompressedBigDecimalMaxAggregatorFactory("cbdRevenueFromString", "revenue", 3, 9, null),
new CompressedBigDecimalMaxAggregatorFactory("cbdRevenueFromLong", "longRevenue", 3, 9, null),
new CompressedBigDecimalMaxAggregatorFactory("cbdRevenueFromDouble", "doubleRevenue", 3, 9, null)
)
.build(),
"9999999999.000000000",
"9999999999.000000000",
"9999999999.000000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,30 @@
package org.apache.druid.compressedbigdecimal.aggregator.max;

import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalAggregatorTimeseriesTestBase;
import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.query.Druids;
import org.apache.druid.query.filter.NotDimFilter;
import org.apache.druid.query.filter.SelectorDimFilter;
import org.apache.druid.query.timeseries.TimeseriesQuery;

import java.util.List;

public class CompressedBigDecimalMaxAggregatorTimeseriesTest extends CompressedBigDecimalAggregatorTimeseriesTestBase
{
private static final TimeseriesQuery QUERY = Druids.newTimeseriesQueryBuilder()
.dataSource("test_datasource")
.granularity(Granularities.ALL)
.aggregators(new CompressedBigDecimalMaxAggregatorFactory("cbdStringRevenue", "revenue", 3, 9, null))
.filters(new NotDimFilter(new SelectorDimFilter("property", "XXX", null)))
.intervals("2017-01-01T00:00:00.000Z/P1D")
.build();

@Override
public void testIngestAndTimeseriesQuery() throws Exception
{
testIngestAndTimeseriesQueryHelper(
"bd_max_test_aggregators.json",
"bd_max_test_timeseries_query.json",
List.of(new CompressedBigDecimalMaxAggregatorFactory("bigDecimalRevenue", "revenue", 3, 9, null)),
QUERY,
"9999999999.000000000"
);
}
Expand All @@ -37,10 +52,9 @@ public void testIngestAndTimeseriesQuery() throws Exception
public void testIngestMultipleSegmentsAndTimeseriesQuery() throws Exception
{
testIngestMultipleSegmentsAndTimeseriesQueryHelper(
"bd_max_test_aggregators.json",
"bd_max_test_timeseries_query.json",
List.of(new CompressedBigDecimalMaxAggregatorFactory("bigDecimalRevenue", "revenue", 3, 9, null)),
QUERY,
"9999999999.000000000"
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.apache.druid.compressedbigdecimal.CompressedBigDecimalGroupByQueryConfig;
import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalAggregatorGroupByTestBase;
import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.query.groupby.GroupByQuery;
import org.apache.druid.query.groupby.GroupByQueryConfig;
import org.apache.druid.query.groupby.GroupByQueryRunnerTest;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -52,8 +54,17 @@ public static Collection<?> constructorFeeder()
{
List<Object[]> constructors = new ArrayList<>();
CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig = new CompressedBigDecimalGroupByQueryConfig(
"bd_min_test_groupby_query.json",
"bd_min_test_aggregators.json",
List.of(new CompressedBigDecimalMinAggregatorFactory("bigDecimalRevenue", "revenue", 3, 9, null)),
GroupByQuery.builder()
.setDataSource("test_datasource")
.setGranularity(Granularities.ALL)
.setInterval("2017-01-01T00:00:00.000Z/P1D")
.setAggregatorSpecs(
new CompressedBigDecimalMinAggregatorFactory("cbdRevenueFromString", "revenue", 3, 9, null),
new CompressedBigDecimalMinAggregatorFactory("cbdRevenueFromLong", "longRevenue", 3, 9, null),
new CompressedBigDecimalMinAggregatorFactory("cbdRevenueFromDouble", "doubleRevenue", 3, 9, null)
)
.build(),
"-1.000000000",
"-1.000000000",
"-1.000000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,30 @@
package org.apache.druid.compressedbigdecimal.aggregator.min;

import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalAggregatorTimeseriesTestBase;
import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.query.Druids;
import org.apache.druid.query.filter.NotDimFilter;
import org.apache.druid.query.filter.SelectorDimFilter;
import org.apache.druid.query.timeseries.TimeseriesQuery;

import java.util.List;

public class CompressedBigDecimalMinAggregatorTimeseriesTest extends CompressedBigDecimalAggregatorTimeseriesTestBase
{
private static final TimeseriesQuery QUERY = Druids.newTimeseriesQueryBuilder()
.dataSource("test_datasource")
.granularity(Granularities.ALL)
.aggregators(new CompressedBigDecimalMinAggregatorFactory("cbdStringRevenue", "revenue", 3, 9, null))
.filters(new NotDimFilter(new SelectorDimFilter("property", "XXX", null)))
.intervals("2017-01-01T00:00:00.000Z/P1D")
.build();

@Override
public void testIngestAndTimeseriesQuery() throws Exception
{
testIngestAndTimeseriesQueryHelper(
"bd_min_test_aggregators.json",
"bd_min_test_timeseries_query.json",
List.of(new CompressedBigDecimalMinAggregatorFactory("bigDecimalRevenue", "revenue", 3, 9, null)),
QUERY,
"-1.000000000"
);
}
Expand All @@ -37,10 +52,9 @@ public void testIngestAndTimeseriesQuery() throws Exception
public void testIngestMultipleSegmentsAndTimeseriesQuery() throws Exception
{
testIngestMultipleSegmentsAndTimeseriesQueryHelper(
"bd_min_test_aggregators.json",
"bd_min_test_timeseries_query.json",
List.of(new CompressedBigDecimalMinAggregatorFactory("bigDecimalRevenue", "revenue", 3, 9, null)),
QUERY,
"-1.000000000"
);
}
}

Loading
Loading