Fix GroupBy type cast when ChainedExecutionQueryRunner merges results#4488
Fix GroupBy type cast when ChainedExecutionQueryRunner merges results#4488gianm merged 4 commits intoapache:masterfrom
Conversation
| ); | ||
| } | ||
|
|
||
| // Convert dimension types to specified output types |
There was a problem hiding this comment.
Please make this conversion a method
There was a problem hiding this comment.
Now this comment almost exactly repeats the method name so not needed
There was a problem hiding this comment.
removed the unnecessary comment
| private static void convertRowTypesToOutputTypes(List<DimensionSpec> dimensionSpecs, Map<String, Object> rowMap) | ||
| { | ||
| for (DimensionSpec dimSpec : dimensionSpecs) { | ||
| Object baseVal = rowMap.get(dimSpec.getOutputName()); |
There was a problem hiding this comment.
I decided to keep it as-is, the function for compute(...) would need to lookup the outputType associated with the dimension name key.
That info is only kept in the DimensionSpecs list from the query in that context, so it would have to scan the list for every key or keep some other mapping structure of dimName->outputType around
There was a problem hiding this comment.
Hm, why?
for (DimensionSpec dimSpec : dimensionSpecs) {
ValueType outputType = dimSpec.getOutputType();
rawMap.compute(dimSpec.getOutputName(), (name, baseVal) -> {
switch (outputType) {
case STRING:
return baseVal == null ? "" : baseVal.toString();
...
}
});
}c3ce20b to
3ed1057
Compare
c1daa42 to
9dfd18d
Compare
| (dimName, baseVal) -> { | ||
| switch (outputType) { | ||
| case STRING: | ||
| baseVal = baseVal == null ? "" : baseVal.toString(); |
There was a problem hiding this comment.
[Minor] Could return from switch, without reassigning baseVal and break
…apache#4488) * Fix GroupBy type cast error when ChainedExecutionQueryRunner merges multiple runners * Move conversion step to separate method * Remove unnecessary comment * Use compute to update map
When using the "outputType" parameter of DimensionSpec to change the type of a dimension, a ClassCastException would occur when the ChainedExecutionQueryRunner merges results from multiple query runners:
The unit test provides an example that would trigger the error.
This patch adds a type conversion step to results generated by GroupByEngineV2 before they are merged by the ChainedExecutionQueryRunner.