Skip to content

Commit cda3e51

Browse files
committed
If responseContext keys are null.....
1 parent 05c1f2b commit cda3e51

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryMetrics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public interface GroupByQueryMetrics extends QueryMetrics<GroupByQuery>
4242
void numMetrics(GroupByQuery query);
4343

4444
/**
45-
* Sets the number of "complex" metrics of the given groupBy query as dimension. By default it is assumed that
45+
* Sets the number of "complex" metrics of the given groupBy query as dimension. By default, it is assumed that
4646
* "complex" metric is a metric of not long or double type, but it could be redefined in the implementation of this
4747
* method.
4848
*/

processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ private Sequence<ResultRow> initAndMergeGroupByResults(
189189

190190
if (reportMetricsForEmission) {
191191
GroupByQueryMetrics queryMetrics = (GroupByQueryMetrics) queryPlus.getQueryMetrics();
192-
queryMetrics.bytesSpilledToStorage((Long) context.get(GroupByResponseContextKeys.GROUPBY_BYTES_SPILLED_TO_STORAGE_KEY));
193-
queryMetrics.mergeDictionarySize((Long) context.get(GroupByResponseContextKeys.GROUPBY_MERGE_DICTIONARY_SIZE_KEY));
194-
queryMetrics.mergeBufferAcquisitionTime((Long) context.get(GroupByResponseContextKeys.GROUPBY_MERGE_BUFFER_ACQUISITION_TIME_KEY));
192+
populateQueryMetrics(queryMetrics, context);
195193
groupByStatsProvider.aggregateStats(queryMetrics);
196194
}
197195

@@ -207,6 +205,27 @@ private Sequence<ResultRow> initAndMergeGroupByResults(
207205
}
208206
}
209207

208+
private void populateQueryMetrics(GroupByQueryMetrics queryMetrics, ResponseContext context)
209+
{
210+
Object bytesSpilledToStorage = context.get(GroupByResponseContextKeys.GROUPBY_BYTES_SPILLED_TO_STORAGE_KEY);
211+
212+
if (bytesSpilledToStorage != null) {
213+
queryMetrics.bytesSpilledToStorage((Long) bytesSpilledToStorage);
214+
}
215+
216+
Object mergeDictionarySize = context.get(GroupByResponseContextKeys.GROUPBY_MERGE_DICTIONARY_SIZE_KEY);
217+
218+
if (mergeDictionarySize != null) {
219+
queryMetrics.mergeDictionarySize((Long) mergeDictionarySize);
220+
}
221+
222+
Object mergeBufferAcquisitionTime = context.get(GroupByResponseContextKeys.GROUPBY_MERGE_BUFFER_ACQUISITION_TIME_KEY);
223+
224+
if (mergeBufferAcquisitionTime != null) {
225+
queryMetrics.mergeBufferAcquisitionTime((Long) mergeBufferAcquisitionTime);
226+
}
227+
}
228+
210229
private Sequence<ResultRow> mergeGroupByResults(
211230
final GroupByQuery query,
212231
GroupByQueryResources resource,

processing/src/main/java/org/apache/druid/query/groupby/GroupByResponseContextKeys.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import org.apache.druid.query.context.ResponseContext;
2323

24+
import javax.annotation.Nullable;
25+
2426
/**
2527
* Response context keys for GroupBy query metrics.
2628
* These keys are used to aggregate metrics from parallel query execution threads
@@ -32,6 +34,20 @@ public class GroupByResponseContextKeys
3234
public static final String GROUPBY_BYTES_SPILLED_TO_STORAGE_NAME = "groupByBytesSpilledToStorage";
3335
public static final String GROUPBY_MERGE_DICTIONARY_SIZE_NAME = "groupByMergeDictionarySize";
3436

37+
private static Object mergeMax(@Nullable Object oldValue, @Nullable Object newValue)
38+
{
39+
if (oldValue == null && newValue == null) {
40+
return 0L;
41+
}
42+
43+
if (oldValue == null) {
44+
return newValue;
45+
} else if (newValue == null) {
46+
return oldValue;
47+
}
48+
49+
return Math.max((Long) oldValue, (Long) newValue);
50+
}
3551
/**
3652
* Maximum bytes spilled to storage across all parallel threads processing segments.
3753
* This represents the peak disk usage during query execution.
@@ -42,7 +58,7 @@ public class GroupByResponseContextKeys
4258
@Override
4359
public Object mergeValues(Object oldValue, Object newValue)
4460
{
45-
return Math.max((Long) oldValue, (Long) newValue);
61+
return mergeMax(oldValue, newValue);
4662
}
4763
};
4864

@@ -56,7 +72,7 @@ public Object mergeValues(Object oldValue, Object newValue)
5672
@Override
5773
public Object mergeValues(Object oldValue, Object newValue)
5874
{
59-
return Math.max((Long) oldValue, (Long) newValue);
75+
return mergeMax(oldValue, newValue);
6076
}
6177
};
6278

@@ -70,7 +86,7 @@ public Object mergeValues(Object oldValue, Object newValue)
7086
@Override
7187
public Object mergeValues(Object oldValue, Object newValue)
7288
{
73-
return Math.max((Long) oldValue, (Long) newValue);
89+
return mergeMax(oldValue, newValue);
7490
}
7591
};
7692

0 commit comments

Comments
 (0)