Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.function.Function;

public class StringTopNColumnSelectorStrategy
implements TopNColumnSelectorStrategy<DimensionSelector, Map<Comparable, Aggregator[]>>
implements TopNColumnSelectorStrategy<DimensionSelector, Map<Comparable<?>, Aggregator[]>>
{
private final Function<Object, Comparable<?>> dimensionValueConverter;

Expand Down Expand Up @@ -73,7 +73,7 @@ public Aggregator[][] getDimExtractionRowSelector(TopNQuery query, TopNParams pa
}

@Override
public Map<Comparable, Aggregator[]> makeDimExtractionAggregateStore()
public Map<Comparable<?>, Aggregator[]> makeDimExtractionAggregateStore()
{
return new HashMap<>();
}
Expand All @@ -84,7 +84,7 @@ public long dimExtractionScanAndAggregate(
DimensionSelector selector,
Cursor cursor,
Aggregator[][] rowSelector,
Map<Comparable, Aggregator[]> aggregatesStore
Map<Comparable<?>, Aggregator[]> aggregatesStore
)
{
if (selector.getValueCardinality() != DimensionSelector.CARDINALITY_UNKNOWN) {
Expand All @@ -96,19 +96,19 @@ public long dimExtractionScanAndAggregate(

@Override
public void updateDimExtractionResults(
final Map<Comparable, Aggregator[]> aggregatesStore,
final Map<Comparable<?>, Aggregator[]> aggregatesStore,
final TopNResultBuilder resultBuilder
)
{
for (Map.Entry<Comparable, Aggregator[]> entry : aggregatesStore.entrySet()) {
for (Map.Entry<Comparable<?>, Aggregator[]> entry : aggregatesStore.entrySet()) {
Aggregator[] aggs = entry.getValue();
if (aggs != null) {
Object[] vals = new Object[aggs.length];
for (int i = 0; i < aggs.length; i++) {
vals[i] = aggs[i].get();
}

final Comparable key = dimensionValueConverter.apply(entry.getKey());
final Comparable<?> key = dimensionValueConverter.apply(entry.getKey());
resultBuilder.addEntry(key, key, vals);
}
}
Expand All @@ -119,7 +119,7 @@ private long dimExtractionScanAndAggregateWithCardinalityKnown(
Cursor cursor,
DimensionSelector selector,
Aggregator[][] rowSelector,
Map<Comparable, Aggregator[]> aggregatesStore
Map<Comparable<?>, Aggregator[]> aggregatesStore
)
{
long processedRows = 0;
Expand Down Expand Up @@ -152,7 +152,7 @@ private long dimExtractionScanAndAggregateWithCardinalityUnknown(
TopNQuery query,
Cursor cursor,
DimensionSelector selector,
Map<Comparable, Aggregator[]> aggregatesStore
Map<Comparable<?>, Aggregator[]> aggregatesStore
)
{
long processedRows = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ public TopNColumnSelectorStrategy makeColumnSelectorStrategy(
case LONG:
case FLOAT:
case DOUBLE:
// When the selector is numeric, we want to use NumericTopNColumnSelectorStrategy. It aggregates using
// a numeric type and then converts to the desired output type after aggregating. We must be careful not to
// convert to an output type that cannot represent all possible values of the input type.

if (ValueType.isNumeric(dimensionType)) {
// Return strategy that aggregates using the _output_ type, because this allows us to collapse values
// properly (numeric types cannot represent all values of other numeric types).
// properly (numeric types cannot always represent all values of other numeric types).
return NumericTopNColumnSelectorStrategy.ofType(dimensionType, dimensionType);
} else {
// Return strategy that aggregates using the _input_ type. Here we are assuming that the output type can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,7 @@ public static int compareObjectsAsType(
}

@Nullable
public static Comparable<?> convertObjectToType(
@Nullable final Object obj,
final ValueType type
)
public static Comparable<?> convertObjectToType(@Nullable final Object obj, final ValueType type)
{
return convertObjectToType(obj, Preconditions.checkNotNull(type, "type"), false);
}
Expand Down