From 43d96d43a3b7e5aa980da55edaafdadec1f71b6a Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Tue, 25 Aug 2015 11:47:44 +0200 Subject: [PATCH] Aggregations Refactor: Refactor Global Aggregation --- .../bucket/global/GlobalAggregator.java | 30 +++++++++++++++++ .../bucket/global/GlobalParser.java | 3 +- .../aggregations/bucket/GlobalTests.java | 33 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/search/aggregations/bucket/GlobalTests.java diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java index 63f47e152f642..b86895b7e9720 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java @@ -19,6 +19,9 @@ package org.elasticsearch.search.aggregations.bucket.global; import org.apache.lucene.index.LeafReaderContext; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; @@ -87,5 +90,32 @@ public Aggregator createInternal(AggregationContext context, Aggregator parent, return new GlobalAggregator(name, factories, context, pipelineAggregators, metaData); } + @Override + protected AggregatorFactory doReadFrom(String name, StreamInput in) throws IOException { + return new Factory(name); + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + // Nothing to write + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.endObject(); + return builder; + } + + @Override + protected boolean doEquals(Object obj) { + return true; + } + + @Override + protected int doHashCode() { + return 0; + } + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java index 5a11ad8087eac..b7a606312cd9d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java @@ -41,10 +41,9 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se return new GlobalAggregator.Factory(aggregationName); } - // NORELEASE implement this method when refactoring this aggregation @Override public AggregatorFactory getFactoryPrototype() { - return null; + return new GlobalAggregator.Factory(null); } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GlobalTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GlobalTests.java new file mode 100644 index 0000000000000..6529e0bd7c327 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GlobalTests.java @@ -0,0 +1,33 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket; + +import org.elasticsearch.search.aggregations.BaseAggregationTestCase; +import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator; +import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator.Factory; + +public class GlobalTests extends BaseAggregationTestCase { + + @Override + protected Factory createTestAggregatorFactory() { + return new GlobalAggregator.Factory(randomAsciiOfLengthBetween(3, 20)); + } + +}