From ec5aa34d174084eadd369888b41d5e738f236189 Mon Sep 17 00:00:00 2001 From: Dimitrios Athanasiou Date: Tue, 29 Nov 2016 18:28:31 +0000 Subject: [PATCH] Rename epochStart/epochEnd to start/end in result query builders Original commit: elastic/x-pack-elasticsearch@f4fdd64278b9f87e81f2fd682b4dcb3eba2e5dd6 --- .../prelert/action/GetInfluencersAction.java | 2 +- .../job/persistence/BucketsQueryBuilder.java | 28 +++--- .../persistence/ElasticsearchJobProvider.java | 8 +- .../persistence/InfluencersQueryBuilder.java | 46 +++++----- .../job/persistence/RecordsQueryBuilder.java | 90 +++++++------------ .../persistence/BucketsQueryBuilderTests.java | 8 +- .../ElasticsearchJobProviderTests.java | 2 +- .../InfluencersQueryBuilderTests.java | 28 +++--- 8 files changed, 93 insertions(+), 119 deletions(-) diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetInfluencersAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetInfluencersAction.java index b52eee5615e..03775f9c03d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetInfluencersAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetInfluencersAction.java @@ -319,7 +319,7 @@ extends Action listener) { InfluencersQueryBuilder.InfluencersQuery query = new InfluencersQueryBuilder().includeInterim(request.includeInterim) - .epochStart(request.start).epochEnd(request.end).from(request.pageParams.getFrom()).size(request.pageParams.getSize()) + .start(request.start).end(request.end).from(request.pageParams.getFrom()).size(request.pageParams.getSize()) .anomalyScoreThreshold(request.anomalyScoreFilter).sortField(request.sort).sortDescending(request.decending).build(); QueryPage page = jobProvider.influencers(request.jobId, query); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilder.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilder.java index 0f45dd71a2a..7ba9be31e27 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilder.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilder.java @@ -5,8 +5,8 @@ */ package org.elasticsearch.xpack.prelert.job.persistence; -import org.elasticsearch.xpack.prelert.job.results.Bucket; import org.elasticsearch.common.Strings; +import org.elasticsearch.xpack.prelert.job.results.Bucket; import java.util.Objects; @@ -23,10 +23,10 @@ import java.util.Objects; * this value. Default = 0.0 *
  • normalizedProbabilityThreshold- Return only buckets with a * maxNormalizedProbability >= this value. Default = 0.0
  • - *
  • epochStart- The start bucket time. A bucket with this timestamp will be + *
  • start- The start bucket time. A bucket with this timestamp will be * included in the results. If 0 all buckets up to endEpochMs are * returned. Default = -1
  • - *
  • epochEnd- The end bucket timestamp buckets up to but NOT including this + *
  • end- The end bucket timestamp buckets up to but NOT including this * timestamp are returned. If 0 all buckets from startEpochMs are * returned. Default = -1
  • *
  • partitionValue Set the bucket's max normalised probability to this @@ -92,7 +92,7 @@ public final class BucketsQueryBuilder { * If startTime <= 0 the parameter is not set */ public BucketsQueryBuilder epochStart(String startTime) { - bucketsQuery.epochStart = startTime; + bucketsQuery.start = startTime; return this; } @@ -100,7 +100,7 @@ public final class BucketsQueryBuilder { * If endTime <= 0 the parameter is not set */ public BucketsQueryBuilder epochEnd(String endTime) { - bucketsQuery.epochEnd = endTime; + bucketsQuery.end = endTime; return this; } @@ -120,8 +120,8 @@ public final class BucketsQueryBuilder { private boolean includeInterim = false; private double anomalyScoreFilter = 0.0d; private double normalizedProbability = 0.0d; - private String epochStart; - private String epochEnd; + private String start; + private String end; private String partitionValue = null; private String sortField = Bucket.TIMESTAMP.getPreferredName(); private boolean sortDescending = false; @@ -150,12 +150,12 @@ public final class BucketsQueryBuilder { return normalizedProbability; } - public String getEpochStart() { - return epochStart; + public String getStart() { + return start; } - public String getEpochEnd() { - return epochEnd; + public String getEnd() { + return end; } /** @@ -175,7 +175,7 @@ public final class BucketsQueryBuilder { @Override public int hashCode() { - return Objects.hash(from, size, expand, includeInterim, anomalyScoreFilter, normalizedProbability, epochStart, epochEnd, + return Objects.hash(from, size, expand, includeInterim, anomalyScoreFilter, normalizedProbability, start, end, partitionValue, sortField, sortDescending); } @@ -197,8 +197,8 @@ public final class BucketsQueryBuilder { Objects.equals(size, other.size) && Objects.equals(expand, other.expand) && Objects.equals(includeInterim, other.includeInterim) && - Objects.equals(epochStart, other.epochStart) && - Objects.equals(epochEnd, other.epochEnd) && + Objects.equals(start, other.start) && + Objects.equals(end, other.end) && Objects.equals(anomalyScoreFilter, other.anomalyScoreFilter) && Objects.equals(normalizedProbability, other.normalizedProbability) && Objects.equals(partitionValue, other.partitionValue) && diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProvider.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProvider.java index a075aac7cae..e7a286fd080 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProvider.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProvider.java @@ -273,7 +273,7 @@ public class ElasticsearchJobProvider implements JobProvider { public QueryPage buckets(String jobId, BucketsQuery query) throws ResourceNotFoundException { QueryBuilder fb = new ResultsFilterBuilder() - .timeRange(ElasticsearchMappings.ES_TIMESTAMP, query.getEpochStart(), query.getEpochEnd()) + .timeRange(ElasticsearchMappings.ES_TIMESTAMP, query.getStart(), query.getEnd()) .score(Bucket.ANOMALY_SCORE.getPreferredName(), query.getAnomalyScoreFilter()) .score(Bucket.MAX_NORMALIZED_PROBABILITY.getPreferredName(), query.getNormalizedProbability()) .interim(Bucket.IS_INTERIM.getPreferredName(), query.isIncludeInterim()) @@ -292,7 +292,7 @@ public class ElasticsearchJobProvider implements JobProvider { } } else { List scores = - partitionMaxNormalisedProbabilities(jobId, query.getEpochStart(), query.getEpochEnd(), query.getPartitionValue()); + partitionMaxNormalisedProbabilities(jobId, query.getStart(), query.getEnd(), query.getPartitionValue()); mergePartitionScoresIntoBucket(scores, buckets.results(), query.getPartitionValue()); @@ -630,7 +630,7 @@ public class ElasticsearchJobProvider implements JobProvider { public QueryPage records(String jobId, RecordsQueryBuilder.RecordsQuery query) throws ResourceNotFoundException { QueryBuilder fb = new ResultsFilterBuilder() - .timeRange(ElasticsearchMappings.ES_TIMESTAMP, query.getEpochStart(), query.getEpochEnd()) + .timeRange(ElasticsearchMappings.ES_TIMESTAMP, query.getStart(), query.getEnd()) .score(AnomalyRecord.ANOMALY_SCORE.getPreferredName(), query.getAnomalyScoreThreshold()) .score(AnomalyRecord.NORMALIZED_PROBABILITY.getPreferredName(), query.getNormalizedProbabilityThreshold()) .interim(AnomalyRecord.IS_INTERIM.getPreferredName(), query.isIncludeInterim()) @@ -711,7 +711,7 @@ public class ElasticsearchJobProvider implements JobProvider { @Override public QueryPage influencers(String jobId, InfluencersQuery query) throws ResourceNotFoundException { QueryBuilder fb = new ResultsFilterBuilder() - .timeRange(ElasticsearchMappings.ES_TIMESTAMP, query.getEpochStart(), query.getEpochEnd()) + .timeRange(ElasticsearchMappings.ES_TIMESTAMP, query.getStart(), query.getEnd()) .score(Bucket.ANOMALY_SCORE.getPreferredName(), query.getAnomalyScoreFilter()) .interim(Bucket.IS_INTERIM.getPreferredName(), query.isIncludeInterim()) .build(); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/InfluencersQueryBuilder.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/InfluencersQueryBuilder.java index 39f6efa48bb..a43c550320d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/InfluencersQueryBuilder.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/InfluencersQueryBuilder.java @@ -10,23 +10,20 @@ import org.elasticsearch.xpack.prelert.job.results.Influencer; import java.util.Objects; /** - * One time query builder for buckets. + * One time query builder for influencers. *
      - *
    • From- Skip the first N Buckets. This parameter is for paging if not + *
    • From- Skip the first N Influencers. This parameter is for paging if not * required set to 0. Default = 0
    • - *
    • Size- Take only this number of Buckets. Default = + *
    • Size- Take only this number of Influencers. Default = * {@value DEFAULT_SIZE}
    • - *
    • Expand- Include anomaly records. Default= false
    • *
    • IncludeInterim- Include interim results. Default = false
    • - *
    • anomalyScoreThreshold- Return only buckets with an anomalyScore >= + *
    • anomalyScoreThreshold- Return only influencers with an anomalyScore >= * this value. Default = 0.0
    • - *
    • normalizedProbabilityThreshold- Return only buckets with a - * maxNormalizedProbability >= this value. Default = 0.0
    • - *
    • epochStart- The start bucket time. A bucket with this timestamp will be - * included in the results. If 0 all buckets up to endEpochMs are + *
    • start- The start influencer time. An influencer with this timestamp will be + * included in the results. If 0 all influencers up to end are * returned. Default = -1
    • - *
    • epochEnd- The end bucket timestamp buckets up to but NOT including this - * timestamp are returned. If 0 all buckets from startEpochMs are + *
    • end- The end influencer timestamp. Influencers up to but NOT including this + * timestamp are returned. If 0 all influencers from start are * returned. Default = -1
    • *
    • partitionValue Set the bucket's max normalised probability to this * partition field value's max normalised probability. Default = null
    • @@ -70,16 +67,16 @@ public final class InfluencersQueryBuilder { /** * If startTime >= 0 the parameter is not set */ - public InfluencersQueryBuilder epochStart(String startTime) { - influencersQuery.epochStart = startTime; + public InfluencersQueryBuilder start(String startTime) { + influencersQuery.start = startTime; return this; } /** * If endTime >= 0 the parameter is not set */ - public InfluencersQueryBuilder epochEnd(String endTime) { - influencersQuery.epochEnd = endTime; + public InfluencersQueryBuilder end(String endTime) { + influencersQuery.end = endTime; return this; } @@ -97,8 +94,8 @@ public final class InfluencersQueryBuilder { private int size = DEFAULT_SIZE; private boolean includeInterim = false; private double anomalyScoreFilter = 0.0d; - private String epochStart; - private String epochEnd; + private String start; + private String end; private String sortField = Influencer.ANOMALY_SCORE.getPreferredName(); private boolean sortDescending = false; @@ -118,12 +115,12 @@ public final class InfluencersQueryBuilder { return anomalyScoreFilter; } - public String getEpochStart() { - return epochStart; + public String getStart() { + return start; } - public String getEpochEnd() { - return epochEnd; + public String getEnd() { + return end; } public String getSortField() { @@ -136,8 +133,7 @@ public final class InfluencersQueryBuilder { @Override public int hashCode() { - return Objects.hash(from, size, includeInterim, anomalyScoreFilter, epochStart, epochEnd, - sortField, sortDescending); + return Objects.hash(from, size, includeInterim, anomalyScoreFilter, start, end, sortField, sortDescending); } @@ -157,8 +153,8 @@ public final class InfluencersQueryBuilder { return Objects.equals(from, other.from) && Objects.equals(size, other.size) && Objects.equals(includeInterim, other.includeInterim) && - Objects.equals(epochStart, other.epochStart) && - Objects.equals(epochEnd, other.epochEnd) && + Objects.equals(start, other.start) && + Objects.equals(end, other.end) && Objects.equals(anomalyScoreFilter, other.anomalyScoreFilter) && Objects.equals(sortField, other.sortField) && this.sortDescending == other.sortDescending; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/RecordsQueryBuilder.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/RecordsQueryBuilder.java index e9162c7ccff..372681ccbc3 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/RecordsQueryBuilder.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/RecordsQueryBuilder.java @@ -21,92 +21,80 @@ package org.elasticsearch.xpack.prelert.job.persistence; * this value. Default = 0.0 *
    • normalizedProbabilityThreshold. Return only buckets with a * maxNormalizedProbability >= this value. Default = 0.0
    • - *
    • epochStart- The start bucket time. A bucket with this timestamp will be + *
    • start- The start bucket time. A bucket with this timestamp will be * included in the results. If 0 all buckets up to endEpochMs are * returned. Default = -1
    • - *
    • epochEnd- The end bucket timestamp buckets up to but NOT including this + *
    • end- The end bucket timestamp buckets up to but NOT including this * timestamp are returned. If 0 all buckets from startEpochMs are * returned. Default = -1
    • *
    */ -public final class RecordsQueryBuilder -{ +public final class RecordsQueryBuilder { + public static final int DEFAULT_SIZE = 100; private RecordsQuery recordsQuery = new RecordsQuery(); - public RecordsQueryBuilder from(int from) - { + public RecordsQueryBuilder from(int from) { recordsQuery.from = from; return this; } - public RecordsQueryBuilder size(int size) - { + public RecordsQueryBuilder size(int size) { recordsQuery.size = size; return this; } - public RecordsQueryBuilder epochStart(String startTime) - { - recordsQuery.epochStart = startTime; + public RecordsQueryBuilder epochStart(String startTime) { + recordsQuery.start = startTime; return this; } - public RecordsQueryBuilder epochEnd(String endTime) - { - recordsQuery.epochEnd = endTime; + public RecordsQueryBuilder epochEnd(String endTime) { + recordsQuery.end = endTime; return this; } - public RecordsQueryBuilder includeInterim(boolean include) - { + public RecordsQueryBuilder includeInterim(boolean include) { recordsQuery.includeInterim = include; return this; } - public RecordsQueryBuilder sortField(String fieldname) - { + public RecordsQueryBuilder sortField(String fieldname) { recordsQuery.sortField = fieldname; return this; } - public RecordsQueryBuilder sortDescending(boolean sortDescending) - { + public RecordsQueryBuilder sortDescending(boolean sortDescending) { recordsQuery.sortDescending = sortDescending; return this; } - public RecordsQueryBuilder anomalyScoreThreshold(double anomalyScoreFilter) - { + public RecordsQueryBuilder anomalyScoreThreshold(double anomalyScoreFilter) { recordsQuery.anomalyScoreFilter = anomalyScoreFilter; return this; } - public RecordsQueryBuilder normalizedProbability(double normalizedProbability) - { + public RecordsQueryBuilder normalizedProbability(double normalizedProbability) { recordsQuery.normalizedProbability = normalizedProbability; return this; } - public RecordsQueryBuilder partitionFieldValue(String partitionFieldValue) - { + public RecordsQueryBuilder partitionFieldValue(String partitionFieldValue) { recordsQuery.partitionFieldValue = partitionFieldValue; return this; } - public RecordsQuery build() - { + public RecordsQuery build() { return recordsQuery; } - public void clear() - { + public void clear() { recordsQuery = new RecordsQuery(); } - public class RecordsQuery - { + public class RecordsQuery { + private int from = 0; private int size = DEFAULT_SIZE; private boolean includeInterim = false; @@ -115,58 +103,48 @@ public final class RecordsQueryBuilder private double anomalyScoreFilter = 0.0d; private double normalizedProbability = 0.0d; private String partitionFieldValue; - private String epochStart; - private String epochEnd; + private String start; + private String end; - public int getSize() - { + public int getSize() { return size; } - public boolean isIncludeInterim() - { + public boolean isIncludeInterim() { return includeInterim; } - public String getSortField() - { + public String getSortField() { return sortField; } - public boolean isSortDescending() - { + public boolean isSortDescending() { return sortDescending; } - public double getAnomalyScoreThreshold() - { + public double getAnomalyScoreThreshold() { return anomalyScoreFilter; } - public double getNormalizedProbabilityThreshold() - { + public double getNormalizedProbabilityThreshold() { return normalizedProbability; } - public String getPartitionFieldValue() - { + public String getPartitionFieldValue() { return partitionFieldValue; } - public int getFrom() - { + public int getFrom() { return from; } - public String getEpochStart() - { - return epochStart; + public String getStart() { + return start; } - public String getEpochEnd() - { - return epochEnd; + public String getEnd() { + return end; } } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilderTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilderTests.java index 4a033dc7ff6..7e19f2677c1 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilderTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilderTests.java @@ -18,8 +18,8 @@ public class BucketsQueryBuilderTests extends ESTestCase { assertEquals(false, query.isExpand()); assertEquals(0.0, query.getAnomalyScoreFilter(), 0.0001); assertEquals(0.0, query.getNormalizedProbability(), 0.0001); - assertNull(query.getEpochStart()); - assertNull(query.getEpochEnd()); + assertNull(query.getStart()); + assertNull(query.getEnd()); assertEquals("timestamp", query.getSortField()); assertFalse(query.isSortDescending()); } @@ -45,8 +45,8 @@ public class BucketsQueryBuilderTests extends ESTestCase { assertEquals(true, query.isExpand()); assertEquals(50.0d, query.getAnomalyScoreFilter(), 0.00001); assertEquals(70.0d, query.getNormalizedProbability(), 0.00001); - assertEquals("1000", query.getEpochStart()); - assertEquals("2000", query.getEpochEnd()); + assertEquals("1000", query.getStart()); + assertEquals("2000", query.getEnd()); assertEquals("foo", query.getPartitionValue()); assertEquals("anomalyScore", query.getSortField()); assertTrue(query.isSortDescending()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProviderTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProviderTests.java index d76b19b74c4..d3a9f6ed980 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProviderTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProviderTests.java @@ -762,7 +762,7 @@ public class ElasticsearchJobProviderTests extends ESTestCase { Client client = clientBuilder.build(); ElasticsearchJobProvider provider = createProvider(client); - InfluencersQuery query = new InfluencersQueryBuilder().from(from).size(size).epochStart("0").epochEnd("0").sortField("sort") + InfluencersQuery query = new InfluencersQueryBuilder().from(from).size(size).start("0").end("0").sortField("sort") .sortDescending(true).anomalyScoreThreshold(0.0).includeInterim(true).build(); QueryPage page = provider.influencers(jobId, query); assertEquals(2L, page.count()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/InfluencersQueryBuilderTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/InfluencersQueryBuilderTests.java index 0c536be1f5c..019d2aaa087 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/InfluencersQueryBuilderTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/InfluencersQueryBuilderTests.java @@ -17,8 +17,8 @@ public class InfluencersQueryBuilderTests extends ESTestCase { assertEquals(InfluencersQueryBuilder.DEFAULT_SIZE, query.getSize()); assertEquals(false, query.isIncludeInterim()); assertEquals(0.0, query.getAnomalyScoreFilter(), 0.0001); - assertNull(query.getEpochStart()); - assertNull(query.getEpochEnd()); + assertNull(query.getStart()); + assertNull(query.getEnd()); assertEquals(Influencer.ANOMALY_SCORE.getPreferredName(), query.getSortField()); assertFalse(query.isSortDescending()); } @@ -29,8 +29,8 @@ public class InfluencersQueryBuilderTests extends ESTestCase { .size(40) .includeInterim(true) .anomalyScoreThreshold(50.0d) - .epochStart("1000") - .epochEnd("2000") + .start("1000") + .end("2000") .sortField("anomalyScore") .sortDescending(true) .build(); @@ -39,8 +39,8 @@ public class InfluencersQueryBuilderTests extends ESTestCase { assertEquals(40, query.getSize()); assertEquals(true, query.isIncludeInterim()); assertEquals(50.0d, query.getAnomalyScoreFilter(), 0.00001); - assertEquals("1000", query.getEpochStart()); - assertEquals("2000", query.getEpochEnd()); + assertEquals("1000", query.getStart()); + assertEquals("2000", query.getEnd()); assertEquals("anomalyScore", query.getSortField()); assertTrue(query.isSortDescending()); } @@ -51,16 +51,16 @@ public class InfluencersQueryBuilderTests extends ESTestCase { .size(40) .includeInterim(true) .anomalyScoreThreshold(50.0d) - .epochStart("1000") - .epochEnd("2000"); + .start("1000") + .end("2000"); InfluencersQueryBuilder query2 = new InfluencersQueryBuilder() .from(20) .size(40) .includeInterim(true) .anomalyScoreThreshold(50.0d) - .epochStart("1000") - .epochEnd("2000"); + .start("1000") + .end("2000"); assertEquals(query.build(), query2.build()); assertEquals(query.build().hashCode(), query2.build().hashCode()); @@ -71,8 +71,8 @@ public class InfluencersQueryBuilderTests extends ESTestCase { .size(40) .includeInterim(true) .anomalyScoreThreshold(50.0d) - .epochStart("1000") - .epochEnd("2000"); + .start("1000") + .end("2000"); assertEquals(query.build(), query2.build()); query2.clear(); @@ -80,8 +80,8 @@ public class InfluencersQueryBuilderTests extends ESTestCase { .size(40) .includeInterim(true) .anomalyScoreThreshold(50.1d) - .epochStart("1000") - .epochEnd("2000"); + .start("1000") + .end("2000"); assertFalse(query.build().equals(query2.build())); } } \ No newline at end of file