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

View File

@ -54,7 +54,7 @@ import static org.elasticsearch.common.xcontent.ObjectParser.ValueType;
*/ */
public class DateHistogramGroupConfig implements Writeable, ToXContentObject { 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 INTERVAL = "interval";
private static final String FIELD = "field"; private static final String FIELD = "field";
public static final String TIME_ZONE = "time_zone"; 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.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; 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.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import static java.util.Arrays.asList; 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. * 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 { 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 { static {
PARSER.declareObject(GroupConfig.Builder::setDateHisto, (p,c) -> DateHistogramGroupConfig.fromXContent(p), DATE_HISTO); PARSER = new ConstructingObjectParser<>(NAME, args ->
PARSER.declareObject(GroupConfig.Builder::setHisto, (p,c) -> HistogramGroupConfig.fromXContent(p), HISTO); new GroupConfig((DateHistogramGroupConfig) args[0], (HistogramGroupConfig) args[1], (TermsGroupConfig) args[2]));
PARSER.declareObject(GroupConfig.Builder::setTerms, (p,c) -> TermsGroupConfig.fromXContent(p), TERMS); 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) { private final DateHistogramGroupConfig dateHistogram;
this.dateHisto = Objects.requireNonNull(dateHisto, "A date_histogram group is mandatory"); private final @Nullable HistogramGroupConfig histogram;
this.histo = histo; 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; this.terms = terms;
} }
GroupConfig(StreamInput in) throws IOException { GroupConfig(final StreamInput in) throws IOException {
dateHisto = new DateHistogramGroupConfig(in); dateHistogram = new DateHistogramGroupConfig(in);
histo = in.readOptionalWriteable(HistogramGroupConfig::new); histogram = in.readOptionalWriteable(HistogramGroupConfig::new);
terms = in.readOptionalWriteable(TermsGroupConfig::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() { public TermsGroupConfig getTerms() {
return terms; return terms;
} }
public Set<String> getAllFields() { public Set<String> getAllFields() {
Set<String> fields = new HashSet<>(); Set<String> fields = new HashSet<>();
fields.add(dateHisto.getField()); fields.add(dateHistogram.getField());
if (histo != null) { if (histogram != null) {
fields.addAll(asList(histo.getFields())); fields.addAll(asList(histogram.getFields()));
} }
if (terms != null) { if (terms != null) {
fields.addAll(asList(terms.getFields())); fields.addAll(asList(terms.getFields()));
} }
return fields; return Collections.unmodifiableSet(fields);
} }
public void validateMappings(Map<String, Map<String, FieldCapabilities>> fieldCapsResponse, public void validateMappings(final Map<String, Map<String, FieldCapabilities>> fieldCapsResponse,
ActionRequestValidationException validationException) { final ActionRequestValidationException validationException) {
dateHisto.validateMappings(fieldCapsResponse, validationException); dateHistogram.validateMappings(fieldCapsResponse, validationException);
if (histo != null) { if (histogram != null) {
histo.validateMappings(fieldCapsResponse, validationException); histogram.validateMappings(fieldCapsResponse, validationException);
} }
if (terms != null) { if (terms != null) {
terms.validateMappings(fieldCapsResponse, validationException); terms.validateMappings(fieldCapsResponse, validationException);
@ -105,44 +130,43 @@ public class GroupConfig implements Writeable, ToXContentObject {
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(); builder.startObject();
builder.field(DATE_HISTO.getPreferredName(), dateHisto); {
if (histo != null) { builder.field(DateHistogramGroupConfig.NAME, dateHistogram);
builder.field(HISTO.getPreferredName(), histo); if (histogram != null) {
builder.field(HistogramGroupConfig.NAME, histogram);
}
if (terms != null) {
builder.field(TermsGroupConfig.NAME, terms);
}
} }
if (terms != null) { return builder.endObject();
builder.field(TERMS.getPreferredName(), terms);
}
builder.endObject();
return builder;
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(final StreamOutput out) throws IOException {
dateHisto.writeTo(out); dateHistogram.writeTo(out);
out.writeOptionalWriteable(histo); out.writeOptionalWriteable(histogram);
out.writeOptionalWriteable(terms); out.writeOptionalWriteable(terms);
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(final Object other) {
if (this == other) { if (this == other) {
return true; return true;
} }
if (other == null || getClass() != other.getClass()) { if (other == null || getClass() != other.getClass()) {
return false; return false;
} }
GroupConfig that = (GroupConfig) other; final GroupConfig that = (GroupConfig) other;
return Objects.equals(dateHistogram, that.dateHistogram)
return Objects.equals(this.dateHisto, that.dateHisto) && Objects.equals(histogram, that.histogram)
&& Objects.equals(this.histo, that.histo) && Objects.equals(terms, that.terms);
&& Objects.equals(this.terms, that.terms);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(dateHisto, histo, terms); return Objects.hash(dateHistogram, histogram, terms);
} }
@Override @Override
@ -150,43 +174,7 @@ public class GroupConfig implements Writeable, ToXContentObject {
return Strings.toString(this, true, true); return Strings.toString(this, true, true);
} }
public static class Builder { public static GroupConfig fromXContent(final XContentParser parser) throws IOException {
private DateHistogramGroupConfig dateHisto; return PARSER.parse(parser, null);
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);
}
} }
} }

View File

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

View File

@ -62,7 +62,7 @@ public class RollupJobConfig implements NamedWriteable, ToXContentObject {
static { static {
PARSER.declareString(RollupJobConfig.Builder::setId, RollupField.ID); 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.declareObjectArray(RollupJobConfig.Builder::setMetricsConfig, (p, c) -> MetricConfig.fromXContent(p), METRICS);
PARSER.declareString((params, val) -> PARSER.declareString((params, val) ->
params.setTimeout(TimeValue.parseTimeValue(val, TIMEOUT.getPreferredName())), TIMEOUT); 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 { 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 String FIELDS = "fields";
private static final List<String> FLOAT_TYPES = Arrays.asList("half_float", "float", "double", "scaled_float"); 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); String indexPattern = ESTestCase.randomAlphaOfLengthBetween(1,10);
builder.setIndexPattern(indexPattern); builder.setIndexPattern(indexPattern);
builder.setRollupIndex("rollup_" + indexPattern); // to ensure the index pattern != rollup index 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)); builder.setPageSize(ESTestCase.randomIntBetween(1,10));
if (ESTestCase.randomBoolean()) { if (ESTestCase.randomBoolean()) {
builder.setMetricsConfig(randomMetricsConfigs(ESTestCase.random())); builder.setMetricsConfig(randomMetricsConfigs(ESTestCase.random()));
@ -45,16 +45,11 @@ public class ConfigTestHelpers {
return builder; return builder;
} }
public static GroupConfig.Builder getGroupConfig() { public static GroupConfig randomGroupConfig(final Random random) {
GroupConfig.Builder groupBuilder = new GroupConfig.Builder(); DateHistogramGroupConfig dateHistogram = randomDateHistogramGroupConfig(random);
groupBuilder.setDateHisto(randomDateHistogramGroupConfig(ESTestCase.random())); HistogramGroupConfig histogram = random.nextBoolean() ? randomHistogramGroupConfig(random) : null;
if (ESTestCase.randomBoolean()) { TermsGroupConfig terms = random.nextBoolean() ? randomTermsGroupConfig(random) : null;
groupBuilder.setHisto(randomHistogramGroupConfig(ESTestCase.random())); return new GroupConfig(dateHistogram, histogram, terms);
}
if (ESTestCase.randomBoolean()) {
groupBuilder.setTerms(randomTermsGroupConfig(ESTestCase.random()));
}
return groupBuilder;
} }
private static final String[] TIME_SUFFIXES = new String[]{"d", "h", "ms", "s", "m"}; 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.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.test.AbstractSerializingTestCase;
import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomGroupConfig;
public class GroupConfigSerializingTests extends AbstractSerializingTestCase<GroupConfig> { public class GroupConfigSerializingTests extends AbstractSerializingTestCase<GroupConfig> {
@Override @Override
protected GroupConfig doParseInstance(XContentParser parser) throws IOException { protected GroupConfig doParseInstance(final XContentParser parser) throws IOException {
return GroupConfig.PARSER.apply(parser, null).build(); return GroupConfig.fromXContent(parser);
} }
@Override @Override
@ -25,6 +27,6 @@ public class GroupConfigSerializingTests extends AbstractSerializingTestCase<Gro
@Override @Override
protected GroupConfig createTestInstance() { protected GroupConfig createTestInstance() {
return ConfigTestHelpers.getGroupConfig().build(); return randomGroupConfig(random());
} }
} }

View File

@ -89,12 +89,12 @@ class IndexerUtils {
if (k.endsWith("." + DateHistogramAggregationBuilder.NAME)) { if (k.endsWith("." + DateHistogramAggregationBuilder.NAME)) {
assert v != null; assert v != null;
doc.put(k + "." + RollupField.TIMESTAMP, v); doc.put(k + "." + RollupField.TIMESTAMP, v);
doc.put(k + "." + RollupField.INTERVAL, groupConfig.getDateHisto().getInterval()); doc.put(k + "." + RollupField.INTERVAL, groupConfig.getDateHistogram().getInterval());
doc.put(k + "." + DateHistogramGroupConfig.TIME_ZONE, groupConfig.getDateHisto().getTimeZone().toString()); doc.put(k + "." + DateHistogramGroupConfig.TIME_ZONE, groupConfig.getDateHistogram().getTimeZone());
idGenerator.add((Long)v); idGenerator.add((Long)v);
} else if (k.endsWith("." + HistogramAggregationBuilder.NAME)) { } else if (k.endsWith("." + HistogramAggregationBuilder.NAME)) {
doc.put(k + "." + RollupField.VALUE, v); 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) { if (v == null) {
idGenerator.addNull(); idGenerator.addNull();
} else { } 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. // 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. // 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); long rounded = dateHisto.createRounding().round(now);
if (dateHisto.getDelay() != null) { if (dateHisto.getDelay() != null) {
// if the job has a delay we filter all documents that appear before it. // 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 // Add all the agg builders to our request in order: date_histo -> histo -> terms
if (groupConfig != null) { if (groupConfig != null) {
builders.addAll(groupConfig.getDateHisto().toBuilders()); builders.addAll(groupConfig.getDateHistogram().toBuilders());
metadata.putAll(groupConfig.getDateHisto().getMetadata()); metadata.putAll(groupConfig.getDateHistogram().getMetadata());
if (groupConfig.getHisto() != null) { if (groupConfig.getHistogram() != null) {
builders.addAll(groupConfig.getHisto().toBuilders()); builders.addAll(groupConfig.getHistogram().toBuilders());
metadata.putAll(groupConfig.getHisto().getMetadata()); metadata.putAll(groupConfig.getHistogram().getMetadata());
} }
if (groupConfig.getTerms() != null) { if (groupConfig.getTerms() != null) {
builders.addAll(groupConfig.getTerms().toBuilders()); builders.addAll(groupConfig.getTerms().toBuilders());
@ -426,7 +426,7 @@ public abstract class RollupIndexer {
*/ */
private QueryBuilder createBoundaryQuery(Map<String, Object> position) { private QueryBuilder createBoundaryQuery(Map<String, Object> position) {
assert maxBoundary < Long.MAX_VALUE; assert maxBoundary < Long.MAX_VALUE;
DateHistogramGroupConfig dateHisto = job.getConfig().getGroupConfig().getDateHisto(); DateHistogramGroupConfig dateHisto = job.getConfig().getGroupConfig().getDateHistogram();
String fieldName = dateHisto.getField(); String fieldName = dateHisto.getField();
String rollupFieldName = fieldName + "." + DateHistogramAggregationBuilder.NAME; String rollupFieldName = fieldName + "." + DateHistogramAggregationBuilder.NAME;
long lowerBound = 0L; long lowerBound = 0L;

View File

@ -36,14 +36,13 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testOneMatch() { public void testOneMatch() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(group);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap); Set<RollupJobCaps> caps = singletonSet(cap);
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo") DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
.dateHistogramInterval(job.getGroupConfig().getDateHisto().getInterval()); .dateHistogramInterval(job.getGroupConfig().getDateHistogram().getInterval());
Set<RollupJobCaps> bestCaps = RollupJobIdentifierUtils.findBestJobs(builder, caps); Set<RollupJobCaps> bestCaps = RollupJobIdentifierUtils.findBestJobs(builder, caps);
assertThat(bestCaps.size(), equalTo(1)); assertThat(bestCaps.size(), equalTo(1));
@ -51,9 +50,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testBiggerButCompatibleInterval() { public void testBiggerButCompatibleInterval() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(group);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap); Set<RollupJobCaps> caps = singletonSet(cap);
@ -66,9 +64,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testIncompatibleInterval() { public void testIncompatibleInterval() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"))); job.setGroupConfig(group);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap); Set<RollupJobCaps> caps = singletonSet(cap);
@ -82,9 +79,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testBadTimeZone() { public void testBadTimeZone() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"), null, "EST"));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"), null, "EST")); job.setGroupConfig(group);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap); Set<RollupJobCaps> caps = singletonSet(cap);
@ -99,9 +95,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testMetricOnlyAgg() { public void testMetricOnlyAgg() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(group);
job.setGroupConfig(group.build());
job.setMetricsConfig(singletonList(new MetricConfig("bar", singletonList("max")))); job.setMetricsConfig(singletonList(new MetricConfig("bar", singletonList("max"))));
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap); Set<RollupJobCaps> caps = singletonSet(cap);
@ -114,9 +109,8 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testOneOfTwoMatchingCaps() { public void testOneOfTwoMatchingCaps() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(group);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap); Set<RollupJobCaps> caps = singletonSet(cap);
@ -131,21 +125,15 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testTwoJobsSameRollupIndex() { public void testTwoJobsSameRollupIndex() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(group);
group.setTerms(null);
group.setHisto(null);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(2); Set<RollupJobCaps> caps = new HashSet<>(2);
caps.add(cap); caps.add(cap);
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2"); RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2");
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig(); final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job2.setGroupConfig(group);
group2.setTerms(null);
group2.setHisto(null);
job2.setGroupConfig(group.build());
job2.setRollupIndex(job.getRollupIndex()); job2.setRollupIndex(job.getRollupIndex());
RollupJobCaps cap2 = new RollupJobCaps(job2.build()); RollupJobCaps cap2 = new RollupJobCaps(job2.build());
caps.add(cap2); caps.add(cap2);
@ -161,18 +149,16 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testTwoJobsButBothPartialMatches() { public void testTwoJobsButBothPartialMatches() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(group);
job.setGroupConfig(group.build());
job.setMetricsConfig(singletonList(new MetricConfig("bar", singletonList("max")))); job.setMetricsConfig(singletonList(new MetricConfig("bar", singletonList("max"))));
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(2); Set<RollupJobCaps> caps = new HashSet<>(2);
caps.add(cap); caps.add(cap);
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2"); RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2");
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig(); final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job2.setGroupConfig(group);
job2.setGroupConfig(group.build());
job.setMetricsConfig(singletonList(new MetricConfig("bar", singletonList("min")))); job.setMetricsConfig(singletonList(new MetricConfig("bar", singletonList("min"))));
RollupJobCaps cap2 = new RollupJobCaps(job2.build()); RollupJobCaps cap2 = new RollupJobCaps(job2.build());
caps.add(cap2); caps.add(cap2);
@ -189,19 +175,13 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testComparableDifferentDateIntervals() { public void testComparableDifferentDateIntervals() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))) job.setGroupConfig(group);
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex()); RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig(); final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d")));
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"))) job2.setGroupConfig(group2);
.setHisto(null)
.setTerms(null);
job2.setGroupConfig(group2.build());
RollupJobCaps cap2 = new RollupJobCaps(job2.build()); RollupJobCaps cap2 = new RollupJobCaps(job2.build());
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo") DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
@ -218,19 +198,13 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testComparableDifferentDateIntervalsOnlyOneWorks() { public void testComparableDifferentDateIntervalsOnlyOneWorks() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))) job.setGroupConfig(group);
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex()); RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig(); final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d")));
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"))) job2.setGroupConfig(group2);
.setHisto(null)
.setTerms(null);
job2.setGroupConfig(group2.build());
RollupJobCaps cap2 = new RollupJobCaps(job2.build()); RollupJobCaps cap2 = new RollupJobCaps(job2.build());
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo") DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
@ -247,19 +221,14 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testComparableNoHistoVsHisto() { public void testComparableNoHistoVsHisto() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))) job.setGroupConfig(group);
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex()); RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig(); final HistogramGroupConfig histoConfig = new HistogramGroupConfig(100L, "bar");
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))) final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")), histoConfig, null);
.setHisto(new HistogramGroupConfig(100L, "bar")) job2.setGroupConfig(group2);
.setTerms(null);
job2.setGroupConfig(group2.build());
RollupJobCaps cap2 = new RollupJobCaps(job2.build()); RollupJobCaps cap2 = new RollupJobCaps(job2.build());
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo") DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
@ -277,19 +246,14 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
public void testComparableNoTermsVsTerms() { public void testComparableNoTermsVsTerms() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))) job.setGroupConfig(group);
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex()); RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig(); final TermsGroupConfig termsConfig = new TermsGroupConfig("bar");
group2.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))) final GroupConfig group2 = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")), null, termsConfig);
.setHisto(null) job2.setGroupConfig(group2);
.setTerms(new TermsGroupConfig("bar"));
job2.setGroupConfig(group2.build());
RollupJobCaps cap2 = new RollupJobCaps(job2.build()); RollupJobCaps cap2 = new RollupJobCaps(job2.build());
DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo") DateHistogramAggregationBuilder builder = new DateHistogramAggregationBuilder("foo").field("foo")
@ -313,11 +277,12 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field")); .subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo") RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig() .setGroupConfig(new GroupConfig(
// NOTE same name but wrong type // NOTE same name but wrong type
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID())) new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()),
.setHisto(new HistogramGroupConfig(1L, "baz")) // <-- NOTE right type but wrong name new HistogramGroupConfig(1L, "baz"), // <-- NOTE right type but wrong name
.build()) null
))
.setMetricsConfig( .setMetricsConfig(
Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg")))) Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg"))))
.build(); .build();
@ -336,9 +301,9 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field")); .subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo") RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig() .setGroupConfig(new GroupConfig(
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID())) new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID())
.build()) ))
.setMetricsConfig( .setMetricsConfig(
Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg")))) Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg"))))
.build(); .build();
@ -357,10 +322,10 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field")); .subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo") RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig() .setGroupConfig(new GroupConfig(
// interval in job is much higher than agg interval above // interval in job is much higher than agg interval above
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("100d"), null, DateTimeZone.UTC.getID())) new DateHistogramGroupConfig("foo", new DateHistogramInterval("100d"), null, DateTimeZone.UTC.getID())
.build()) ))
.build(); .build();
Set<RollupJobCaps> caps = singletonSet(new RollupJobCaps(job)); Set<RollupJobCaps> caps = singletonSet(new RollupJobCaps(job));
@ -377,10 +342,10 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field")); .subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo") RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig() .setGroupConfig(new GroupConfig(
// NOTE different field from the one in the query // NOTE different field from the one in the query
.setDateHisto(new DateHistogramGroupConfig("bar", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID())) new DateHistogramGroupConfig("bar", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID())
.build()) ))
.setMetricsConfig( .setMetricsConfig(
Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg")))) Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg"))))
.build(); .build();
@ -399,10 +364,11 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field")); .subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo") RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig() .setGroupConfig(new GroupConfig(
.setDateHisto(new DateHistogramGroupConfig("bar", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID())) new DateHistogramGroupConfig("bar", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()),
.setHisto(new HistogramGroupConfig(1L, "baz")) // <-- NOTE right type but wrong name new HistogramGroupConfig(1L, "baz"), // <-- NOTE right type but wrong name
.build()) null
))
.setMetricsConfig( .setMetricsConfig(
Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg")))) Arrays.asList(new MetricConfig("max_field", singletonList("max")), new MetricConfig("avg_field", singletonList("avg"))))
.build(); .build();
@ -421,10 +387,11 @@ public class RollupJobIdentifierUtilTests extends ESTestCase {
.subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field")); .subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo") RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig() .setGroupConfig(new GroupConfig(
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID())) new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()),
.setHisto(new HistogramGroupConfig(1L, "baz")) // <-- NOTE right type but wrong name new HistogramGroupConfig(1L, "baz"), // <-- NOTE right type but wrong name
.build()) null
))
.build(); .build();
Set<RollupJobCaps> caps = singletonSet(new RollupJobCaps(job)); 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.core.rollup.job.TermsGroupConfig;
import org.elasticsearch.xpack.rollup.Rollup; import org.elasticsearch.xpack.rollup.Rollup;
import org.hamcrest.core.IsEqual; import org.hamcrest.core.IsEqual;
import org.joda.time.DateTimeZone; import org.junit.Before;
import org.mockito.Mockito; import org.mockito.Mockito;
import java.io.IOException; import java.io.IOException;
@ -81,6 +81,9 @@ import static org.mockito.Mockito.when;
public class SearchActionTests extends ESTestCase { public class SearchActionTests extends ESTestCase {
private NamedWriteableRegistry namedWriteableRegistry; private NamedWriteableRegistry namedWriteableRegistry;
@Override
@Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
IndicesModule indicesModule = new IndicesModule(Collections.emptyList()); IndicesModule indicesModule = new IndicesModule(Collections.emptyList());
@ -119,9 +122,8 @@ public class SearchActionTests extends ESTestCase {
public void testRange() { public void testRange() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(groupConfig);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(); Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap); caps.add(cap);
@ -132,9 +134,8 @@ public class SearchActionTests extends ESTestCase {
public void testRangeNullTimeZone() { public void testRangeNullTimeZone() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(group);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(); Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap); caps.add(cap);
@ -145,9 +146,8 @@ public class SearchActionTests extends ESTestCase {
public void testRangeWrongTZ() { public void testRangeWrongTZ() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(group);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(); Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap); caps.add(cap);
@ -159,9 +159,9 @@ public class SearchActionTests extends ESTestCase {
public void testTermQuery() { public void testTermQuery() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final TermsGroupConfig termsConfig = new TermsGroupConfig("foo");
group.setTerms(new TermsGroupConfig("foo")); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("date", new DateHistogramInterval("1h")), null, termsConfig);
job.setGroupConfig(group.build()); job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(); Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap); caps.add(cap);
@ -172,9 +172,9 @@ public class SearchActionTests extends ESTestCase {
public void testTermsQuery() { public void testTermsQuery() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final TermsGroupConfig termsConfig = new TermsGroupConfig("foo");
group.setTerms(new TermsGroupConfig("foo")); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("date", new DateHistogramInterval("1h")), null, termsConfig);
job.setGroupConfig(group.build()); job.setGroupConfig(group);
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(); Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap); caps.add(cap);
@ -189,9 +189,8 @@ public class SearchActionTests extends ESTestCase {
public void testCompounds() { public void testCompounds() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(groupConfig);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(); Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap); caps.add(cap);
@ -205,9 +204,8 @@ public class SearchActionTests extends ESTestCase {
public void testMatchAll() { public void testMatchAll() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(groupConfig);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(); Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap); caps.add(cap);
@ -217,10 +215,9 @@ public class SearchActionTests extends ESTestCase {
public void testAmbiguousResolution() { public void testAmbiguousResolution() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final TermsGroupConfig termsConfig = new TermsGroupConfig("foo");
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")), null, termsConfig);
group.setTerms(new TermsGroupConfig("foo")); job.setGroupConfig(group);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = new HashSet<>(); Set<RollupJobCaps> caps = new HashSet<>();
caps.add(cap); caps.add(cap);
@ -368,9 +365,8 @@ public class SearchActionTests extends ESTestCase {
public void testGood() { public void testGood() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))); job.setGroupConfig(groupConfig);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
Set<RollupJobCaps> caps = singletonSet(cap); Set<RollupJobCaps> caps = singletonSet(cap);
@ -385,7 +381,7 @@ public class SearchActionTests extends ESTestCase {
source.query(getQueryBuilder(1)); source.query(getQueryBuilder(1));
source.size(0); source.size(0);
source.aggregation(new DateHistogramAggregationBuilder("foo").field("foo") source.aggregation(new DateHistogramAggregationBuilder("foo").field("foo")
.dateHistogramInterval(job.getGroupConfig().getDateHisto().getInterval())); .dateHistogramInterval(job.getGroupConfig().getDateHistogram().getInterval()));
SearchRequest request = new SearchRequest(combinedIndices, source); SearchRequest request = new SearchRequest(combinedIndices, source);
MultiSearchRequest msearch = TransportRollupSearchAction.createMSearchRequest(request, namedWriteableRegistry, ctx); MultiSearchRequest msearch = TransportRollupSearchAction.createMSearchRequest(request, namedWriteableRegistry, ctx);
@ -414,9 +410,7 @@ public class SearchActionTests extends ESTestCase {
SearchRequest request = new SearchRequest(combinedIndices, source); SearchRequest request = new SearchRequest(combinedIndices, source);
RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo") RollupJobConfig job = ConfigTestHelpers.getRollupJob("foo")
.setGroupConfig(ConfigTestHelpers.getGroupConfig() .setGroupConfig(new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, "UTC")))
.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1d"), null, DateTimeZone.UTC.getID()))
.build())
.build(); .build();
Set<RollupJobCaps> caps = singletonSet(new RollupJobCaps(job)); Set<RollupJobCaps> caps = singletonSet(new RollupJobCaps(job));
@ -439,15 +433,12 @@ public class SearchActionTests extends ESTestCase {
public void testTwoMatchingJobs() { public void testTwoMatchingJobs() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))) job.setGroupConfig(group);
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex()); RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
job2.setGroupConfig(group.build()); job2.setGroupConfig(group);
// so that the jobs aren't exactly equal // so that the jobs aren't exactly equal
job2.setMetricsConfig(ConfigTestHelpers.randomMetricsConfigs(random())); job2.setMetricsConfig(ConfigTestHelpers.randomMetricsConfigs(random()));
@ -468,7 +459,7 @@ public class SearchActionTests extends ESTestCase {
source.query(getQueryBuilder(1)); source.query(getQueryBuilder(1));
source.size(0); source.size(0);
source.aggregation(new DateHistogramAggregationBuilder("foo").field("foo") source.aggregation(new DateHistogramAggregationBuilder("foo").field("foo")
.dateHistogramInterval(job.getGroupConfig().getDateHisto().getInterval())); .dateHistogramInterval(job.getGroupConfig().getDateHistogram().getInterval()));
SearchRequest request = new SearchRequest(combinedIndices, source); SearchRequest request = new SearchRequest(combinedIndices, source);
MultiSearchRequest msearch = TransportRollupSearchAction.createMSearchRequest(request, namedWriteableRegistry, ctx); MultiSearchRequest msearch = TransportRollupSearchAction.createMSearchRequest(request, namedWriteableRegistry, ctx);
@ -489,19 +480,13 @@ public class SearchActionTests extends ESTestCase {
public void testTwoMatchingJobsOneBetter() { public void testTwoMatchingJobsOneBetter() {
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo"); RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
GroupConfig.Builder group = ConfigTestHelpers.getGroupConfig(); final GroupConfig group = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h")));
group.setDateHisto(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"))) job.setGroupConfig(group);
.setHisto(null)
.setTerms(null);
job.setGroupConfig(group.build());
RollupJobCaps cap = new RollupJobCaps(job.build()); RollupJobCaps cap = new RollupJobCaps(job.build());
RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex()); RollupJobConfig.Builder job2 = ConfigTestHelpers.getRollupJob("foo2").setRollupIndex(job.getRollupIndex());
GroupConfig.Builder group2 = ConfigTestHelpers.getGroupConfig(); final GroupConfig group2 = new GroupConfig(group.getDateHistogram(), randomHistogramGroupConfig(random()), null);
group2.setDateHisto(group.getDateHisto()) job2.setGroupConfig(group2);
.setHisto(randomHistogramGroupConfig(random()))
.setTerms(null);
job2.setGroupConfig(group2.build());
RollupJobCaps cap2 = new RollupJobCaps(job2.build()); RollupJobCaps cap2 = new RollupJobCaps(job2.build());
Set<RollupJobCaps> caps = new HashSet<>(2); Set<RollupJobCaps> caps = new HashSet<>(2);
@ -519,7 +504,7 @@ public class SearchActionTests extends ESTestCase {
source.query(getQueryBuilder(1)); source.query(getQueryBuilder(1));
source.size(0); source.size(0);
source.aggregation(new DateHistogramAggregationBuilder("foo").field("foo") source.aggregation(new DateHistogramAggregationBuilder("foo").field("foo")
.dateHistogramInterval(job.getGroupConfig().getDateHisto().getInterval())); .dateHistogramInterval(job.getGroupConfig().getDateHistogram().getInterval()));
SearchRequest request = new SearchRequest(combinedIndices, source); SearchRequest request = new SearchRequest(combinedIndices, source);
MultiSearchRequest msearch = TransportRollupSearchAction.createMSearchRequest(request, namedWriteableRegistry, ctx); 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.emptyList;
import static java.util.Collections.singletonList; 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; import static org.hamcrest.Matchers.equalTo;
//TODO split this into dedicated unit test classes (one for each config object) //TODO split this into dedicated unit test classes (one for each config object)
public class ConfigTests extends ESTestCase { public class ConfigTests extends ESTestCase {
@ -43,22 +45,14 @@ public class ConfigTests extends ESTestCase {
} }
public void testEmptyGroup() { public void testEmptyGroup() {
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig(); Exception e = expectThrows(IllegalArgumentException.class, () -> new GroupConfig(null, null, null));
groupConfig.setDateHisto(null); assertThat(e.getMessage(), equalTo("Date histogram must not be null"));
groupConfig.setTerms(null);
groupConfig.setHisto(null);
Exception e = expectThrows(IllegalArgumentException.class, groupConfig::build);
assertThat(e.getMessage(), equalTo("A date_histogram group is mandatory"));
} }
public void testNoDateHisto() { public void testNoDateHisto() {
GroupConfig.Builder groupConfig = new GroupConfig.Builder(); Exception e = expectThrows(IllegalArgumentException.class,
groupConfig.setTerms(ConfigTestHelpers.randomTermsGroupConfig(random())); () -> new GroupConfig(null, randomHistogramGroupConfig(random()), randomTermsGroupConfig(random())));
groupConfig.setHisto(ConfigTestHelpers.randomHistogramGroupConfig(random())); assertThat(e.getMessage(), equalTo("Date histogram must not be null"));
Exception e = expectThrows(IllegalArgumentException.class, groupConfig::build);
assertThat(e.getMessage(), equalTo("A date_histogram group is mandatory"));
} }
public void testEmptyGroupAndMetrics() { 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.avg.AvgAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder; 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.RollupField;
import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig;
import org.elasticsearch.xpack.core.rollup.job.GroupConfig; import org.elasticsearch.xpack.core.rollup.job.GroupConfig;
@ -54,8 +53,10 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomHistogramGroupConfig;
import static java.util.Collections.singletonList; 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.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -112,8 +113,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close(); indexReader.close();
directory.close(); directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, final GroupConfig groupConfig = randomGroupConfig(random());
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean()); List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(numDocs)); assertThat(docs.size(), equalTo(numDocs));
for (IndexRequest doc : docs) { for (IndexRequest doc : docs) {
@ -179,8 +180,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close(); indexReader.close();
directory.close(); directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, final GroupConfig groupConfig = randomGroupConfig(random());
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean()); List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(numDocs)); assertThat(docs.size(), equalTo(numDocs));
for (IndexRequest doc : docs) { for (IndexRequest doc : docs) {
@ -235,8 +236,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close(); indexReader.close();
directory.close(); directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, final GroupConfig groupConfig = randomGroupConfig(random());
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean()); List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(numDocs)); assertThat(docs.size(), equalTo(numDocs));
for (IndexRequest doc : docs) { for (IndexRequest doc : docs) {
@ -301,8 +302,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close(); indexReader.close();
directory.close(); directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, final GroupConfig groupConfig = randomGroupConfig(random());
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean()); List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(numDocs)); assertThat(docs.size(), equalTo(numDocs));
for (IndexRequest doc : docs) { 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 // The content of the config don't actually matter for this test
// because the test is just looking at agg keys // because the test is just looking at agg keys
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig(); GroupConfig groupConfig = new GroupConfig(randomDateHistogramGroupConfig(random()), new HistogramGroupConfig(123L, "abc"), null);
groupConfig.setHisto(new HistogramGroupConfig(123L, "abc")); List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(), groupConfig, "foo", false);
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(),
groupConfig.build(), "foo", false);
assertThat(docs.size(), equalTo(1)); assertThat(docs.size(), equalTo(1));
assertThat(docs.get(0).id(), equalTo("1237859798")); assertThat(docs.get(0).id(), equalTo("1237859798"));
} }
@ -400,11 +398,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
return foos; return foos;
}); });
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig(); GroupConfig groupConfig = new GroupConfig(randomDateHistogramGroupConfig(random()), new HistogramGroupConfig(1L, "abc"), null);
groupConfig.setHisto(new HistogramGroupConfig(1, "abc")); List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(), groupConfig, "foo", true);
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(),
groupConfig.build(), "foo", true);
assertThat(docs.size(), equalTo(1)); assertThat(docs.size(), equalTo(1));
assertThat(docs.get(0).id(), equalTo("foo$c9LcrFqeFW92uN_Z7sv1hA")); assertThat(docs.get(0).id(), equalTo("foo$c9LcrFqeFW92uN_Z7sv1hA"));
} }
@ -453,11 +448,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
return foos; return foos;
}); });
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig(); GroupConfig groupConfig = new GroupConfig(randomDateHistogramGroupConfig(random()), new HistogramGroupConfig(1, "abc"), null);
groupConfig.setHisto(new HistogramGroupConfig(1, "abc")); List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(), groupConfig, "foo", true);
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(),
groupConfig.build(), "foo", true);
assertThat(docs.size(), equalTo(1)); assertThat(docs.size(), equalTo(1));
assertThat(docs.get(0).id(), equalTo("foo$VAFKZpyaEqYRPLyic57_qw")); assertThat(docs.get(0).id(), equalTo("foo$VAFKZpyaEqYRPLyic57_qw"));
} }
@ -483,11 +475,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
return foos; return foos;
}); });
GroupConfig.Builder groupConfig = ConfigTestHelpers.getGroupConfig(); GroupConfig groupConfig = new GroupConfig(randomDateHistogramGroupConfig(random()), randomHistogramGroupConfig(random()), null);
groupConfig.setHisto(randomHistogramGroupConfig(random())); List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(), groupConfig, "foo", randomBoolean());
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, "foo", new RollupJobStats(),
groupConfig.build(), "foo", randomBoolean());
assertThat(docs.size(), equalTo(1)); assertThat(docs.size(), equalTo(1));
assertFalse(Strings.isNullOrEmpty(docs.get(0).id())); assertFalse(Strings.isNullOrEmpty(docs.get(0).id()));
} }
@ -548,8 +537,8 @@ public class IndexerUtilsTests extends AggregatorTestCase {
indexReader.close(); indexReader.close();
directory.close(); directory.close();
List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, final GroupConfig groupConfig = randomGroupConfig(random());
ConfigTestHelpers.getGroupConfig().build(), "foo", randomBoolean()); List<IndexRequest> docs = IndexerUtils.processBuckets(composite, indexName, stats, groupConfig, "foo", randomBoolean());
assertThat(docs.size(), equalTo(6)); assertThat(docs.size(), equalTo(6));
for (IndexRequest doc : docs) { for (IndexRequest doc : docs) {

View File

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

View File

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