Skip to content

Commit 43d96d4

Browse files
committed
Aggregations Refactor: Refactor Global Aggregation
1 parent 7e316ba commit 43d96d4

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
package org.elasticsearch.search.aggregations.bucket.global;
2020

2121
import org.apache.lucene.index.LeafReaderContext;
22+
import org.elasticsearch.common.io.stream.StreamInput;
23+
import org.elasticsearch.common.io.stream.StreamOutput;
24+
import org.elasticsearch.common.xcontent.XContentBuilder;
2225
import org.elasticsearch.search.aggregations.AggregationExecutionException;
2326
import org.elasticsearch.search.aggregations.Aggregator;
2427
import org.elasticsearch.search.aggregations.AggregatorFactories;
@@ -87,5 +90,32 @@ public Aggregator createInternal(AggregationContext context, Aggregator parent,
8790
return new GlobalAggregator(name, factories, context, pipelineAggregators, metaData);
8891
}
8992

93+
@Override
94+
protected AggregatorFactory doReadFrom(String name, StreamInput in) throws IOException {
95+
return new Factory(name);
96+
}
97+
98+
@Override
99+
protected void doWriteTo(StreamOutput out) throws IOException {
100+
// Nothing to write
101+
}
102+
103+
@Override
104+
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
105+
builder.startObject();
106+
builder.endObject();
107+
return builder;
108+
}
109+
110+
@Override
111+
protected boolean doEquals(Object obj) {
112+
return true;
113+
}
114+
115+
@Override
116+
protected int doHashCode() {
117+
return 0;
118+
}
119+
90120
}
91121
}

core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se
4141
return new GlobalAggregator.Factory(aggregationName);
4242
}
4343

44-
// NORELEASE implement this method when refactoring this aggregation
4544
@Override
4645
public AggregatorFactory getFactoryPrototype() {
47-
return null;
46+
return new GlobalAggregator.Factory(null);
4847
}
4948

5049
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.search.aggregations.bucket;
21+
22+
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
23+
import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator;
24+
import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator.Factory;
25+
26+
public class GlobalTests extends BaseAggregationTestCase<GlobalAggregator.Factory> {
27+
28+
@Override
29+
protected Factory createTestAggregatorFactory() {
30+
return new GlobalAggregator.Factory(randomAsciiOfLengthBetween(3, 20));
31+
}
32+
33+
}

0 commit comments

Comments
 (0)