|
@@ -10,6 +10,7 @@ import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.cluster.AbstractDiffable;
|
|
|
import org.elasticsearch.common.ParseField;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
+import org.elasticsearch.common.TriFunction;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
import org.elasticsearch.common.unit.TimeValue;
|
|
@@ -46,7 +47,6 @@ import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Random;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.function.BiFunction;
|
|
|
|
|
|
/**
|
|
|
* Datafeed configuration options. Describes where to proactively pull input
|
|
@@ -65,9 +65,10 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> implements
|
|
|
private static final int TWENTY_MINS_SECONDS = 20 * SECONDS_IN_MINUTE;
|
|
|
private static final int HALF_DAY_SECONDS = 12 * 60 * SECONDS_IN_MINUTE;
|
|
|
static final XContentObjectTransformer<QueryBuilder> QUERY_TRANSFORMER = XContentObjectTransformer.queryBuilderTransformer();
|
|
|
- private static final BiFunction<Map<String, Object>, String, QueryBuilder> lazyQueryParser = (objectMap, id) -> {
|
|
|
+ static final TriFunction<Map<String, Object>, String, List<String>, QueryBuilder> lazyQueryParser =
|
|
|
+ (objectMap, id, warnings) -> {
|
|
|
try {
|
|
|
- return QUERY_TRANSFORMER.fromMap(objectMap);
|
|
|
+ return QUERY_TRANSFORMER.fromMap(objectMap, warnings);
|
|
|
} catch (IOException | XContentParseException exception) {
|
|
|
// Certain thrown exceptions wrap up the real Illegal argument making it hard to determine cause for the user
|
|
|
if (exception.getCause() instanceof IllegalArgumentException) {
|
|
@@ -85,9 +86,10 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> implements
|
|
|
};
|
|
|
|
|
|
static final XContentObjectTransformer<AggregatorFactories.Builder> AGG_TRANSFORMER = XContentObjectTransformer.aggregatorTransformer();
|
|
|
- private static final BiFunction<Map<String, Object>, String, AggregatorFactories.Builder> lazyAggParser = (objectMap, id) -> {
|
|
|
+ static final TriFunction<Map<String, Object>, String, List<String>, AggregatorFactories.Builder> lazyAggParser =
|
|
|
+ (objectMap, id, warnings) -> {
|
|
|
try {
|
|
|
- return AGG_TRANSFORMER.fromMap(objectMap);
|
|
|
+ return AGG_TRANSFORMER.fromMap(objectMap, warnings);
|
|
|
} catch (IOException | XContentParseException exception) {
|
|
|
// Certain thrown exceptions wrap up the real Illegal argument making it hard to determine cause for the user
|
|
|
if (exception.getCause() instanceof IllegalArgumentException) {
|
|
@@ -237,8 +239,8 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> implements
|
|
|
this.chunkingConfig = chunkingConfig;
|
|
|
this.headers = Collections.unmodifiableMap(headers);
|
|
|
this.delayedDataCheckConfig = delayedDataCheckConfig;
|
|
|
- this.querySupplier = new CachedSupplier<>(() -> lazyQueryParser.apply(query, id));
|
|
|
- this.aggSupplier = new CachedSupplier<>(() -> lazyAggParser.apply(aggregations, id));
|
|
|
+ this.querySupplier = new CachedSupplier<>(() -> lazyQueryParser.apply(query, id, new ArrayList<>()));
|
|
|
+ this.aggSupplier = new CachedSupplier<>(() -> lazyAggParser.apply(aggregations, id, new ArrayList<>()));
|
|
|
}
|
|
|
|
|
|
public DatafeedConfig(StreamInput in) throws IOException {
|
|
@@ -284,8 +286,8 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> implements
|
|
|
} else {
|
|
|
delayedDataCheckConfig = DelayedDataCheckConfig.defaultDelayedDataCheckConfig();
|
|
|
}
|
|
|
- this.querySupplier = new CachedSupplier<>(() -> lazyQueryParser.apply(query, id));
|
|
|
- this.aggSupplier = new CachedSupplier<>(() -> lazyAggParser.apply(aggregations, id));
|
|
|
+ this.querySupplier = new CachedSupplier<>(() -> lazyQueryParser.apply(query, id, new ArrayList<>()));
|
|
|
+ this.aggSupplier = new CachedSupplier<>(() -> lazyAggParser.apply(aggregations, id, new ArrayList<>()));
|
|
|
}
|
|
|
|
|
|
public String getId() {
|
|
@@ -320,6 +322,20 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> implements
|
|
|
return querySupplier.get();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Calls the lazy parser and returns any gathered deprecations
|
|
|
+ * @return The deprecations from parsing the query
|
|
|
+ */
|
|
|
+ public List<String> getQueryDeprecations() {
|
|
|
+ return getQueryDeprecations(lazyQueryParser);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> getQueryDeprecations(TriFunction<Map<String, Object>, String, List<String>, QueryBuilder> parser) {
|
|
|
+ List<String> deprecations = new ArrayList<>();
|
|
|
+ parser.apply(query, id, deprecations);
|
|
|
+ return deprecations;
|
|
|
+ }
|
|
|
+
|
|
|
public Map<String, Object> getQuery() {
|
|
|
return query;
|
|
|
}
|
|
@@ -328,6 +344,20 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> implements
|
|
|
return aggSupplier.get();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Calls the lazy parser and returns any gathered deprecations
|
|
|
+ * @return The deprecations from parsing the aggregations
|
|
|
+ */
|
|
|
+ public List<String> getAggDeprecations() {
|
|
|
+ return getAggDeprecations(lazyAggParser);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> getAggDeprecations(TriFunction<Map<String, Object>, String, List<String>, AggregatorFactories.Builder> parser) {
|
|
|
+ List<String> deprecations = new ArrayList<>();
|
|
|
+ parser.apply(aggregations, id, deprecations);
|
|
|
+ return deprecations;
|
|
|
+ }
|
|
|
+
|
|
|
public Map<String, Object> getAggregations() {
|
|
|
return aggregations;
|
|
|
}
|
|
@@ -758,7 +788,8 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> implements
|
|
|
if (aggregations == null) {
|
|
|
chunkingConfig = ChunkingConfig.newAuto();
|
|
|
} else {
|
|
|
- long histogramIntervalMillis = ExtractorUtils.getHistogramIntervalMillis(lazyAggParser.apply(aggregations, id));
|
|
|
+ long histogramIntervalMillis =
|
|
|
+ ExtractorUtils.getHistogramIntervalMillis(lazyAggParser.apply(aggregations, id, new ArrayList<>()));
|
|
|
chunkingConfig = ChunkingConfig.newManual(TimeValue.timeValueMillis(
|
|
|
DEFAULT_AGGREGATION_CHUNKING_BUCKETS * histogramIntervalMillis));
|
|
|
}
|