[Rollup] Remove builders from GroupConfig (#32614)

This commit is contained in:
Tanguy Leroux 2018-08-07 09:39:24 +02:00 committed by GitHub
parent 3fb0923182
commit 1122314b3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 246 additions and 331 deletions

View File

@ -42,8 +42,8 @@ public class RollupJobCaps implements Writeable, ToXContentObject {
jobID = job.getId();
rollupIndex = job.getRollupIndex();
indexPattern = job.getIndexPattern();
Map<String, Object> dateHistoAggCap = job.getGroupConfig().getDateHisto().toAggCap();
String dateField = job.getGroupConfig().getDateHisto().getField();
Map<String, Object> dateHistoAggCap = job.getGroupConfig().getDateHistogram().toAggCap();
String dateField = job.getGroupConfig().getDateHistogram().getField();
RollupFieldCaps fieldCaps = fieldCapLookup.get(dateField);
if (fieldCaps == null) {
fieldCaps = new RollupFieldCaps();
@ -51,9 +51,9 @@ public class RollupJobCaps implements Writeable, ToXContentObject {
fieldCaps.addAgg(dateHistoAggCap);
fieldCapLookup.put(dateField, fieldCaps);
if (job.getGroupConfig().getHisto() != null) {
Map<String, Object> histoAggCap = job.getGroupConfig().getHisto().toAggCap();
Arrays.stream(job.getGroupConfig().getHisto().getFields()).forEach(field -> {
if (job.getGroupConfig().getHistogram() != null) {
Map<String, Object> histoAggCap = job.getGroupConfig().getHistogram().toAggCap();
Arrays.stream(job.getGroupConfig().getHistogram().getFields()).forEach(field -> {
RollupFieldCaps caps = fieldCapLookup.get(field);
if (caps == null) {
caps = new RollupFieldCaps();

View File

@ -54,7 +54,7 @@ import static org.elasticsearch.common.xcontent.ObjectParser.ValueType;
*/
public class DateHistogramGroupConfig implements Writeable, ToXContentObject {
private static final String NAME = "date_histogram";
static final String NAME = "date_histogram";
private static final String INTERVAL = "interval";
private static final String FIELD = "field";
public static final String TIME_ZONE = "time_zone";

View File

@ -13,17 +13,21 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import static java.util.Arrays.asList;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
/**
* The configuration object for the groups section in the rollup config.
@ -38,64 +42,85 @@ import static java.util.Arrays.asList;
* }
*/
public class GroupConfig implements Writeable, ToXContentObject {
private static final String NAME = "grouping_config";
private static final ParseField DATE_HISTO = new ParseField("date_histogram");
private static final ParseField HISTO = new ParseField("histogram");
private static final ParseField TERMS = new ParseField("terms");
private final DateHistogramGroupConfig dateHisto;
private final HistogramGroupConfig histo;
private final TermsGroupConfig terms;
public static final ObjectParser<GroupConfig.Builder, Void> PARSER = new ObjectParser<>(NAME, GroupConfig.Builder::new);
public static final String NAME = "groups";
private static final ConstructingObjectParser<GroupConfig, Void> PARSER;
static {
PARSER.declareObject(GroupConfig.Builder::setDateHisto, (p,c) -> DateHistogramGroupConfig.fromXContent(p), DATE_HISTO);
PARSER.declareObject(GroupConfig.Builder::setHisto, (p,c) -> HistogramGroupConfig.fromXContent(p), HISTO);
PARSER.declareObject(GroupConfig.Builder::setTerms, (p,c) -> TermsGroupConfig.fromXContent(p), TERMS);
PARSER = new ConstructingObjectParser<>(NAME, args ->
new GroupConfig((DateHistogramGroupConfig) args[0], (HistogramGroupConfig) args[1], (TermsGroupConfig) args[2]));
PARSER.declareObject(constructorArg(),
(p, c) -> DateHistogramGroupConfig.fromXContent(p), new ParseField(DateHistogramGroupConfig.NAME));
PARSER.declareObject(optionalConstructorArg(),
(p, c) -> HistogramGroupConfig.fromXContent(p), new ParseField(HistogramGroupConfig.NAME));
PARSER.declareObject(optionalConstructorArg(),
(p, c) -> TermsGroupConfig.fromXContent(p), new ParseField(TermsGroupConfig.NAME));
}
private GroupConfig(DateHistogramGroupConfig dateHisto, @Nullable HistogramGroupConfig histo, @Nullable TermsGroupConfig terms) {
this.dateHisto = Objects.requireNonNull(dateHisto, "A date_histogram group is mandatory");
this.histo = histo;
private final DateHistogramGroupConfig dateHistogram;
private final @Nullable HistogramGroupConfig histogram;
private final @Nullable TermsGroupConfig terms;
public GroupConfig(final DateHistogramGroupConfig dateHistogram) {
this(dateHistogram, null, null);
}
public GroupConfig(final DateHistogramGroupConfig dateHistogram,
final @Nullable HistogramGroupConfig histogram,
final @Nullable TermsGroupConfig terms) {
if (dateHistogram == null) {
throw new IllegalArgumentException("Date histogram must not be null");
}
this.dateHistogram = dateHistogram;
this.histogram = histogram;
this.terms = terms;
}
GroupConfig(StreamInput in) throws IOException {
dateHisto = new DateHistogramGroupConfig(in);
histo = in.readOptionalWriteable(HistogramGroupConfig::new);
GroupConfig(final StreamInput in) throws IOException {
dateHistogram = new DateHistogramGroupConfig(in);
histogram = in.readOptionalWriteable(HistogramGroupConfig::new);
terms = in.readOptionalWriteable(TermsGroupConfig::new);
}
public DateHistogramGroupConfig getDateHisto() {
return dateHisto;
/**
* @return the configuration of the date histogram
*/
public DateHistogramGroupConfig getDateHistogram() {
return dateHistogram;
}
public HistogramGroupConfig getHisto() {
return histo;
/**
* @return the configuration of the histogram
*/
@Nullable
public HistogramGroupConfig getHistogram() {
return histogram;
}
/**
* @return the configuration of the terms
*/
@Nullable
public TermsGroupConfig getTerms() {
return terms;
}
public Set<String> getAllFields() {
Set<String> fields = new HashSet<>();
fields.add(dateHisto.getField());
if (histo != null) {
fields.addAll(asList(histo.getFields()));
fields.add(dateHistogram.getField());
if (histogram != null) {
fields.addAll(asList(histogram.getFields()));
}
if (terms != null) {
fields.addAll(asList(terms.getFields()));
}
return fields;
return Collections.unmodifiableSet(fields);
}
public void validateMappings(Map<String, Map<String, FieldCapabilities>> fieldCapsResponse,
ActionRequestValidationException validationException) {
dateHisto.validateMappings(fieldCapsResponse, validationException);
if (histo != null) {
histo.validateMappings(fieldCapsResponse, validationException);
public void validateMappings(final Map<String, Map<String, FieldCapabilities>> fieldCapsResponse,
final ActionRequestValidationException validationException) {
dateHistogram.validateMappings(fieldCapsResponse, validationException);
if (histogram != null) {
histogram.validateMappings(fieldCapsResponse, validationException);
}
if (terms != null) {
terms.validateMappings(fieldCapsResponse, validationException);
@ -105,44 +130,43 @@ public class GroupConfig implements Writeable, ToXContentObject {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(DATE_HISTO.getPreferredName(), dateHisto);
if (histo != null) {
builder.field(HISTO.getPreferredName(), histo);
{
builder.field(DateHistogramGroupConfig.NAME, dateHistogram);
if (histogram != null) {
builder.field(HistogramGroupConfig.NAME, histogram);
}
if (terms != null) {
builder.field(TermsGroupConfig.NAME, terms);
}
}
if (terms != null) {
builder.field(TERMS.getPreferredName(), terms);
}
builder.endObject();
return builder;
return builder.endObject();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
dateHisto.writeTo(out);
out.writeOptionalWriteable(histo);
public void writeTo(final StreamOutput out) throws IOException {
dateHistogram.writeTo(out);
out.writeOptionalWriteable(histogram);
out.writeOptionalWriteable(terms);
}
@Override
public boolean equals(Object other) {
public boolean equals(final Object other) {
if (this == other) {
return true;
}
if (other == null || getClass() != other.getClass()) {
return false;
}
GroupConfig that = (GroupConfig) other;
return Objects.equals(this.dateHisto, that.dateHisto)
&& Objects.equals(this.histo, that.histo)
&& Objects.equals(this.terms, that.terms);
final GroupConfig that = (GroupConfig) other;
return Objects.equals(dateHistogram, that.dateHistogram)
&& Objects.equals(histogram, that.histogram)
&& Objects.equals(terms, that.terms);
}
@Override
public int hashCode() {
return Objects.hash(dateHisto, histo, terms);
return Objects.hash(dateHistogram, histogram, terms);
}
@Override
@ -150,43 +174,7 @@ public class GroupConfig implements Writeable, ToXContentObject {
return Strings.toString(this, true, true);
}
public static class Builder {
private DateHistogramGroupConfig dateHisto;
private HistogramGroupConfig histo;
private TermsGroupConfig terms;
public DateHistogramGroupConfig getDateHisto() {
return dateHisto;
}
public GroupConfig.Builder setDateHisto(DateHistogramGroupConfig dateHisto) {
this.dateHisto = dateHisto;
return this;
}
public HistogramGroupConfig getHisto() {
return histo;
}
public GroupConfig.Builder setHisto(HistogramGroupConfig histo) {
this.histo = histo;
return this;
}
public TermsGroupConfig getTerms() {
return terms;
}
public GroupConfig.Builder setTerms(TermsGroupConfig terms) {
this.terms = terms;
return this;
}
public GroupConfig build() {
if (dateHisto == null) {
throw new IllegalArgumentException("A date_histogram group is mandatory");
}
return new GroupConfig(dateHisto, histo, terms);
}
public static GroupConfig fromXContent(final XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}
}

View File

@ -46,7 +46,7 @@ import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constru
*/
public class HistogramGroupConfig implements Writeable, ToXContentObject {
public static final String NAME = "histogram";
static final String NAME = "histogram";
private static final String INTERVAL = "interval";
private static final String FIELDS = "fields";
private static final ConstructingObjectParser<HistogramGroupConfig, Void> PARSER;

View File

@ -62,7 +62,7 @@ public class RollupJobConfig implements NamedWriteable, ToXContentObject {
static {
PARSER.declareString(RollupJobConfig.Builder::setId, RollupField.ID);
PARSER.declareObject(RollupJobConfig.Builder::setGroupConfig, (p, c) -> GroupConfig.PARSER.apply(p,c).build(), GROUPS);
PARSER.declareObject(RollupJobConfig.Builder::setGroupConfig, (p, c) -> GroupConfig.fromXContent(p), GROUPS);
PARSER.declareObjectArray(RollupJobConfig.Builder::setMetricsConfig, (p, c) -> MetricConfig.fromXContent(p), METRICS);
PARSER.declareString((params, val) ->
params.setTimeout(TimeValue.parseTimeValue(val, TIMEOUT.getPreferredName())), TIMEOUT);

View File

@ -45,7 +45,7 @@ import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constru
*/
public class TermsGroupConfig implements Writeable, ToXContentObject {
private static final String NAME = "terms";
static final String NAME = "terms";
private static final String FIELDS = "fields";
private static final List<String> FLOAT_TYPES = Arrays.asList("half_float", "float", "double", "scaled_float");

View File

@ -37,7 +37,7 @@ public class ConfigTestHelpers {
String indexPattern = ESTestCase.randomAlphaOfLengthBetween(1,10);
builder.setIndexPattern(indexPattern);
builder.setRollupIndex("rollup_" + indexPattern); // to ensure the index pattern != rollup index
builder.setGroupConfig(ConfigTestHelpers.getGroupConfig().build());
builder.setGroupConfig(ConfigTestHelpers.randomGroupConfig(ESTestCase.random()));
builder.setPageSize(ESTestCase.randomIntBetween(1,10));
if (ESTestCase.randomBoolean()) {
builder.setMetricsConfig(randomMetricsConfigs(ESTestCase.random()));
@ -45,16 +45,11 @@ public class ConfigTestHelpers {
return builder;
}
public static GroupConfig.Builder getGroupConfig() {
GroupConfig.Builder groupBuilder = new GroupConfig.Builder();
groupBuilder.setDateHisto(randomDateHistogramGroupConfig(ESTestCase.random()));
if (ESTestCase.randomBoolean()) {
groupBuilder.setHisto(randomHistogramGroupConfig(ESTestCase.random()));
}
if (ESTestCase.randomBoolean()) {
groupBuilder.setTerms(randomTermsGroupConfig(ESTestCase.random()));
}
return groupBuilder;
public static GroupConfig randomGroupConfig(final Random random) {
DateHistogramGroupConfig dateHistogram = randomDateHistogramGroupConfig(random);
HistogramGroupConfig histogram = random.nextBoolean() ? randomHistogramGroupConfig(random) : null;
TermsGroupConfig terms = random.nextBoolean() ? randomTermsGroupConfig(random) : null;
return new GroupConfig(dateHistogram, histogram, terms);
}
private static final String[] TIME_SUFFIXES = new String[]{"d", "h", "ms", "s", "m"};

View File

@ -8,14 +8,16 @@ package org.elasticsearch.xpack.core.rollup.job;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractSerializingTestCase;
import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers;
import java.io.IOException;
import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomGroupConfig;
public class GroupConfigSerializingTests extends AbstractSerializingTestCase<GroupConfig> {
@Override
protected GroupConfig doParseInstance(XContentParser parser) throws IOException {
return GroupConfig.PARSER.apply(parser, null).build();
protected GroupConfig doParseInstance(final XContentParser parser) throws IOException {
return GroupConfig.fromXContent(parser);
}
@Override
@ -25,6 +27,6 @@ public class GroupConfigSerializingTests extends AbstractSerializingTestCase<Gro
@Override
protected GroupConfig createTestInstance() {
return ConfigTestHelpers.getGroupConfig().build();
return randomGroupConfig(random());
}
}

View File

@ -89,12 +89,12 @@ class IndexerUtils {
if (k.endsWith("." + DateHistogramAggregationBuilder.NAME)) {
assert v != null;
doc.put(k + "." + RollupField.TIMESTAMP, v);
doc.put(k + "." + RollupField.INTERVAL, groupConfig.getDateHisto().getInterval());
doc.put(k + "." + DateHistogramGroupConfig.TIME_ZONE, groupConfig.getDateHisto().getTimeZone().toString());
doc.put(k + "." + RollupField.INTERVAL, groupConfig.getDateHistogram().getInterval());
doc.put(k + "." + DateHistogramGroupConfig.TIME_ZONE, groupConfig.getDateHistogram().getTimeZone());
idGenerator.add((Long)v);
} else if (k.endsWith("." + HistogramAggregationBuilder.NAME)) {
doc.put(k + "." + RollupField.VALUE, v);
doc.put(k + "." + RollupField.INTERVAL, groupConfig.getHisto().getInterval());
doc.put(k + "." + RollupField.INTERVAL, groupConfig.getHistogram().getInterval());
if (v == null) {
idGenerator.addNull();
} else {

View File

@ -219,7 +219,7 @@ public abstract class RollupIndexer {
// rounds the current time to its current bucket based on the date histogram interval.
// this is needed to exclude buckets that can still receive new documents.
DateHistogramGroupConfig dateHisto = job.getConfig().getGroupConfig().getDateHisto();
DateHistogramGroupConfig dateHisto = job.getConfig().getGroupConfig().getDateHistogram();
long rounded = dateHisto.createRounding().round(now);
if (dateHisto.getDelay() != null) {
// if the job has a delay we filter all documents that appear before it.
@ -396,11 +396,11 @@ public abstract class RollupIndexer {
// Add all the agg builders to our request in order: date_histo -> histo -> terms
if (groupConfig != null) {
builders.addAll(groupConfig.getDateHisto().toBuilders());
metadata.putAll(groupConfig.getDateHisto().getMetadata());
if (groupConfig.getHisto() != null) {
builders.addAll(groupConfig.getHisto().toBuilders());
metadata.putAll(groupConfig.getHisto().getMetadata());
builders.addAll(groupConfig.getDateHistogram().toBuilders());
metadata.putAll(groupConfig.getDateHistogram().getMetadata());
if (groupConfig.getHistogram() != null) {
builders.addAll(groupConfig.getHistogram().toBuilders());
metadata.putAll(groupConfig.getHistogram().getMetadata());
}
if (groupConfig.getTerms() != null) {
builders.addAll(groupConfig.getTerms().toBuilders());
@ -426,7 +426,7 @@ public abstract class RollupIndexer {
*/
private QueryBuilder createBoundaryQuery(Map<String, Object> position) {
assert maxBoundary < Long.MAX_VALUE;
DateHistogramGroupConfig dateHisto = job.getConfig().getGroupConfig().getDateHisto();
DateHistogramGroupConfig dateHisto = job.getConfig().getGroupConfig().getDateHistogram();
String fieldName = dateHisto.getField();
String rollupFieldName = fieldName + "." + DateHistogramAggregationBuilder.NAME;
long lowerBound = 0L;

View File

@ -36,14 +36,13 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testOneMatch() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap);
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
.dateHistogramInterval(job.getGroupConfig().getDateHisto().getInterval());
.dateHistogramInterval(job.getGroupConfig().getDateHistogram().getInterval());
Set<RollupJobCaps> bestCaps = RollupJobIdentifierUtils.findBestJobs(builder, caps);
assertThat(bestCaps.size(), equalTo(1));
@ -51,9 +50,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testBiggerButCompatibleInterval() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap);
@ -66,9 +64,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testIncompatibleInterval() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d")));
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap);
@ -82,9 +79,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testBadTimeZone() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"), null, "EST"));
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"), null, "EST"));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap);
@ -99,9 +95,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testMetricOnlyAgg() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
job.setMetricsConfig(singletonList(new MetricConfig("bar", singletonList("max"))));
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap);
@ -114,9 +109,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testOneOfTwoMatchingCaps() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap);
@ -131,21 +125,15 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testTwoJobsSameRollupIndex() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setTerms(null);
group.setHisto(null);
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(2);
caps.add(cap);
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2");
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig();
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group2.setTerms(null);
group2.setHisto(null);
job2.setGroupConfig(group.build());
final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job2.setGroupConfig(group);
job2.setRollupIndex(job.getRollupIndex());
RollupJobCaps cap2 = new RollupJobCaps(job2.build());
caps.add(cap2);
@ -161,18 +149,16 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testTwoJobsButBothPartialMatches() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
job.setMetricsConfig(singletonList(new MetricConfig("bar", singletonList("max"))));
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(2);
caps.add(cap);
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2");
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig();
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job2.setGroupConfig(group.build());
final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job2.setGroupConfig(group);
job.setMetricsConfig(singletonList(new MetricConfig("bar", singletonList("min"))));
RollupJobCaps cap2 = new RollupJobCaps(job2.build());
caps.add(cap2);
@ -189,19 +175,13 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testComparableDifferentDateIntervals() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")))
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig();
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d")))
.setHisto(null)
.setTerms(null);
job2.setGroupConfig(group2.build());
final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d")));
job2.setGroupConfig(group2);
RollupJobCaps cap2 = new RollupJobCaps(job2.build());
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
@ -218,19 +198,13 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testComparableDifferentDateIntervalsOnlyOneWorks() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")))
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig();
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d")))
.setHisto(null)
.setTerms(null);
job2.setGroupConfig(group2.build());
final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d")));
job2.setGroupConfig(group2);
RollupJobCaps cap2 = new RollupJobCaps(job2.build());
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
@ -247,19 +221,14 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testComparableNoHistoVsHisto() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")))
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig();
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")))
.setHisto(new HistogramGroupConfig(100L, "bar"))
.setTerms(null);
job2.setGroupConfig(group2.build());
final HistogramGroupConfig histoConfig = new HistogramGroupConfig(100L, "bar");
final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")), histoConfig, null);
job2.setGroupConfig(group2);
RollupJobCaps cap2 = new RollupJobCaps(job2.build());
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
@ -277,19 +246,14 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testComparableNoTermsVsTerms() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")))
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig();
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")))
.setHisto(null)
.setTerms(new TermsGroupConfig("bar"));
job2.setGroupConfig(group2.build());
final TermsGroupConfig termsConfig = new TermsGroupConfig("bar");
final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")), null, termsConfig);
job2.setGroupConfig(group2);
RollupJobCaps cap2 = new RollupJobCaps(job2.build());
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
@ -313,11 +277,12 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig()
.setGroupConfig(new GroupConfig(
// NOTE same name but wrong type
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()))
.setHisto(new HistogramGroupConfig(1L, "baz")) // <-- NOTE right type but wrong name
.build())
new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()),
new HistogramGroupConfig(1L, "baz"), // <-- NOTE right type but wrong name
null
))
.setMetricsConfig(
Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg"))))
.build();
@ -336,9 +301,9 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig()
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()))
.build())
.setGroupConfig(new GroupConfig(
new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID())
))
.setMetricsConfig(
Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg"))))
.build();
@ -357,10 +322,10 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig()
.setGroupConfig(new GroupConfig(
// interval in job is much higher than agg interval above
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("100d"), null, DateTimeZone.UTC.getID()))
.build())
new DateHistogramGroupConfig("foo", new DateHistogramInterval("100d"), null, DateTimeZone.UTC.getID())
))
.build();
Set<RollupJobCaps> caps = singletonSet(new RollupJobCaps(job));
@ -377,10 +342,10 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig()
.setGroupConfig(new GroupConfig(
// NOTE different field from the one in the query
.setDateHisto(new DateHistogramGroupConfig("bar", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()))
.build())
new DateHistogramGroupConfig("bar", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID())
))
.setMetricsConfig(
Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg"))))
.build();
@ -399,10 +364,11 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig()
.setDateHisto(new DateHistogramGroupConfig("bar", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()))
.setHisto(new HistogramGroupConfig(1L, "baz")) // <-- NOTE right type but wrong name
.build())
.setGroupConfig(new GroupConfig(
new DateHistogramGroupConfig("bar", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()),
new HistogramGroupConfig(1L, "baz"), // <-- NOTE right type but wrong name
null
))
.setMetricsConfig(
Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg"))))
.build();
@ -421,10 +387,11 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig()
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()))
.setHisto(new HistogramGroupConfig(1L, "baz")) // <-- NOTE right type but wrong name
.build())
.setGroupConfig(new GroupConfig(
new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()),
new HistogramGroupConfig(1L, "baz"), // <-- NOTE right type but wrong name
null
))
.build();
Set<RollupJobCaps> caps = singletonSet(new RollupJobCaps(job));

View File

@ -58,7 +58,7 @@ import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig;
import org.elasticsearch.xpack.core.rollup.job.TermsGroupConfig;
import org.elasticsearch.xpack.rollup.Rollup;
import org.hamcrest.core.IsEqual;
import org.joda.time.DateTimeZone;
import org.junit.Before;
import org.mockito.Mockito;
import java.io.IOException;
@ -81,6 +81,9 @@ import static org.mockito.Mockito.when;
public class SearchActionTests extends ESTestCase {
private NamedWriteableRegistry namedWriteableRegistry;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
IndicesModule indicesModule = new IndicesModule(Collections.emptyList());
@ -119,9 +122,8 @@ public class SearchActionTests extends ESTestCase {
public void testRange() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(groupConfig);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap);
@ -132,9 +134,8 @@ public class SearchActionTests extends ESTestCase {
public void testRangeNullTimeZone() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap);
@ -145,9 +146,8 @@ public class SearchActionTests extends ESTestCase {
public void testRangeWrongTZ() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap);
@ -159,9 +159,9 @@ public class SearchActionTests extends ESTestCase {
public void testTermQuery() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setTerms(new TermsGroupConfig("foo"));
job.setGroupConfig(group.build());
final TermsGroupConfig termsConfig = new TermsGroupConfig("foo");
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("date", new DateHistogramInterval("1h")), null, termsConfig);
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap);
@ -172,9 +172,9 @@ public class SearchActionTests extends ESTestCase {
public void testTermsQuery() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setTerms(new TermsGroupConfig("foo"));
job.setGroupConfig(group.build());
final TermsGroupConfig termsConfig = new TermsGroupConfig("foo");
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("date", new DateHistogramInterval("1h")), null, termsConfig);
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap);
@ -189,9 +189,8 @@ public class SearchActionTests extends ESTestCase {
public void testCompounds() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(groupConfig);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap);
@ -205,9 +204,8 @@ public class SearchActionTests extends ESTestCase {
public void testMatchAll() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(groupConfig);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap);
@ -217,10 +215,9 @@ public class SearchActionTests extends ESTestCase {
public void testAmbiguousResolution() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setTerms(new TermsGroupConfig("foo"));
job.setGroupConfig(group.build());
final TermsGroupConfig termsConfig = new TermsGroupConfig("foo");
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")), null, termsConfig);
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap);
@ -368,9 +365,8 @@ public class SearchActionTests extends ESTestCase {
public void testGood() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group.build());
final GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(groupConfig);
RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap);
@ -385,7 +381,7 @@ public class SearchActionTests extends ESTestCase {
source.query(getQueryBuilder(1));
source.size(0);
source.aggregation(new DateHistogramAggregationBuilder("foo").field("foo")
.dateHistogramInterval(job.getGroupConfig().getDateHisto().getInterval()));
.dateHistogramInterval(job.getGroupConfig().getDateHistogram().getInterval()));
SearchRequest request = new SearchRequest(combinedIndices, source);
MultiSearchRequest msearch = TransportRollupSearchAction.createMSearchRequest(request, namedWriteableRegistry, ctx);
@ -414,9 +410,7 @@ public class SearchActionTests extends ESTestCase {
SearchRequest request = new SearchRequest(combinedIndices, source);
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig()
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()))
.build())
.setGroupConfig(new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, "UTC")))
.build();
Set<RollupJobCaps> caps = singletonSet(new RollupJobCaps(job));
@ -439,15 +433,12 @@ public class SearchActionTests extends ESTestCase {
public void testTwoMatchingJobs() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")))
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
job2.setGroupConfig(group.build());
job2.setGroupConfig(group);
// so that the jobs aren't exactly equal
job2.setMetricsConfig(ConfigTestHelpers.randomMetricsConfigs(random()));
@ -468,7 +459,7 @@ public class SearchActionTests extends ESTestCase {
source.query(getQueryBuilder(1));
source.size(0);
source.aggregation(new DateHistogramAggregationBuilder("foo").field("foo")
.dateHistogramInterval(job.getGroupConfig().getDateHisto().getInterval()));
.dateHistogramInterval(job.getGroupConfig().getDateHistogram().getInterval()));
SearchRequest request = new SearchRequest(combinedIndices, source);
MultiSearchRequest msearch = TransportRollupSearchAction.createMSearchRequest(request, namedWriteableRegistry, ctx);
@ -489,19 +480,13 @@ public class SearchActionTests extends ESTestCase {
public void testTwoMatchingJobsOneBetter() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig();
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")))
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig();
group2.setDateHisto(group.getDateHisto())
.setHisto(randomHistogramGroupConfig(random()))
.setTerms(null);
job2.setGroupConfig(group2.build());
final GroupConfig group2 = new GroupConfig(group.getDateHistogram(), randomHistogramGroupConfig(random()), null);
job2.setGroupConfig(group2);
RollupJobCaps cap2 = new RollupJobCaps(job2.build());
Set<RollupJobCaps> caps = new HashSet<>(2);
@ -519,7 +504,7 @@ public class SearchActionTests extends ESTestCase {
source.query(getQueryBuilder(1));
source.size(0);
source.aggregation(new DateHistogramAggregationBuilder("foo").field("foo")
.dateHistogramInterval(job.getGroupConfig().getDateHisto().getInterval()));
.dateHistogramInterval(job.getGroupConfig().getDateHistogram().getInterval()));
SearchRequest request = new SearchRequest(combinedIndices, source);
MultiSearchRequest msearch = TransportRollupSearchAction.createMSearchRequest(request, namedWriteableRegistry, ctx);

View File

@ -22,6 +22,8 @@ import java.util.Map;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomHistogramGroupConfig;
import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomTermsGroupConfig;
import static org.hamcrest.Matchers.equalTo;
//TODO split this into dedicated unit test classes (one for each config object)
public class ConfigTests extends ESTestCase {
@ -43,22 +45,14 @@ public class ConfigTests extends ESTestCase {
}
public void testEmptyGroup() {
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig();
groupConfig.setDateHisto(null);
groupConfig.setTerms(null);
groupConfig.setHisto(null);
Exception e = expectThrows(IllegalArgumentException.class, groupConfig::build);
assertThat(e.getMessage(), equalTo("A date_histogram group is mandatory"));
Exception e = expectThrows(IllegalArgumentException.class, () -> new GroupConfig(null, null, null));
assertThat(e.getMessage(), equalTo("Date histogram must not be null"));
}
public void testNoDateHisto() {
GroupConfig.Builder groupConfig = new GroupConfig.Builder();
groupConfig.setTerms(ConfigTestHelpers.randomTermsGroupConfig(random()));
groupConfig.setHisto(ConfigTestHelpers.randomHistogramGroupConfig(random()));
Exception e = expectThrows(IllegalArgumentException.class, groupConfig::build);
assertThat(e.getMessage(), equalTo("A date_histogram group is mandatory"));
Exception e = expectThrows(IllegalArgumentException.class,
() -> new GroupConfig(null, randomHistogramGroupConfig(random()), randomTermsGroupConfig(random())));
assertThat(e.getMessage(), equalTo("Date histogram must not be null"));
}
public void testEmptyGroupAndMetrics() {

View File

@ -35,7 +35,6 @@ import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggre
import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder;
import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers;
import org.elasticsearch.xpack.core.rollup.RollupField;
import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig;
import org.elasticsearch.xpack.core.rollup.job.GroupConfig;
@ -54,8 +53,10 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomHistogramGroupConfig;
import static java.util.Collections.singletonList;
import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomDateHistogramGroupConfig;
import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomGroupConfig;
import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomHistogramGroupConfig;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -112,8 +113,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close();
directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats,
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean());
final GroupConfig groupConfig = randomGroupConfig(random());
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(numDocs));
for (IndexRequest doc : docs) {
@ -179,8 +180,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close();
directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats,
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean());
final GroupConfig groupConfig = randomGroupConfig(random());
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(numDocs));
for (IndexRequest doc : docs) {
@ -235,8 +236,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close();
directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats,
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean());
final GroupConfig groupConfig = randomGroupConfig(random());
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(numDocs));
for (IndexRequest doc : docs) {
@ -301,8 +302,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close();
directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats,
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean());
final GroupConfig groupConfig = randomGroupConfig(random());
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(numDocs));
for (IndexRequest doc : docs) {
@ -353,11 +354,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
// The content of the config don't actually matter for this test
// because the test is just looking at agg keys
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig();
groupConfig.setHisto(new HistogramGroupConfig(123L, "abc"));
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(),
groupConfig.build(), "foo", false);
GroupConfig groupConfig = new GroupConfig(randomDateHistogramGroupConfig(random()), new HistogramGroupConfig(123L, "abc"), null);
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(), groupConfig, "foo", false);
assertThat(docs.size(), equalTo(1));
assertThat(docs.get(0).id(), equalTo("1237859798"));
}
@ -400,11 +398,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
return foos;
});
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig();
groupConfig.setHisto(new HistogramGroupConfig(1, "abc"));
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(),
groupConfig.build(), "foo", true);
GroupConfig groupConfig = new GroupConfig(randomDateHistogramGroupConfig(random()), new HistogramGroupConfig(1L, "abc"), null);
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(), groupConfig, "foo", true);
assertThat(docs.size(), equalTo(1));
assertThat(docs.get(0).id(), equalTo("foo$c9LcrFqeFW92uN_Z7sv1hA"));
}
@ -453,11 +448,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
return foos;
});
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig();
groupConfig.setHisto(new HistogramGroupConfig(1, "abc"));
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(),
groupConfig.build(), "foo", true);
GroupConfig groupConfig = new GroupConfig(randomDateHistogramGroupConfig(random()), new HistogramGroupConfig(1, "abc"), null);
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(), groupConfig, "foo", true);
assertThat(docs.size(), equalTo(1));
assertThat(docs.get(0).id(), equalTo("foo$VAFKZpyaEqYRPLyic57_qw"));
}
@ -483,11 +475,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
return foos;
});
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig();
groupConfig.setHisto(randomHistogramGroupConfig(random()));
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(),
groupConfig.build(), "foo", randomBoolean());
GroupConfig groupConfig = new GroupConfig(randomDateHistogramGroupConfig(random()), randomHistogramGroupConfig(random()), null);
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(), groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(1));
assertFalse(Strings.isNullOrEmpty(docs.get(0).id()));
}
@ -548,8 +537,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close();
directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats,
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean());
final GroupConfig groupConfig = randomGroupConfig(random());
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(6));
for (IndexRequest doc : docs) {

View File

@ -96,8 +96,7 @@ public class RollupIndexerIndexingTests extends AggregatorTestCase {
String rollupIndex = randomAlphaOfLength(10);
String field = "the_histo";
DateHistogramGroupConfig dateHistoConfig = new DateHistogramGroupConfig(field, new DateHistogramInterval("1ms"));
RollupJobConfig job = createJob(rollupIndex, new GroupConfig.Builder().setDateHisto(dateHistoConfig).build(),
Collections.emptyList());
RollupJobConfig job = createJob(rollupIndex, new GroupConfig(dateHistoConfig), Collections.emptyList());
final List<Map<String, Object>> dataset = new ArrayList<>();
dataset.addAll(
Arrays.asList(
@ -142,8 +141,7 @@ public class RollupIndexerIndexingTests extends AggregatorTestCase {
String field = "the_histo";
DateHistogramGroupConfig dateHistoConfig = new DateHistogramGroupConfig(field, new DateHistogramInterval("1h"));
MetricConfig config = new MetricConfig("counter", Arrays.asList("avg", "sum", "max", "min"));
RollupJobConfig job = createJob(rollupIndex, new GroupConfig.Builder().setDateHisto(dateHistoConfig).build(),
Collections.singletonList(config));
RollupJobConfig job = createJob(rollupIndex, new GroupConfig(dateHistoConfig), Collections.singletonList(config));
final List<Map<String, Object>> dataset = new ArrayList<>();
dataset.addAll(
Arrays.asList(
@ -265,8 +263,7 @@ public class RollupIndexerIndexingTests extends AggregatorTestCase {
String field = "the_histo";
DateHistogramGroupConfig dateHistoConfig =
new DateHistogramGroupConfig(field, new DateHistogramInterval("1m"), new DateHistogramInterval("1h"), null);
RollupJobConfig job = createJob(rollupIndex, new GroupConfig.Builder().setDateHisto(dateHistoConfig).build(),
Collections.emptyList());
RollupJobConfig job = createJob(rollupIndex, new GroupConfig(dateHistoConfig), Collections.emptyList());
final List<Map<String, Object>> dataset = new ArrayList<>();
long now = System.currentTimeMillis();
dataset.addAll(
@ -347,8 +344,7 @@ public class RollupIndexerIndexingTests extends AggregatorTestCase {
String rollupIndex = randomAlphaOfLengthBetween(5, 10);
String field = "the_histo";
DateHistogramGroupConfig dateHistoConfig = new DateHistogramGroupConfig(field, new DateHistogramInterval("1d"), null, timeZone);
RollupJobConfig job = createJob(rollupIndex, new GroupConfig.Builder().setDateHisto(dateHistoConfig).build(),
Collections.emptyList());
RollupJobConfig job = createJob(rollupIndex, new GroupConfig(dateHistoConfig), Collections.emptyList());
executeTestCase(dataset, job, now, (resp) -> {
assertThat(resp.size(), equalTo(1));
@ -410,8 +406,7 @@ public class RollupIndexerIndexingTests extends AggregatorTestCase {
DateHistogramGroupConfig dateHistoConfig =
new DateHistogramGroupConfig(timestampField, new DateHistogramInterval(timeInterval));
MetricConfig metricConfig = new MetricConfig(valueField, Collections.singletonList("avg"));
RollupJobConfig job = createJob(rollupIndex, new GroupConfig.Builder().setDateHisto(dateHistoConfig).build(),
Collections.singletonList(metricConfig));
RollupJobConfig job = createJob(rollupIndex, new GroupConfig(dateHistoConfig), Collections.singletonList(metricConfig));
final List<Map<String, Object>> dataset = new ArrayList<>();
int numDocs = randomIntBetween(1,100);
@ -477,7 +472,7 @@ public class RollupIndexerIndexingTests extends AggregatorTestCase {
Directory dir = index(docs, fieldTypeLookup);
IndexReader reader = DirectoryReader.open(dir);
IndexSearcher searcher = new IndexSearcher(reader);
String dateHistoField = config.getGroupConfig().getDateHisto().getField();
String dateHistoField = config.getGroupConfig().getDateHistogram().getField();
final ExecutorService executor = Executors.newFixedThreadPool(1);
try {
RollupJob job = new RollupJob(config, Collections.emptyMap());
@ -499,14 +494,14 @@ public class RollupIndexerIndexingTests extends AggregatorTestCase {
*/
private Map<String, MappedFieldType> createFieldTypes(RollupJobConfig job) {
Map<String, MappedFieldType> fieldTypes = new HashMap<>();
MappedFieldType fieldType = new DateFieldMapper.Builder(job.getGroupConfig().getDateHisto().getField())
MappedFieldType fieldType = new DateFieldMapper.Builder(job.getGroupConfig().getDateHistogram().getField())
.dateTimeFormatter(Joda.forPattern(randomFrom("basic_date", "date_optional_time", "epoch_second")))
.build(new Mapper.BuilderContext(settings.getSettings(), new ContentPath(0)))
.fieldType();
fieldTypes.put(fieldType.name(), fieldType);
if (job.getGroupConfig().getHisto() != null) {
for (String field : job.getGroupConfig().getHisto().getFields()) {
if (job.getGroupConfig().getHistogram() != null) {
for (String field : job.getGroupConfig().getHistogram().getFields()) {
MappedFieldType ft = new NumberFieldMapper.Builder(field, NumberFieldMapper.NumberType.LONG)
.build(new Mapper.BuilderContext(settings.getSettings(), new ContentPath(0)))
.fieldType();

View File

@ -273,7 +273,7 @@ public class RollupIndexerStateTests extends ESTestCase {
// and make sure the appropriate error is thrown
when(config.getGroupConfig()).then((Answer<GroupConfig>) invocationOnMock -> {
state.set(IndexerState.STOPPED);
return ConfigTestHelpers.getGroupConfig().build();
return ConfigTestHelpers.randomGroupConfig(random());
});
RollupJob job = new RollupJob(config, Collections.emptyMap());