Skip to content
Open
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 @@ -70,7 +70,8 @@
public class AggregateIndexExpansionVisitor extends KeyExpressionExpansionVisitor
implements ExpansionVisitor<KeyExpressionExpansionVisitor.VisitorState> {
@Nonnull
private static final Supplier<Map<String, BuiltInFunction<? extends Value>>> aggregateMap = Suppliers.memoize(AggregateIndexExpansionVisitor::computeAggregateMap);
private static final Supplier<Map<String, BuiltInFunction<? extends Value>>> aggregateMap =
Suppliers.memoize(AggregateIndexExpansionVisitor::computeAggregateMap);

@Nonnull
private final Index index;
Expand Down Expand Up @@ -218,7 +219,7 @@ private Quantifier constructGroupBy(@Nonnull final Quantifier selectWhereQun, @N
// construct aggregation RCV
final Value argument;
if (groupedValue instanceof EmptyValue) {
argument = RecordConstructorValue.ofColumns(ImmutableList.of());
argument = QuantifiedObjectValue.of(selectWhereQun);
} else if (groupedValue instanceof FieldValue) {
final var aliasMap = AliasMap.identitiesFor(Sets.union(selectWhereQun.getCorrelatedTo(),
groupedValue.getCorrelatedTo()));
Expand All @@ -243,15 +244,20 @@ private Quantifier constructGroupBy(@Nonnull final Quantifier selectWhereQun, @N
.map(Column::getValue)
.collect(ImmutableList.toImmutableList());
final var selectQunValue = selectWhereQun.getRangesOver().get().getResultValue();
final var aliasMap = AliasMap.identitiesFor(Sets.union(selectQunValue.getCorrelatedTo(), groupingValues.stream().flatMap(v -> v.getCorrelatedTo().stream()).collect(ImmutableSet.toImmutableSet())));
final var pulledUpGroupingValuesMap = selectQunValue.pullUp(groupingValues, aliasMap, ImmutableSet.of(), selectWhereQun.getAlias());
final var pulledUpGroupingValues = groupingValues.stream().map(groupingValue -> {
if (!pulledUpGroupingValuesMap.containsKey(groupingValue)) {
throw new RecordCoreException("could not pull grouping value " + groupingValue)
.addLogInfo(LogMessageKeys.VALUE, groupingValue);
}
return pulledUpGroupingValuesMap.get(groupingValue);
}).collect(ImmutableList.toImmutableList());
final var aliasMap = AliasMap.identitiesFor(
Sets.union(selectQunValue.getCorrelatedTo(),
groupingValues.stream().flatMap(v -> v.getCorrelatedTo().stream())
.collect(ImmutableSet.toImmutableSet())));
final var pulledUpGroupingValuesMap =
selectQunValue.pullUp(groupingValues, aliasMap, ImmutableSet.of(), selectWhereQun.getAlias());
final var pulledUpGroupingValues =
groupingValues.stream().map(groupingValue -> {
if (!pulledUpGroupingValuesMap.containsKey(groupingValue)) {
throw new RecordCoreException("could not pull grouping value " + groupingValue)
.addLogInfo(LogMessageKeys.VALUE, groupingValue);
}
return pulledUpGroupingValuesMap.get(groupingValue);
}).collect(ImmutableList.toImmutableList());
Comment on lines -246 to +260

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all white space/line break changes, right? Just making sure I'm not missing anything


// construct grouping column(s) value, the grouping column is _always_ fixed at position-0 in the underlying select-where.
final var groupingColsValue = RecordConstructorValue.ofUnnamed(pulledUpGroupingValues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import com.apple.foundationdb.record.query.plan.cascades.values.FieldValue;
import com.apple.foundationdb.record.query.plan.cascades.values.IndexOnlyAggregateValue;
import com.apple.foundationdb.record.query.plan.cascades.values.NumericAggregationValue;
import com.apple.foundationdb.record.query.plan.cascades.values.QuantifiedObjectValue;
import com.apple.foundationdb.record.query.plan.cascades.values.RecordConstructorValue;
import com.apple.foundationdb.record.query.plan.cascades.values.Value;
import com.apple.foundationdb.record.query.plan.plans.QueryResult;
Expand Down Expand Up @@ -1316,7 +1317,7 @@ void countByKeyIndexes() {
final Quantifier outerQun = outerRecQun();
final Quantifier entryQun = explodeEntryKeys(outerQun);
final Quantifier selectWhere = selectWhereGroupByKey(outerQun, entryQun);
final Quantifier groupBy = groupAggregateByKey(selectWhere, new CountValue.CountFn(), RecordConstructorValue.ofColumns(List.of()));
final Quantifier groupBy = groupAggregateByKey(selectWhere, new CountValue.CountFn(), QuantifiedObjectValue.of(selectWhere));
return unsorted(selectHaving(groupBy));
});
}
Expand Down