somandal commented on issue #10628:
URL: https://github.com/apache/pinot/issues/10628#issuecomment-1512281335
@ankitsultana @walterddr we could potentially do something like this:
```
public interface Merger {
/**
* Initializes the merger based on the first input
*/
default Object initialize(Object other, DataSchema.ColumnDataType
dataType) {
// TODO: Initialize as a double so that if only one row is returned it
matches the type when many rows are
// returned
return other == null ? dataType.getNullPlaceholder() : other;
}
/**
* Merges the existing aggregate (the result of {@link
#initialize(Object, DataSchema.ColumnDataType)}) with
* the new value coming in (which may be an aggregate in and of itself).
*/
Object merge(Object agg, Object value);
}
public abstract static class BaseMerger implements AggregationUtils.Merger
{
public final DataSchema.ColumnDataType _dataType;
BaseMerger(DataSchema.ColumnDataType dataType) {
_dataType = dataType;
}
}
```
We can have all the mergers extend the above `BaseMerger` so that they get
the `_dataType`. Then we can use the `_dataType` within the min and max
functions to implement it differently:
```
private static class MergeMins extends BaseMerger {
MergeMins(DataSchema.ColumnDataType dataType) {
super(dataType);
}
@Override
public Object merge(Object left, Object right) {
if (_dataType == DataSchema.ColumnDataType.BOOLEAN) {
return (Boolean) left && (Boolean) right;
}
return Math.min(((Number) left).doubleValue(), ((Number)
right).doubleValue());
}
}
```
wdyt?
--
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]