Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
talevy committed Dec 13, 2018
1 parent da1072e commit d8ef49b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Expand Up @@ -79,7 +79,7 @@ private MultiValuesSourceFieldConfig(String fieldName, Object missing, Script sc
}

public MultiValuesSourceFieldConfig(StreamInput in) throws IOException {
this.fieldName = in.readOptionalString();
this.fieldName = in.readString();
this.missing = in.readGenericValue();
this.script = in.readOptionalWriteable(Script::new);
this.timeZone = in.readOptionalTimeZone();
Expand All @@ -103,7 +103,7 @@ public String getFieldName() {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(fieldName);
out.writeString(fieldName);
out.writeGenericValue(missing);
out.writeOptionalWriteable(script);
out.writeOptionalTimeZone(timeZone);
Expand Down
Expand Up @@ -19,23 +19,22 @@

package org.elasticsearch.search.aggregations.metrics.weighted_avg;

import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.metrics.WeightedAvgAggregationBuilder;
import org.elasticsearch.search.aggregations.support.MultiValuesSourceFieldConfig;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.test.AbstractSerializingTestCase;
import org.junit.Before;

import java.io.IOException;
import java.util.Collections;

import static org.hamcrest.Matchers.hasSize;

public class WeightedAvgAggregationBuilderTests extends AbstractSerializingTestCase<WeightedAvgAggregationBuilder> {
String aggregationName;

Expand All @@ -52,13 +51,14 @@ protected NamedXContentRegistry xContentRegistry() {

@Override
protected WeightedAvgAggregationBuilder doParseInstance(XContentParser parser) throws IOException {
parser.nextToken();
AggregatorFactories.Builder builders = AggregatorFactories.parseAggregators(parser);
if (builders.getAggregatorFactories().size() == 1) {
AggregationBuilder builder = builders.getAggregatorFactories().iterator().next();
return (WeightedAvgAggregationBuilder) builder;
}
return null;
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
AggregatorFactories.Builder parsed = AggregatorFactories.parseAggregators(parser);
assertThat(parsed.getAggregatorFactories(), hasSize(1));
assertThat(parsed.getPipelineAggregatorFactories(), hasSize(0));
WeightedAvgAggregationBuilder agg = (WeightedAvgAggregationBuilder) parsed.getAggregatorFactories().iterator().next();
assertNull(parser.nextToken());
assertNotNull(agg);
return agg;
}

@Override
Expand Down
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.script.Script;
import org.elasticsearch.test.AbstractSerializingTestCase;
import org.elasticsearch.test.ESTestCase;
import org.joda.time.DateTimeZone;

import java.io.IOException;
Expand All @@ -39,13 +38,11 @@ protected MultiValuesSourceFieldConfig doParseInstance(XContentParser parser) th

@Override
protected MultiValuesSourceFieldConfig createTestInstance() {
boolean hasField = randomBoolean();
String field = hasField ? randomAlphaOfLength(10) : null;
Script script = hasField ? null : new Script("foo");
String field = randomAlphaOfLength(10);
Object missing = randomBoolean() ? randomAlphaOfLength(10) : null;
DateTimeZone timeZone = randomBoolean() ? randomDateTimeZone() : null;
return new MultiValuesSourceFieldConfig.Builder()
.setFieldName(field).setMissing(missing).setScript(script).setTimeZone(timeZone).build();
.setFieldName(field).setMissing(missing).setScript(null).setTimeZone(timeZone).build();
}

@Override
Expand Down

0 comments on commit d8ef49b

Please sign in to comment.