Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.elasticsearch.search.aggregations.support;

import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
Expand Down Expand Up @@ -123,11 +122,10 @@ public AggregatorSupplier getAggregator(ValuesSourceConfig valuesSourceConfig, S
aggregatorRegistry.get(aggregationName)
);
if (supplier == null) {
// TODO: push building the description into ValuesSourceConfig
MappedFieldType fieldType = valuesSourceConfig.fieldContext().fieldType();
String fieldDescription = fieldType.typeName();
throw new IllegalArgumentException("Field [" + fieldType.name() + "] of type [" + fieldDescription +
"] is not supported for aggregation [" + aggregationName + "]"); }
throw new IllegalArgumentException(
valuesSourceConfig.getDescription() + " is not supported for aggregation [" + aggregationName + "]"
);
}
return supplier;
}
throw new AggregationExecutionException("Unregistered Aggregation [" + aggregationName + "]");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.support;

import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.script.AggregationScript;
import org.elasticsearch.test.ESTestCase;
import org.mockito.Mockito;

import java.util.Collections;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ValuesSourceRegistryTests extends ESTestCase {

public void testAggregatorNotFoundException() {
final QueryShardContext queryShardContext = mock(QueryShardContext.class);
final AggregationScript.Factory mockAggScriptFactory = mock(AggregationScript.Factory.class);
when(mockAggScriptFactory.newFactory(Mockito.any(), Mockito.any())).thenReturn(mock(AggregationScript.LeafFactory.class));
when(queryShardContext.compile(Mockito.any(), Mockito.any())).thenReturn(mockAggScriptFactory);

ValuesSourceConfig fieldOnly = ValuesSourceConfig.resolve(
queryShardContext,
null,
"field",
null,
null,
null,
null,
CoreValuesSourceType.BYTES
);

ValuesSourceConfig scriptOnly = ValuesSourceConfig.resolve(
queryShardContext,
null,
null,
mockScript("fakeScript"),
null,
null,
null,
CoreValuesSourceType.BYTES
);
ValuesSourceRegistry registry = new ValuesSourceRegistry(
Collections.singletonMap("bogus", Collections.emptyList()),
null);
expectThrows(IllegalArgumentException.class, () -> registry.getAggregator(fieldOnly, "bogus"));
expectThrows(IllegalArgumentException.class, () -> registry.getAggregator(scriptOnly, "bogus"));
}

}