set ValuesSourceConfig fields as private
This commit is contained in:
parent
90b8f5d0d8
commit
54575e55ca
|
@ -61,29 +61,30 @@ public class AggregationContext {
|
|||
assert config.valid() : "value source config is invalid - must have either a field context or a script or marked as unmapped";
|
||||
|
||||
final VS vs;
|
||||
if (config.unmapped) {
|
||||
if (config.missing == null) {
|
||||
if (config.unmapped()) {
|
||||
if (config.missing() == null) {
|
||||
// otherwise we will have values because of the missing value
|
||||
vs = null;
|
||||
} else if (config.valueSourceType == ValuesSourceType.NUMERIC) {
|
||||
} else if (config.valueSourceType() == ValuesSourceType.NUMERIC) {
|
||||
vs = (VS) ValuesSource.Numeric.EMPTY;
|
||||
} else if (config.valueSourceType == ValuesSourceType.GEOPOINT) {
|
||||
} else if (config.valueSourceType() == ValuesSourceType.GEOPOINT) {
|
||||
vs = (VS) ValuesSource.GeoPoint.EMPTY;
|
||||
} else if (config.valueSourceType == ValuesSourceType.ANY || config.valueSourceType == ValuesSourceType.BYTES) {
|
||||
} else if (config.valueSourceType() == ValuesSourceType.ANY || config.valueSourceType() == ValuesSourceType.BYTES) {
|
||||
vs = (VS) ValuesSource.Bytes.EMPTY;
|
||||
} else {
|
||||
throw new SearchParseException(searchContext, "Can't deal with unmapped ValuesSource type " + config.valueSourceType, null);
|
||||
throw new SearchParseException(searchContext, "Can't deal with unmapped ValuesSource type "
|
||||
+ config.valueSourceType(), null);
|
||||
}
|
||||
} else {
|
||||
vs = originalValuesSource(config);
|
||||
}
|
||||
|
||||
if (config.missing == null) {
|
||||
if (config.missing() == null) {
|
||||
return vs;
|
||||
}
|
||||
|
||||
if (vs instanceof ValuesSource.Bytes) {
|
||||
final BytesRef missing = new BytesRef(config.missing.toString());
|
||||
final BytesRef missing = new BytesRef(config.missing().toString());
|
||||
if (vs instanceof ValuesSource.Bytes.WithOrdinals) {
|
||||
return (VS) MissingValues.replaceMissing((ValuesSource.Bytes.WithOrdinals) vs, missing);
|
||||
} else {
|
||||
|
@ -91,20 +92,20 @@ public class AggregationContext {
|
|||
}
|
||||
} else if (vs instanceof ValuesSource.Numeric) {
|
||||
Number missing = null;
|
||||
if (config.missing instanceof Number) {
|
||||
missing = (Number) config.missing;
|
||||
if (config.missing() instanceof Number) {
|
||||
missing = (Number) config.missing();
|
||||
} else {
|
||||
if (config.fieldContext != null && config.fieldContext.fieldType() != null) {
|
||||
missing = config.fieldContext.fieldType().docValueFormat(null, DateTimeZone.UTC)
|
||||
.parseDouble(config.missing.toString(), false, context.nowCallable());
|
||||
if (config.fieldContext() != null && config.fieldContext().fieldType() != null) {
|
||||
missing = config.fieldContext().fieldType().docValueFormat(null, DateTimeZone.UTC)
|
||||
.parseDouble(config.missing().toString(), false, context.nowCallable());
|
||||
} else {
|
||||
missing = Double.parseDouble(config.missing.toString());
|
||||
missing = Double.parseDouble(config.missing().toString());
|
||||
}
|
||||
}
|
||||
return (VS) MissingValues.replaceMissing((ValuesSource.Numeric) vs, missing);
|
||||
} else if (vs instanceof ValuesSource.GeoPoint) {
|
||||
// TODO: also support the structured formats of geo points
|
||||
final GeoPoint missing = GeoUtils.parseGeoPoint(config.missing.toString(), new GeoPoint());
|
||||
final GeoPoint missing = GeoUtils.parseGeoPoint(config.missing().toString(), new GeoPoint());
|
||||
return (VS) MissingValues.replaceMissing((ValuesSource.GeoPoint) vs, missing);
|
||||
} else {
|
||||
// Should not happen
|
||||
|
@ -116,21 +117,21 @@ public class AggregationContext {
|
|||
* Return the original values source, before we apply `missing`.
|
||||
*/
|
||||
private <VS extends ValuesSource> VS originalValuesSource(ValuesSourceConfig<VS> config) throws IOException {
|
||||
if (config.fieldContext == null) {
|
||||
if (config.valueSourceType == ValuesSourceType.NUMERIC) {
|
||||
if (config.fieldContext() == null) {
|
||||
if (config.valueSourceType() == ValuesSourceType.NUMERIC) {
|
||||
return (VS) numericScript(config);
|
||||
}
|
||||
if (config.valueSourceType == ValuesSourceType.BYTES) {
|
||||
if (config.valueSourceType() == ValuesSourceType.BYTES) {
|
||||
return (VS) bytesScript(config);
|
||||
}
|
||||
throw new AggregationExecutionException("value source of type [" + config.valueSourceType.name()
|
||||
throw new AggregationExecutionException("value source of type [" + config.valueSourceType().name()
|
||||
+ "] is not supported by scripts");
|
||||
}
|
||||
|
||||
if (config.valueSourceType == ValuesSourceType.NUMERIC) {
|
||||
if (config.valueSourceType() == ValuesSourceType.NUMERIC) {
|
||||
return (VS) numericField(config);
|
||||
}
|
||||
if (config.valueSourceType == ValuesSourceType.GEOPOINT) {
|
||||
if (config.valueSourceType() == ValuesSourceType.GEOPOINT) {
|
||||
return (VS) geoPointField(config);
|
||||
}
|
||||
// falling back to bytes values
|
||||
|
@ -138,25 +139,25 @@ public class AggregationContext {
|
|||
}
|
||||
|
||||
private ValuesSource.Numeric numericScript(ValuesSourceConfig<?> config) throws IOException {
|
||||
return new ValuesSource.Numeric.Script(config.script, config.scriptValueType);
|
||||
return new ValuesSource.Numeric.Script(config.script(), config.scriptValueType());
|
||||
}
|
||||
|
||||
private ValuesSource.Numeric numericField(ValuesSourceConfig<?> config) throws IOException {
|
||||
|
||||
if (!(config.fieldContext.indexFieldData() instanceof IndexNumericFieldData)) {
|
||||
throw new IllegalArgumentException("Expected numeric type on field [" + config.fieldContext.field() +
|
||||
"], but got [" + config.fieldContext.fieldType().typeName() + "]");
|
||||
if (!(config.fieldContext().indexFieldData() instanceof IndexNumericFieldData)) {
|
||||
throw new IllegalArgumentException("Expected numeric type on field [" + config.fieldContext().field() +
|
||||
"], but got [" + config.fieldContext().fieldType().typeName() + "]");
|
||||
}
|
||||
|
||||
ValuesSource.Numeric dataSource = new ValuesSource.Numeric.FieldData((IndexNumericFieldData) config.fieldContext.indexFieldData());
|
||||
if (config.script != null) {
|
||||
dataSource = new ValuesSource.Numeric.WithScript(dataSource, config.script);
|
||||
ValuesSource.Numeric dataSource = new ValuesSource.Numeric.FieldData((IndexNumericFieldData)config.fieldContext().indexFieldData());
|
||||
if (config.script() != null) {
|
||||
dataSource = new ValuesSource.Numeric.WithScript(dataSource, config.script());
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
private ValuesSource bytesField(ValuesSourceConfig<?> config) throws IOException {
|
||||
final IndexFieldData<?> indexFieldData = config.fieldContext.indexFieldData();
|
||||
final IndexFieldData<?> indexFieldData = config.fieldContext().indexFieldData();
|
||||
ValuesSource dataSource;
|
||||
if (indexFieldData instanceof ParentChildIndexFieldData) {
|
||||
dataSource = new ValuesSource.Bytes.WithOrdinals.ParentChild((ParentChildIndexFieldData) indexFieldData);
|
||||
|
@ -165,24 +166,24 @@ public class AggregationContext {
|
|||
} else {
|
||||
dataSource = new ValuesSource.Bytes.FieldData(indexFieldData);
|
||||
}
|
||||
if (config.script != null) {
|
||||
dataSource = new ValuesSource.WithScript(dataSource, config.script);
|
||||
if (config.script() != null) {
|
||||
dataSource = new ValuesSource.WithScript(dataSource, config.script());
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
private ValuesSource.Bytes bytesScript(ValuesSourceConfig<?> config) throws IOException {
|
||||
return new ValuesSource.Bytes.Script(config.script);
|
||||
return new ValuesSource.Bytes.Script(config.script());
|
||||
}
|
||||
|
||||
private ValuesSource.GeoPoint geoPointField(ValuesSourceConfig<?> config) throws IOException {
|
||||
|
||||
if (!(config.fieldContext.indexFieldData() instanceof IndexGeoPointFieldData)) {
|
||||
throw new IllegalArgumentException("Expected geo_point type on field [" + config.fieldContext.field() +
|
||||
"], but got [" + config.fieldContext.fieldType().typeName() + "]");
|
||||
if (!(config.fieldContext().indexFieldData() instanceof IndexGeoPointFieldData)) {
|
||||
throw new IllegalArgumentException("Expected geo_point type on field [" + config.fieldContext().field() +
|
||||
"], but got [" + config.fieldContext().fieldType().typeName() + "]");
|
||||
}
|
||||
|
||||
return new ValuesSource.GeoPoint.Fielddata((IndexGeoPointFieldData) config.fieldContext.indexFieldData());
|
||||
return new ValuesSource.GeoPoint.Fielddata((IndexGeoPointFieldData) config.fieldContext().indexFieldData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -317,7 +317,7 @@ public abstract class ValuesSourceAggregationBuilder<VS extends ValuesSource, AB
|
|||
if (script == null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ValuesSourceConfig<VS> config = new ValuesSourceConfig(ValuesSourceType.ANY);
|
||||
config.format = resolveFormat(null, valueType);
|
||||
config.format(resolveFormat(null, valueType));
|
||||
return config;
|
||||
}
|
||||
ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType;
|
||||
|
@ -329,11 +329,11 @@ public abstract class ValuesSourceAggregationBuilder<VS extends ValuesSource, AB
|
|||
valuesSourceType = ValuesSourceType.BYTES;
|
||||
}
|
||||
ValuesSourceConfig<VS> config = new ValuesSourceConfig<VS>(valuesSourceType);
|
||||
config.missing = missing;
|
||||
config.timeZone = timeZone;
|
||||
config.format = resolveFormat(format, valueType);
|
||||
config.script = createScript(script, context.searchContext());
|
||||
config.scriptValueType = valueType;
|
||||
config.missing(missing);
|
||||
config.timezone(timeZone);
|
||||
config.format(resolveFormat(format, valueType));
|
||||
config.script(createScript(script, context.searchContext()));
|
||||
config.scriptValueType(valueType);
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -341,13 +341,13 @@ public abstract class ValuesSourceAggregationBuilder<VS extends ValuesSource, AB
|
|||
if (fieldType == null) {
|
||||
ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType;
|
||||
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType);
|
||||
config.missing = missing;
|
||||
config.timeZone = timeZone;
|
||||
config.format = resolveFormat(format, valueType);
|
||||
config.unmapped = true;
|
||||
config.missing(missing);
|
||||
config.timezone(timeZone);
|
||||
config.format(resolveFormat(format, valueType));
|
||||
config.unmapped(true);
|
||||
if (valueType != null) {
|
||||
// todo do we really need this for unmapped?
|
||||
config.scriptValueType = valueType;
|
||||
config.scriptValueType(valueType);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
@ -367,11 +367,11 @@ public abstract class ValuesSourceAggregationBuilder<VS extends ValuesSource, AB
|
|||
config = new ValuesSourceConfig(valuesSourceType);
|
||||
}
|
||||
|
||||
config.fieldContext = new FieldContext(field, indexFieldData, fieldType);
|
||||
config.missing = missing;
|
||||
config.timeZone = timeZone;
|
||||
config.script = createScript(script, context.searchContext());
|
||||
config.format = fieldType.docValueFormat(format, timeZone);
|
||||
config.fieldContext(new FieldContext(field, indexFieldData, fieldType));
|
||||
config.missing(missing);
|
||||
config.timezone(timeZone);
|
||||
config.script(createScript(script, context.searchContext()));
|
||||
config.format(fieldType.docValueFormat(format, timeZone));
|
||||
return config;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource, AF
|
|||
}
|
||||
|
||||
public DateTimeZone timeZone() {
|
||||
return config.timeZone;
|
||||
return config.timezone();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,4 +62,4 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource, AF
|
|||
boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
|
||||
throws IOException;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,15 +27,15 @@ import org.joda.time.DateTimeZone;
|
|||
*/
|
||||
public class ValuesSourceConfig<VS extends ValuesSource> {
|
||||
|
||||
final ValuesSourceType valueSourceType;
|
||||
FieldContext fieldContext;
|
||||
SearchScript script;
|
||||
ValueType scriptValueType;
|
||||
boolean unmapped = false;
|
||||
String formatPattern;
|
||||
DocValueFormat format = DocValueFormat.RAW;
|
||||
Object missing;
|
||||
DateTimeZone timeZone;
|
||||
private final ValuesSourceType valueSourceType;
|
||||
private FieldContext fieldContext;
|
||||
private SearchScript script;
|
||||
private ValueType scriptValueType;
|
||||
private boolean unmapped = false;
|
||||
private String formatPattern;
|
||||
private DocValueFormat format = DocValueFormat.RAW;
|
||||
private Object missing;
|
||||
private DateTimeZone timeZone;
|
||||
|
||||
public ValuesSourceConfig(ValuesSourceType valueSourceType) {
|
||||
this.valueSourceType = valueSourceType;
|
||||
|
@ -71,6 +71,15 @@ public class ValuesSourceConfig<VS extends ValuesSource> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ValuesSourceConfig<VS> scriptValueType(ValueType scriptValueType) {
|
||||
this.scriptValueType = scriptValueType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ValueType scriptValueType() {
|
||||
return this.scriptValueType;
|
||||
}
|
||||
|
||||
public ValuesSourceConfig<VS> unmapped(boolean unmapped) {
|
||||
this.unmapped = unmapped;
|
||||
return this;
|
||||
|
@ -86,11 +95,19 @@ public class ValuesSourceConfig<VS extends ValuesSource> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Object missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public ValuesSourceConfig<VS> timezone(final DateTimeZone timeZone) {
|
||||
this.timeZone= timeZone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DateTimeZone timezone() {
|
||||
return this.timeZone;
|
||||
}
|
||||
|
||||
public DocValueFormat format() {
|
||||
return format;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.elasticsearch.index.mapper.MappedFieldType;
|
|||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.aggregations.AggregationInitializationException;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
|
@ -48,7 +48,7 @@ import java.util.Objects;
|
|||
*
|
||||
*/
|
||||
public abstract class MultiValuesSourceAggregationBuilder<VS extends ValuesSource, AB extends MultiValuesSourceAggregationBuilder<VS, AB>>
|
||||
extends AggregationBuilder<AB> {
|
||||
extends AbstractAggregationBuilder<AB> {
|
||||
|
||||
public static final ParseField MULTIVALUE_MODE_FIELD = new ParseField("mode");
|
||||
|
||||
|
|
Loading…
Reference in New Issue