imply-cheddar commented on code in PR #14708:
URL: https://github.com/apache/druid/pull/14708#discussion_r1282587603


##########
processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java:
##########
@@ -151,128 +185,80 @@ public Function<Result<TopNResultValue>, 
Result<TopNResultValue>> makePreCompute
       final MetricManipulationFn fn
   )
   {
+    //noinspection ObjectEquality
+    if (MetricManipulatorFns.deserializing() != fn) {
+      throw DruidException.defensive("This method can only be used to 
deserialize.");
+    }
+
     return new Function<Result<TopNResultValue>, Result<TopNResultValue>>()
     {
-      private String dimension = query.getDimensionSpec().getOutputName();
-      private final List<PostAggregator> prunedAggs = 
prunePostAggregators(query);
       private final AggregatorFactory[] aggregatorFactories = 
query.getAggregatorSpecs()
                                                                    
.toArray(new AggregatorFactory[0]);
       private final String[] aggFactoryNames = 
extractFactoryName(query.getAggregatorSpecs());
 
       @Override
       public Result<TopNResultValue> apply(Result<TopNResultValue> result)
       {
-        List<Map<String, Object>> serializedValues = Lists.newArrayList(
-            Iterables.transform(
-                result.getValue(),
-                new Function<DimensionAndMetricValueExtractor, Map<String, 
Object>>()
-                {
-                  @Override
-                  public Map<String, Object> 
apply(DimensionAndMetricValueExtractor input)
-                  {
-                    final Map<String, Object> values = 
Maps.newHashMapWithExpectedSize(
-                        aggregatorFactories.length
-                        + prunedAggs.size()
-                        + 1
-                    );
-
-                    for (int i = 0; i < aggregatorFactories.length; ++i) {
-                      final String aggName = aggFactoryNames[i];
-                      values.put(aggName, 
fn.manipulate(aggregatorFactories[i], input.getMetric(aggName)));
-                    }
+        final List<DimensionAndMetricValueExtractor> values = 
result.getValue().getValue();
+        final List<DimensionAndMetricValueExtractor> newValues = new 
ArrayList<>(values.size());
 
-                    for (PostAggregator postAgg : prunedAggs) {
-                      final String name = postAgg.getName();
-                      Object calculatedPostAgg = input.getMetric(name);
-                      if (calculatedPostAgg != null) {
-                        values.put(name, calculatedPostAgg);
-                      } else {
-                        values.put(name, postAgg.compute(values));
-                      }
-                    }
-                    values.put(dimension, input.getDimensionValue(dimension));
+        for (DimensionAndMetricValueExtractor input : values) {
+          final Map<String, Object> map = new 
LinkedHashMap<>(input.getBaseObject());
 
-                    return values;
-                  }
-                }
-            )
-        );
+          for (int i = 0; i < aggregatorFactories.length; ++i) {
+            final String aggName = aggFactoryNames[i];
+            map.put(aggName, 
aggregatorFactories[i].deserialize(map.get(aggName)));

Review Comment:
   This was intentional actually.
   
   For both of these, I explicitly called the method (after validating the `fn` 
was what I expected) that I wanted instead of using `fn.apply` because the `fn` 
is a bit superfluous (it's always doing one thing or another).  So, I was 
prepping the implementation for just eliminating the methods altogether.  
Essentially, by making the implementations very explicit in what they do and 
don't do, it becomes easier to know what logic needs to be handled in order to 
eliminate the need for the method.  If it uses `fn.apply`, then any arbitrary 
`fn` *could* be passed in...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to