Aggregations Refactor: Refactor Global Aggregation

This commit is contained in:
Colin Goodheart-Smithe 2015-08-25 11:47:44 +02:00
parent 712b7116f4
commit 8c37c6f896
3 changed files with 64 additions and 2 deletions

View File

@ -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 class GlobalAggregator extends SingleBucketAggregator {
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;
}
}
}

View File

@ -41,10 +41,9 @@ public class GlobalParser implements Aggregator.Parser {
return new GlobalAggregator.Factory(aggregationName);
}
// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
return null;
return new GlobalAggregator.Factory(null);
}
}

View File

@ -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<GlobalAggregator.Factory> {
@Override
protected Factory createTestAggregatorFactory() {
return new GlobalAggregator.Factory(randomAsciiOfLengthBetween(3, 20));
}
}