fix(analytics): fix NPE in aggregate api (#4095)

This commit is contained in:
Dexter Lee 2022-02-08 23:23:18 -08:00 committed by GitHub
parent f944a9ba05
commit beab5ac977
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 16 deletions

View File

@ -56,6 +56,7 @@ public class ESAggregatedStatsDAO {
private static final String ES_TERMS_AGGREGATION_PREFIX = "terms_";
private static final String ES_MAX_AGGREGATION_PREFIX = "max_";
private static final String ES_FIELD_TIMESTAMP = "timestampMillis";
private static final String ES_FIELD_URN = "urn";
private static final String ES_AGG_TIMESTAMP = ES_AGGREGATION_PREFIX + ES_FIELD_TIMESTAMP;
private static final String ES_AGG_MAX_TIMESTAMP =
ES_AGGREGATION_PREFIX + ES_MAX_AGGREGATION_PREFIX + ES_FIELD_TIMESTAMP;
@ -172,11 +173,13 @@ public class ESAggregatedStatsDAO {
if (fieldPath.equals(ES_FIELD_TIMESTAMP)) {
return DataSchema.Type.LONG;
}
/* TODO: Remove if not needed after merge.
if (fieldPath.equals(ES_FIELD_URN)) {
return DataSchema.Type.STRING;
}
if (fieldPath.equals(MappingsBuilder.EVENT_GRANULARITY)) {
return DataSchema.Type.RECORD;
}
*/
String[] memberParts = fieldPath.split("\\.");
if (memberParts.length == 1) {
// Search in the timeseriesFieldSpecs.
@ -439,18 +442,6 @@ public class ESAggregatedStatsDAO {
return lastAggregationBuilder;
}
private boolean isIntegralType(DataSchema.Type fieldType) {
switch (fieldType) {
case INT:
case FLOAT:
case DOUBLE:
case LONG:
return true;
default:
return false;
}
}
private GenericTable generateResponseFromElastic(SearchResponse searchResponse, GroupingBucket[] groupingBuckets,
AggregationSpec[] aggregationSpecs, AspectSpec aspectSpec) {
GenericTable resultTable = new GenericTable();

View File

@ -53,8 +53,12 @@ public class Analytics extends SimpleResourceTemplate<GetTimeseriesAggregatedSta
resp.setEntityName(entityName);
resp.setAspectName(aspectName);
resp.setAggregationSpecs(new AggregationSpecArray(Arrays.asList(aggregationSpecs)));
resp.setFilter(filter);
resp.setGroupingBuckets(new GroupingBucketArray(Arrays.asList(groupingBuckets)));
if (filter != null) {
resp.setFilter(filter);
}
if (groupingBuckets != null) {
resp.setGroupingBuckets(new GroupingBucketArray(Arrays.asList(groupingBuckets)));
}
GenericTable aggregatedStatsTable =
_timeseriesAspectService.getAggregatedStats(entityName, aspectName, aggregationSpecs, filter,