Copilot commented on code in PR #16498:
URL: https://github.com/apache/pinot/pull/16498#discussion_r2251731909


##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/AggregationFunctionType.java:
##########
@@ -52,7 +52,13 @@ public enum AggregationFunctionType {
   COUNT("count"),
   // TODO: min/max only supports NUMERIC in Pinot, where Calcite supports 
COMPARABLE_ORDERED
   MIN("min", SqlTypeName.DOUBLE, SqlTypeName.DOUBLE),
+  /// An alternative to MIN to support other types
+  MIN2("min2", ReturnTypes.ARG0,
+      OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.CHARACTER), 
SqlTypeName.OTHER),
   MAX("max", SqlTypeName.DOUBLE, SqlTypeName.DOUBLE),
+  /// An alternative to MAX to support other types

Review Comment:
   Use proper Javadoc comment syntax instead of '///' which is not standard 
Java documentation format. Replace with '// An alternative to MIN to support 
other types' or proper Javadoc /** */ format.
   ```suggestion
     /** An alternative to MIN to support other types */
     MIN2("min2", ReturnTypes.ARG0,
         OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.CHARACTER), 
SqlTypeName.OTHER),
     MAX("max", SqlTypeName.DOUBLE, SqlTypeName.DOUBLE),
     /** An alternative to MAX to support other types */
   ```



##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/AggregationFunctionType.java:
##########
@@ -52,7 +52,13 @@ public enum AggregationFunctionType {
   COUNT("count"),
   // TODO: min/max only supports NUMERIC in Pinot, where Calcite supports 
COMPARABLE_ORDERED
   MIN("min", SqlTypeName.DOUBLE, SqlTypeName.DOUBLE),
+  /// An alternative to MIN to support other types
+  MIN2("min2", ReturnTypes.ARG0,
+      OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.CHARACTER), 
SqlTypeName.OTHER),
   MAX("max", SqlTypeName.DOUBLE, SqlTypeName.DOUBLE),
+  /// An alternative to MAX to support other types

Review Comment:
   Use proper Javadoc comment syntax instead of '///' which is not standard 
Java documentation format. Replace with '// An alternative to MAX to support 
other types' or proper Javadoc /** */ format.



##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/MinStringAggregationFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.query.aggregation.function;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.CustomObject;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.BlockValSet;
+import org.apache.pinot.core.common.ObjectSerDeUtils;
+import org.apache.pinot.core.query.aggregation.AggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.ObjectAggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import 
org.apache.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder;
+import org.apache.pinot.segment.spi.AggregationFunctionType;
+
+
+public class MinStringAggregationFunction extends 
NullableSingleInputAggregationFunction<String, String> {
+
+  public MinStringAggregationFunction(ExpressionContext expression, boolean 
nullHandlingEnabled) {
+    super(expression, nullHandlingEnabled);
+  }
+
+  @Override
+  public AggregationFunctionType getType() {
+    return AggregationFunctionType.MIN2;
+  }
+
+  @Override
+  public AggregationResultHolder createAggregationResultHolder() {
+    return new ObjectAggregationResultHolder();
+  }
+
+  @Override
+  public GroupByResultHolder createGroupByResultHolder(int initialCapacity, 
int maxCapacity) {
+    return new ObjectGroupByResultHolder(initialCapacity, maxCapacity);
+  }
+
+  @Override
+  public void aggregate(int length, AggregationResultHolder 
aggregationResultHolder,
+      Map<ExpressionContext, BlockValSet> blockValSetMap) {
+    BlockValSet blockValSet = blockValSetMap.get(_expression);
+    String[] values = blockValSet.getStringValuesSV();
+
+    String min = foldNotNull(length, blockValSet, null, (accum, from, to) -> {
+      String innerMin = values[from];
+      for (int i = from + 1; i < to; i++) {
+        innerMin = innerMin.compareTo(values[i]) > 0 ? values[i] : innerMin;
+      }
+      return accum == null ? innerMin : innerMin.compareTo(accum) > 0 ? accum 
: innerMin;
+    });
+
+    if (min != null) {
+      String otherMax = aggregationResultHolder.getResult();
+      if (otherMax == null) {
+        // If the other max is null, we set the value directly

Review Comment:
   The comment mentions 'other max' but this is a MIN function. The comment 
should say 'If the existing min is null, we set the value directly' to be 
accurate.



##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/MaxStringAggregationFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.query.aggregation.function;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.CustomObject;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.BlockValSet;
+import org.apache.pinot.core.common.ObjectSerDeUtils;
+import org.apache.pinot.core.query.aggregation.AggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.ObjectAggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import 
org.apache.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder;
+import org.apache.pinot.segment.spi.AggregationFunctionType;
+
+
+public class MaxStringAggregationFunction extends 
NullableSingleInputAggregationFunction<String, String> {
+
+  public MaxStringAggregationFunction(ExpressionContext expression, boolean 
nullHandlingEnabled) {
+    super(expression, nullHandlingEnabled);
+  }
+
+  @Override
+  public AggregationFunctionType getType() {
+    return AggregationFunctionType.MAX2;
+  }
+
+  @Override
+  public AggregationResultHolder createAggregationResultHolder() {
+    return new ObjectAggregationResultHolder();
+  }
+
+  @Override
+  public GroupByResultHolder createGroupByResultHolder(int initialCapacity, 
int maxCapacity) {
+    return new ObjectGroupByResultHolder(initialCapacity, maxCapacity);
+  }
+
+  @Override
+  public void aggregate(int length, AggregationResultHolder 
aggregationResultHolder,
+      Map<ExpressionContext, BlockValSet> blockValSetMap) {
+    BlockValSet blockValSet = blockValSetMap.get(_expression);
+    String[] values = blockValSet.getStringValuesSV();
+
+    String max = foldNotNull(length, blockValSet, null, (accum, from, to) -> {
+      String innerMax = values[from];
+      for (int i = from + 1; i < to; i++) {
+        innerMax = innerMax.compareTo(values[i]) < 0 ? values[i] : innerMax;
+      }
+      return accum == null ? innerMax : innerMax.compareTo(accum) < 0 ? accum 
: innerMax;
+    });
+
+    if (max != null) {
+      String otherMax = aggregationResultHolder.getResult();
+      if (otherMax == null) {
+        // If the other max is null, we set the value directly
+        aggregationResultHolder.setValue(max);
+      } else if (max.compareTo(otherMax) < 0) {

Review Comment:
   The comparison logic is incorrect for MAX function. It should be 
`max.compareTo(otherMax) > 0` to update when the new max is greater than the 
existing max, not less than.
   ```suggestion
         } else if (max.compareTo(otherMax) > 0) {
   ```



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