Skip to content

Commit

Permalink
rounding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
not-napoleon committed Sep 27, 2023
1 parent ae42755 commit ccb08a0
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public static RuntimeException rateWithoutDateHistogram(String name) {
);
}

/**
* This error indicates that the backing indices for a field have different, incompatible, types (e.g. IP and Keyword). This
* causes a failure at reduce time, and is not retryable (and thus should be a 400 class error)
*
* @param aggregationName - The name of the aggregation
* @param position - optional, for multisource aggregations. Indicates the position of the field causing the problem.
* @return - an appropriate exception
*/
public static RuntimeException reduceTypeMissmatch(String aggregationName, Optional<Integer> position) {
String fieldString;
if (position.isPresent()) {
Expand All @@ -85,10 +93,23 @@ public static RuntimeException unsupportedScriptValue(String actual) {
return new IllegalArgumentException("Unsupported script value [" + actual + "], expected a number, date, or boolean");
}

/**
* Indicates that a multivalued field was found where we only support a single valued field
* @return an appropriate exception
*/
public static RuntimeException unsupportedMultivalue() {
return new IllegalArgumentException(
"Encountered more than one value for a "
+ "single document. Use a script to combine multiple values per doc into a single value."
);
}

/**
* Indicates an attempt to use date rounding on a non-date values source
* @param typeName - name of the type we're attempting to round
* @return an appropriate exception
*/
public static RuntimeException unsupportedRounding(String typeName) {
return new IllegalArgumentException("can't round a [" + typeName + "]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.AggregationErrors;

import java.io.IOException;
import java.util.Map;
Expand All @@ -28,9 +28,7 @@ public NumericMultiValuesSource(Map<String, ValuesSourceConfig> valuesSourceConf
for (Map.Entry<String, ValuesSourceConfig> entry : valuesSourceConfigs.entrySet()) {
final ValuesSource valuesSource = entry.getValue().getValuesSource();
if (valuesSource instanceof ValuesSource.Numeric == false) {
throw new AggregationExecutionException(
"ValuesSource type " + valuesSource.toString() + "is not supported for multi-valued aggregation"
);
throw AggregationErrors.unsupportedValuesSourceType(valuesSource, "multi-value");
}
values.put(entry.getKey(), (ValuesSource.Numeric) valuesSource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.elasticsearch.index.mapper.RangeType;
import org.elasticsearch.script.AggregationScript;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.AggregationErrors;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileCellIdSource;
import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator;
Expand Down Expand Up @@ -116,7 +116,7 @@ public DocValueBits docsWithValue(LeafReaderContext context) throws IOException

@Override
public final Function<Rounding, Rounding.Prepared> roundingPreparer(AggregationContext context) throws IOException {
throw new AggregationExecutionException("can't round a [BYTES]");
throw AggregationErrors.unsupportedRounding("BYTES");
}

/**
Expand Down Expand Up @@ -723,7 +723,7 @@ public DocValueBits docsWithValue(LeafReaderContext context) throws IOException

@Override
public final Function<Rounding, Rounding.Prepared> roundingPreparer(AggregationContext context) throws IOException {
throw new AggregationExecutionException("can't round a [GEO_POINT]");
throw AggregationErrors.unsupportedRounding("GEO_POINT");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.elasticsearch.index.fielddata.HistogramValues;
import org.elasticsearch.index.fielddata.IndexHistogramFieldData;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.AggregationErrors;
import org.elasticsearch.search.aggregations.support.AggregationContext;

import java.io.IOException;
Expand All @@ -27,7 +27,7 @@ public abstract static class Histogram extends org.elasticsearch.search.aggregat

@Override
public Function<Rounding, Prepared> roundingPreparer(AggregationContext context) throws IOException {
throw new AggregationExecutionException("can't round a [histogram]");
throw AggregationErrors.unsupportedRounding("histogram");
}

public static class Fielddata extends Histogram {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.elasticsearch.index.fielddata.DocValueBits;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.AggregationErrors;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.xpack.aggregatemetric.fielddata.IndexAggregateDoubleMetricFieldData;
import org.elasticsearch.xpack.aggregatemetric.mapper.AggregateDoubleMetricFieldMapper;
Expand Down Expand Up @@ -51,7 +51,7 @@ public boolean advanceExact(int doc) throws IOException {

@Override
protected Function<Rounding, Rounding.Prepared> roundingPreparer(AggregationContext context) throws IOException {
throw new AggregationExecutionException("Can't round an [" + AggregateDoubleMetricFieldMapper.CONTENT_TYPE + "]");
throw AggregationErrors.unsupportedRounding(AggregateDoubleMetricFieldMapper.CONTENT_TYPE);
}

public SortedNumericDoubleValues getAggregateMetricValues(LeafReaderContext context, Metric metric) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.elasticsearch.index.fielddata.MultiPointValues;
import org.elasticsearch.index.fielddata.PointValues;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.AggregationErrors;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.xcontent.ToXContentFragment;
Expand Down Expand Up @@ -51,7 +51,7 @@ public DocValueBits docsWithValue(LeafReaderContext context) {

@Override
public final Function<Rounding, Rounding.Prepared> roundingPreparer(AggregationContext context) {
throw new AggregationExecutionException("can't round a [POINT]");
throw AggregationErrors.unsupportedRounding("POINT");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.common.Rounding;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.AggregationErrors;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.xpack.spatial.index.fielddata.CartesianShapeValues;
import org.elasticsearch.xpack.spatial.index.fielddata.IndexShapeFieldData;
Expand All @@ -28,7 +28,7 @@ public CartesianShapeValues shapeValues(LeafReaderContext context) {

@Override
protected Function<Rounding, Rounding.Prepared> roundingPreparer(AggregationContext context) {
throw new AggregationExecutionException("can't round a [shape]");
throw AggregationErrors.unsupportedRounding("shape");
}

public static class Fielddata extends CartesianShapeValuesSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.common.Rounding;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.AggregationErrors;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues;
import org.elasticsearch.xpack.spatial.index.fielddata.IndexShapeFieldData;
Expand All @@ -28,7 +28,7 @@ public GeoShapeValues shapeValues(LeafReaderContext context) {

@Override
protected Function<Rounding, Rounding.Prepared> roundingPreparer(AggregationContext context) {
throw new AggregationExecutionException("can't round a [geo_shape]");
throw AggregationErrors.unsupportedRounding("geo_shape");
}

public static class Fielddata extends GeoShapeValuesSource {
Expand Down

0 comments on commit ccb08a0

Please sign in to comment.