Skip to content

Soft immutability for VSConfig #52729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Aggregator createInternal(SearchContext searchContext,
HashMap<String, ValuesSource> valuesSources = new HashMap<>();

for (Map.Entry<String, ValuesSourceConfig> config : configs.entrySet()) {
ValuesSource vs = config.getValue().toValuesSource(queryShardContext);
ValuesSource vs = config.getValue().toValuesSource();
if (vs != null) {
valuesSources.put(config.getKey(), vs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.join.mapper.ParentIdFieldMapper;
Expand All @@ -34,7 +33,6 @@
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.FieldContext;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
Expand Down Expand Up @@ -109,23 +107,19 @@ protected ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardC

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

private void joinFieldResolveConfig(QueryShardContext queryShardContext, ValuesSourceConfig config) {
ValuesSourceConfig config;
ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService());
ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false);
if (parentIdFieldMapper != null) {
parentFilter = parentIdFieldMapper.getParentFilter();
childFilter = parentIdFieldMapper.getChildFilter(childType);
MappedFieldType fieldType = parentIdFieldMapper.fieldType();
final SortedSetDVOrdinalsIndexFieldData fieldData = queryShardContext.getForField(fieldType);
config.fieldContext(new FieldContext(fieldType.name(), fieldData, fieldType));
config = new ValuesSourceConfig(fieldType.getValuesSourceType(), fieldType, queryShardContext);
} else {
config.unmapped(true);
// Unmapped field case
config = new ValuesSourceConfig(defaultValueSourceType(), queryShardContext);
}
return config;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.join.mapper.ParentIdFieldMapper;
Expand All @@ -34,7 +33,6 @@
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.FieldContext;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
Expand Down Expand Up @@ -109,23 +107,19 @@ protected ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardC

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

private void joinFieldResolveConfig(QueryShardContext queryShardContext, ValuesSourceConfig config) {
ValuesSourceConfig config; // = new ValuesSourceConfig(CoreValuesSourceType.BYTES, null, null);
ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService());
ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false);
if (parentIdFieldMapper != null) {
parentFilter = parentIdFieldMapper.getParentFilter();
childFilter = parentIdFieldMapper.getChildFilter(childType);
MappedFieldType fieldType = parentIdFieldMapper.fieldType();
final SortedSetDVOrdinalsIndexFieldData fieldData = queryShardContext.getForField(fieldType);
config.fieldContext(new FieldContext(fieldType.name(), fieldData, fieldType));
config = new ValuesSourceConfig(fieldType.getValuesSourceType(), fieldType, queryShardContext);
} else {
config.unmapped(true);
// unmapped case
config = new ValuesSourceConfig(defaultValueSourceType(), queryShardContext);
}
return config;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.script.Script;
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.ValuesSourceConfig;
Expand Down Expand Up @@ -277,7 +278,7 @@ protected abstract CompositeValuesSourceConfig innerBuild(QueryShardContext quer

public final CompositeValuesSourceConfig build(QueryShardContext queryShardContext) throws IOException {
ValuesSourceConfig config = ValuesSourceConfig.resolve(queryShardContext,
valueType, field, script, null, timeZone(), format, name());
valueType, field, script, null, timeZone(), format, CoreValuesSourceType.BYTES, name());
return innerBuild(queryShardContext, config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public DateHistogramValuesSourceBuilder offset(long offset) {
@Override
protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException {
Rounding rounding = dateHistogramInterval.createRounding(timeZone(), offset);
ValuesSource orig = config.toValuesSource(queryShardContext);
ValuesSource orig = config.toValuesSource();
if (orig == null) {
orig = ValuesSource.Numeric.EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public boolean equals(Object obj) {

@Override
protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException {
ValuesSource orig = config.toValuesSource(queryShardContext);
ValuesSource orig = config.toValuesSource();
if (orig == null) {
orig = ValuesSource.GeoPoint.EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public HistogramValuesSourceBuilder interval(double interval) {

@Override
protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException {
ValuesSource orig = config.toValuesSource(queryShardContext);
ValuesSource orig = config.toValuesSource();
if (orig == null) {
orig = ValuesSource.Numeric.EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String type() {

@Override
protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException {
ValuesSource vs = config.toValuesSource(queryShardContext);
ValuesSource vs = config.toValuesSource();
if (vs == null) {
// The field is unmapped so we use a value source that can parse any type of values.
// This is needed because the after values are parsed even when there are no values to process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public NumericMultiValuesSource(Map<String, ValuesSourceConfig> valuesSourceConf
QueryShardContext context) {
values = new HashMap<>(valuesSourceConfigs.size());
for (Map.Entry<String, ValuesSourceConfig> entry : valuesSourceConfigs.entrySet()) {
final ValuesSource valuesSource = entry.getValue().toValuesSource(context);
final ValuesSource valuesSource = entry.getValue().toValuesSource();
if (valuesSource instanceof ValuesSource.Numeric == false) {
throw new AggregationExecutionException("ValuesSource type " + valuesSource.toString() +
"is not supported for multi-valued aggregation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ValuesSourceAggregatorFactory(String name, ValuesSourceConfig config, Que
@Override
public Aggregator createInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket,
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
ValuesSource vs = config.toValuesSource(queryShardContext);
ValuesSource vs = config.toValuesSource();
if (vs == null) {
return createUnmapped(searchContext, parent, pipelineAggregators, metaData);
}
Expand Down
Loading