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 @@ -31,7 +31,6 @@
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;

import java.io.IOException;
Expand Down Expand Up @@ -81,7 +80,7 @@ public MultiValueMode multiValueMode() {

@Override
protected MatrixStatsAggregatorFactory innerBuild(QueryShardContext queryShardContext,
Map<String, ValuesSourceConfig<Numeric>> configs,
Map<String, ValuesSourceConfig> configs,
AggregatorFactory parent,
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
return new MatrixStatsAggregatorFactory(name, configs, multiValueMode, queryShardContext, parent, subFactoriesBuilder, metaData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.AggregatorFactory;
Expand All @@ -30,15 +31,16 @@
import org.elasticsearch.search.internal.SearchContext;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

final class MatrixStatsAggregatorFactory extends ArrayValuesSourceAggregatorFactory<ValuesSource.Numeric> {
final class MatrixStatsAggregatorFactory extends ArrayValuesSourceAggregatorFactory {

private final MultiValueMode multiValueMode;

MatrixStatsAggregatorFactory(String name,
Map<String, ValuesSourceConfig<ValuesSource.Numeric>> configs,
Map<String, ValuesSourceConfig> configs,
MultiValueMode multiValueMode,
QueryShardContext queryShardContext,
AggregatorFactory parent,
Expand All @@ -58,12 +60,21 @@ protected Aggregator createUnmapped(SearchContext searchContext,
}

@Override
protected Aggregator doCreateInternal(Map<String, ValuesSource.Numeric> valuesSources,
protected Aggregator doCreateInternal(Map<String, ValuesSource> valuesSources,
SearchContext searchContext,
Aggregator parent,
boolean collectsFromSingleBucket,
List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData) throws IOException {
return new MatrixStatsAggregator(name, valuesSources, searchContext, parent, multiValueMode, pipelineAggregators, metaData);
Map<String, ValuesSource.Numeric> typedValuesSources = new HashMap<>(valuesSources.size());
for (Map.Entry<String, ValuesSource> entry : valuesSources.entrySet()) {
if (entry.getValue() instanceof ValuesSource.Numeric == false) {
throw new AggregationExecutionException("ValuesSource type " + entry.getValue().toString() +
"is not supported for aggregation " + this.name());
}
// TODO: There must be a better option than this.
typedValuesSources.put(entry.getKey(), (ValuesSource.Numeric) entry.getValue());
}
return new MatrixStatsAggregator(name, typedValuesSources, searchContext, parent, multiValueMode, pipelineAggregators, metaData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,34 +239,34 @@ public Map<String, Object> missingMap() {
}

@Override
protected final ArrayValuesSourceAggregatorFactory<VS> doBuild(QueryShardContext queryShardContext, AggregatorFactory parent,
Builder subFactoriesBuilder) throws IOException {
Map<String, ValuesSourceConfig<VS>> configs = resolveConfig(queryShardContext);
ArrayValuesSourceAggregatorFactory<VS> factory = innerBuild(queryShardContext, configs, parent, subFactoriesBuilder);
protected final ArrayValuesSourceAggregatorFactory doBuild(QueryShardContext queryShardContext, AggregatorFactory parent,
Builder subFactoriesBuilder) throws IOException {
Map<String, ValuesSourceConfig> configs = resolveConfig(queryShardContext);
ArrayValuesSourceAggregatorFactory factory = innerBuild(queryShardContext, configs, parent, subFactoriesBuilder);
return factory;
}

protected Map<String, ValuesSourceConfig<VS>> resolveConfig(QueryShardContext queryShardContext) {
HashMap<String, ValuesSourceConfig<VS>> configs = new HashMap<>();
protected Map<String, ValuesSourceConfig> resolveConfig(QueryShardContext queryShardContext) {
HashMap<String, ValuesSourceConfig> configs = new HashMap<>();
for (String field : fields) {
ValuesSourceConfig<VS> config = config(queryShardContext, field, null);
ValuesSourceConfig config = config(queryShardContext, field, null);
configs.put(field, config);
}
return configs;
}

protected abstract ArrayValuesSourceAggregatorFactory<VS> innerBuild(QueryShardContext queryShardContext,
Map<String, ValuesSourceConfig<VS>> configs,
AggregatorFactory parent,
AggregatorFactories.Builder subFactoriesBuilder) throws IOException;
protected abstract ArrayValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardContext,
Map<String, ValuesSourceConfig> configs,
AggregatorFactory parent,
AggregatorFactories.Builder subFactoriesBuilder) throws IOException;

public ValuesSourceConfig<VS> config(QueryShardContext queryShardContext, String field, Script script) {
public ValuesSourceConfig config(QueryShardContext queryShardContext, String field, Script script) {

ValueType valueType = this.valueType != null ? this.valueType : targetValueType;

if (field == null) {
if (script == null) {
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(CoreValuesSourceType.ANY);
ValuesSourceConfig config = new ValuesSourceConfig(CoreValuesSourceType.ANY);
return config.format(resolveFormat(null, valueType));
}
ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType;
Expand All @@ -277,33 +277,33 @@ public ValuesSourceConfig<VS> config(QueryShardContext queryShardContext, String
// on Bytes
valuesSourceType = CoreValuesSourceType.BYTES;
}
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType);
ValuesSourceConfig config = new ValuesSourceConfig(valuesSourceType);
config.missing(missingMap.get(field));
return config.format(resolveFormat(format, valueType));
}

MappedFieldType fieldType = queryShardContext.getMapperService().fullName(field);
if (fieldType == null) {
ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType;
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType);
ValuesSourceConfig config = new ValuesSourceConfig(valuesSourceType);
config.missing(missingMap.get(field));
config.format(resolveFormat(format, valueType));
return config.unmapped(true);
}

IndexFieldData<?> indexFieldData = queryShardContext.getForField(fieldType);

ValuesSourceConfig<VS> config;
ValuesSourceConfig config;
if (valuesSourceType == CoreValuesSourceType.ANY) {
if (indexFieldData instanceof IndexNumericFieldData) {
config = new ValuesSourceConfig<>(CoreValuesSourceType.NUMERIC);
config = new ValuesSourceConfig(CoreValuesSourceType.NUMERIC);
} else if (indexFieldData instanceof IndexGeoPointFieldData) {
config = new ValuesSourceConfig<>(CoreValuesSourceType.GEOPOINT);
config = new ValuesSourceConfig(CoreValuesSourceType.GEOPOINT);
} else {
config = new ValuesSourceConfig<>(CoreValuesSourceType.BYTES);
config = new ValuesSourceConfig(CoreValuesSourceType.BYTES);
}
} else {
config = new ValuesSourceConfig<>(valuesSourceType);
config = new ValuesSourceConfig(valuesSourceType);
}

config.fieldContext(new FieldContext(field, indexFieldData, fieldType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import java.util.List;
import java.util.Map;

public abstract class ArrayValuesSourceAggregatorFactory<VS extends ValuesSource>
public abstract class ArrayValuesSourceAggregatorFactory
extends AggregatorFactory {

protected Map<String, ValuesSourceConfig<VS>> configs;
protected Map<String, ValuesSourceConfig> configs;

public ArrayValuesSourceAggregatorFactory(String name, Map<String, ValuesSourceConfig<VS>> configs,
public ArrayValuesSourceAggregatorFactory(String name, Map<String, ValuesSourceConfig> configs,
QueryShardContext queryShardContext, AggregatorFactory parent,
AggregatorFactories.Builder subFactoriesBuilder,
Map<String, Object> metaData) throws IOException {
Expand All @@ -50,10 +50,10 @@ public Aggregator createInternal(SearchContext searchContext,
boolean collectsFromSingleBucket,
List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData) throws IOException {
HashMap<String, VS> valuesSources = new HashMap<>();
HashMap<String, ValuesSource> valuesSources = new HashMap<>();

for (Map.Entry<String, ValuesSourceConfig<VS>> config : configs.entrySet()) {
VS vs = config.getValue().toValuesSource(queryShardContext);
for (Map.Entry<String, ValuesSourceConfig> config : configs.entrySet()) {
ValuesSource vs = config.getValue().toValuesSource(queryShardContext);
if (vs != null) {
valuesSources.put(config.getKey(), vs);
}
Expand All @@ -70,7 +70,7 @@ protected abstract Aggregator createUnmapped(SearchContext searchContext,
List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData) throws IOException;

protected abstract Aggregator doCreateInternal(Map<String, VS> valuesSources,
protected abstract Aggregator doCreateInternal(Map<String, ValuesSource> valuesSources,
SearchContext searchContext,
Aggregator parent,
boolean collectsFromSingleBucket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
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.Bytes.WithOrdinals;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
Expand All @@ -46,7 +45,7 @@
import java.util.Objects;

public class ChildrenAggregationBuilder
extends ValuesSourceAggregationBuilder<WithOrdinals, ChildrenAggregationBuilder> {
extends ValuesSourceAggregationBuilder<ChildrenAggregationBuilder> {

public static final String NAME = "children";

Expand Down Expand Up @@ -95,22 +94,22 @@ protected void innerWriteTo(StreamOutput out) throws IOException {
}

@Override
protected ValuesSourceAggregatorFactory<WithOrdinals> innerBuild(QueryShardContext queryShardContext,
ValuesSourceConfig<WithOrdinals> config,
AggregatorFactory parent,
Builder subFactoriesBuilder) throws IOException {
protected ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardContext,
ValuesSourceConfig config,
AggregatorFactory parent,
Builder subFactoriesBuilder) throws IOException {
return new ChildrenAggregatorFactory(name, config, childFilter, parentFilter, queryShardContext, parent,
subFactoriesBuilder, metaData);
}

@Override
protected ValuesSourceConfig<WithOrdinals> resolveConfig(QueryShardContext queryShardContext) {
ValuesSourceConfig<WithOrdinals> config = new ValuesSourceConfig<>(CoreValuesSourceType.BYTES);
protected ValuesSourceConfig resolveConfig(QueryShardContext queryShardContext) {
ValuesSourceConfig config = new ValuesSourceConfig(CoreValuesSourceType.BYTES);
joinFieldResolveConfig(queryShardContext, config);
return config;
}

private void joinFieldResolveConfig(QueryShardContext queryShardContext, ValuesSourceConfig<WithOrdinals> config) {
private void joinFieldResolveConfig(QueryShardContext queryShardContext, ValuesSourceConfig config) {
ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService());
ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false);
if (parentIdFieldMapper != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

import org.apache.lucene.search.Query;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.NonCollectingAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
Expand All @@ -36,13 +38,13 @@
import java.util.List;
import java.util.Map;

public class ChildrenAggregatorFactory extends ValuesSourceAggregatorFactory<WithOrdinals> {
public class ChildrenAggregatorFactory extends ValuesSourceAggregatorFactory {

private final Query parentFilter;
private final Query childFilter;

public ChildrenAggregatorFactory(String name,
ValuesSourceConfig<WithOrdinals> config,
ValuesSourceConfig config,
Query childFilter,
Query parentFilter,
QueryShardContext context,
Expand All @@ -67,12 +69,17 @@ public InternalAggregation buildEmptyAggregation() {
}

@Override
protected Aggregator doCreateInternal(WithOrdinals valuesSource,
protected Aggregator doCreateInternal(ValuesSource rawValuesSource,
SearchContext searchContext, Aggregator parent,
boolean collectsFromSingleBucket,
List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData) throws IOException {

if (rawValuesSource instanceof WithOrdinals == false) {
throw new AggregationExecutionException("ValuesSource type " + rawValuesSource.toString() +
"is not supported for aggregation " + this.name());
}
WithOrdinals valuesSource = (WithOrdinals) rawValuesSource;
long maxOrd = valuesSource.globalMaxOrd(searchContext.searcher());
if (collectsFromSingleBucket) {
return new ParentToChildrenAggregator(name, factories, searchContext, parent, childFilter,
Expand Down
Loading