kgyrtkirk commented on code in PR #15434:
URL: https://github.com/apache/druid/pull/15434#discussion_r1408802079


##########
processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyAggregator.java:
##########
@@ -24,38 +24,57 @@
 import org.apache.druid.segment.BaseObjectColumnValueSelector;
 import org.apache.druid.segment.DimensionHandlerUtils;
 
+import java.util.List;
+
 public class StringAnyAggregator implements Aggregator
 {
   private final BaseObjectColumnValueSelector valueSelector;
   private final int maxStringBytes;
   private boolean isFound;
   private String foundValue;
+  private final boolean aggregateMultipleValues;
 
-  public StringAnyAggregator(BaseObjectColumnValueSelector valueSelector, int 
maxStringBytes)
+  public StringAnyAggregator(BaseObjectColumnValueSelector valueSelector, int 
maxStringBytes, boolean aggregateMultipleValues)
   {
     this.valueSelector = valueSelector;
     this.maxStringBytes = maxStringBytes;
     this.foundValue = null;
     this.isFound = false;
+    this.aggregateMultipleValues = aggregateMultipleValues;
   }
 
   @Override
   public void aggregate()
   {
     if (!isFound) {
       final Object object = valueSelector.getObject();
-      foundValue = DimensionHandlerUtils.convertObjectToString(object);
-      if (foundValue != null && foundValue.length() > maxStringBytes) {
-        foundValue = foundValue.substring(0, maxStringBytes);
-      }
+      foundValue = StringUtils.fastLooseChop(readValue(object), 
maxStringBytes);
       isFound = true;
     }
   }
 
+  private String readValue(final Object object)
+  {
+    if (object == null) {
+      return null;
+    }
+    if (object instanceof List) {
+      List<Object> objectList = (List) object;
+      if (objectList.size() == 1) {

Review Comment:
   can the `size() == 0` ? if yes that could be a problem
   note: I wonder if ifs can be  flipped; since when `aggregateMultipleValues` 
is `true` all branches lead to the same decision; could something like this 
work?
   
   ```
   if( !aggregateMultipleValues &&  (object instanceof List) && 
((List)object).size() > 1 ) {
      return DimensionHandlerUtils.convertObjectToString(objectList.get(0));
   } else {
     DimensionHandlerUtils.convertObjectToString(object);
   }
   ```
   



-- 
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