Skip to content

Commit

Permalink
Add supported type tests to min aggregation (elastic#54021)
Browse files Browse the repository at this point in the history
  • Loading branch information
csoulios committed Mar 24, 2020
1 parent 9a64ae0 commit 5e637c4
Showing 1 changed file with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexOptions;
Expand All @@ -45,7 +44,6 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.CheckedConsumer;
Expand All @@ -55,7 +53,6 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperService;
Expand Down Expand Up @@ -84,10 +81,12 @@
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.support.AggregationInspectionHelper;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.FieldContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.lookup.LeafDocLookup;

Expand Down Expand Up @@ -278,22 +277,6 @@ public void testUnmappedWithMissingField() throws IOException {
}, fieldType);
}

public void testUnsupportedType() {
MinAggregationBuilder aggregationBuilder = new MinAggregationBuilder("min").field("not_a_number");

MappedFieldType fieldType = new KeywordFieldMapper.KeywordFieldType();
fieldType.setName("not_a_number");
fieldType.setHasDocValues(true);

IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> testCase(aggregationBuilder, new MatchAllDocsQuery(), iw -> {
iw.addDocument(singleton(new SortedSetDocValuesField("string", new BytesRef("foo"))));
}, (Consumer<InternalMin>) min -> {
fail("Should have thrown exception");
}, fieldType));
assertEquals(e.getMessage(), "Expected numeric type on field [not_a_number], but got [keyword]");
}

public void testBadMissingField() {
MinAggregationBuilder aggregationBuilder = new MinAggregationBuilder("min").field("number").missing("not_a_number");

Expand Down Expand Up @@ -936,5 +919,13 @@ private <T extends AggregationBuilder, V extends InternalAggregation> void testC
}
}

@Override
protected List<ValuesSourceType> getSupportedValuesSourceTypes() {
return Collections.singletonList(CoreValuesSourceType.NUMERIC);
}

@Override
protected AggregationBuilder createAggBuilderForTypeTest(MappedFieldType fieldType, String fieldName) {
return new MinAggregationBuilder("foo").field(fieldName);
}
}

0 comments on commit 5e637c4

Please sign in to comment.