Uday Singh Matta
11/14/2023, 12:04 PM_for_ (DownloadTelemetryDataRequestDto.ParameterAggregationDTO parameterAggregationDTO : parameterAggregationDTOList) {
AggregationRequestDto.Aggregation aggregation = _new_ AggregationRequestDto.Aggregation();
String parameter = parameterAggregationDTO.getParameter(), aggregationType = parameterAggregationDTO.getAggregationType();
aggregation.setFieldName(swappedSchema.get(parameter));
_if_(swappedSchema.containsKey(parameter)){
aggregation.setName(swappedSchema.get(parameter).substring(swappedSchema.get(parameter).indexOf(".") + 1));
}
_if_ (aggregationType.equalsIgnoreCase("min")) aggregation.setType(DRUID_MIN);
_else if_ (aggregationType.equalsIgnoreCase("max")) aggregation.setType(DRUID_MAX);
_else if_ (aggregationType.equalsIgnoreCase("sum")) aggregation.setType(DRUID_SUM);
_else_ aggregation.setType(DRUID_AVG);
aggregationList.add(aggregation);
}
_assert_ dataSource != _null_;
Object query = druidQueryBuilder.buildQueryForTelemetryData(dataSource, deviceIds, aggregationPeriod, dates.get(0), dates.get(1), aggregationList);
JsonNode response = druidHttpClient.druidClientResponse(query, DRUID_NATIVE);
Second one is the difference for which I need to find the first and last values and then sort them according to timestamp and then get the difference like
_if_ (aggregationType.equalsIgnoreCase(DIFF)) {
String interval = startDate + "/" + endDate;
Object requestFirst = druidQueryBuilder.buildDruidQueryTimeZoneAdjusted(attribute, interval, aggregationType, aggregationInvterval, DRUID_STRINGFIRST, timezone, dataSource);
JsonNode responseFirst = druidHttpClient.druidClientResponse(requestFirst, DRUID_NATIVE);
List<DruidAggregationResponseDto> firstResponse = _new_ ArrayList<>();
_if_ (responseFirst != _null_) {
firstResponse = objectMapper.readValue(responseFirst.toPrettyString(), _new_ TypeReference<List<DruidAggregationResponseDto>>() {
});
}
HashMap<String, ValuesDateRangeDto> aggregationHash = _new_ LinkedHashMap<>();
Object requestLast = druidQueryBuilder.buildDruidQueryTimeZoneAdjusted(attribute, interval, aggregationType, aggregationInvterval, DRUID_STRINGLAST, timezone, dataSource);
JsonNode responseLast = druidHttpClient.druidClientResponse(requestLast, DRUID_NATIVE);
List<DruidAggregationResponseDto> lastResponse = _new_ ArrayList<>();
_if_ (responseLast != _null_) {
lastResponse = objectMapper.readValue(responseLast.toPrettyString(), _new_ TypeReference<List<DruidAggregationResponseDto>>() {
});
}
firstResponse = firstResponse.stream()
.sorted(Comparator.comparing(DruidAggregationResponseDto::getTimestamp))
.collect(Collectors.toList());
lastResponse = lastResponse.stream()
.sorted(Comparator.comparing(DruidAggregationResponseDto::getTimestamp))
.collect(Collectors.toList());
_for_ (_int_ i = 0; i < firstResponse.size() && i < lastResponse.size(); i++) {
DruidAggregationResponseDto firstDto = firstResponse.get(i);
DruidAggregationResponseDto lastDto = lastResponse.get(i);
Double diffValue = lastDto.getResult().getValue() - firstDto.getResult().getValue();
}
But now the thing is how to combine the response or call the database with a common query.
Can someone help me out on this...